mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-21 05:44:07 -07:00
Change system hostname
This commit is contained in:
parent
1834f56497
commit
a4a404ee02
1 changed files with 57 additions and 0 deletions
57
bin/v-change-sys-hostname
Executable file
57
bin/v-change-sys-hostname
Executable file
|
@ -0,0 +1,57 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# info: change hostname
|
||||||
|
# options: HOSTNAME
|
||||||
|
#
|
||||||
|
# The function for changing system hostname.
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Variable&Function #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
# Argument defenition
|
||||||
|
domain=$1
|
||||||
|
|
||||||
|
# Includes
|
||||||
|
source $VESTA/func/main.sh
|
||||||
|
source $VESTA/conf/vesta.conf
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Verifications #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
check_args '1' "$#" 'HOSTNAME'
|
||||||
|
validate_format 'domain'
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Action #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
hostname $domain
|
||||||
|
|
||||||
|
# RHEL/CentOS
|
||||||
|
if [ -e "/etc/redhat-release" ]; then
|
||||||
|
touch /etc/sysconfig/network
|
||||||
|
if [ -z "$(grep HOSTNAME /etc/sysconfig/network)" ]; then
|
||||||
|
echo "HOSTNAME='$domain'" >> /etc/sysconfig/network
|
||||||
|
else
|
||||||
|
sed -i "s/HOSTNAME=.*/HOSTNAME='$domain'/" /etc/sysconfig/network
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Debian/Ubuntu
|
||||||
|
if [ ! -e "/etc/redhat-release" ]; then
|
||||||
|
echo "$domain" > /etc/hostname
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Vesta #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
log_event "$OK" "$EVENT"
|
||||||
|
|
||||||
|
exit
|
Loading…
Add table
Add a link
Reference in a new issue