mirror of
https://github.com/serghey-rodin/vesta.git
synced 2024-12-03 19:00:24 -08:00
56 lines
1.4 KiB
Bash
Executable File
56 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# info: change hostname
|
|
# options: HOSTNAME
|
|
#
|
|
# The function for changing system hostname.
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
# Argument definition
|
|
domain=$1
|
|
|
|
# Includes
|
|
source $VESTA/func/main.sh
|
|
source $VESTA/conf/vesta.conf
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Verifications #
|
|
#----------------------------------------------------------#
|
|
|
|
check_args '1' "$#" 'HOSTNAME'
|
|
is_format_valid 'domain'
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
hostname $domain
|
|
|
|
if [ -d "/etc/sysconfig" ]; then
|
|
# RHEL/CentOS/Amazon
|
|
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
|
|
else
|
|
# Debian/Ubuntu
|
|
echo "$domain" > /etc/hostname
|
|
fi
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
# Logging
|
|
log_event "$OK" "$ARGUMENTS"
|
|
|
|
exit
|