From a4a404ee0282ce410fc15592c72388897b7d1084 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Sun, 18 May 2014 20:09:08 +0300 Subject: [PATCH] Change system hostname --- bin/v-change-sys-hostname | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 bin/v-change-sys-hostname diff --git a/bin/v-change-sys-hostname b/bin/v-change-sys-hostname new file mode 100755 index 000000000..eab206a51 --- /dev/null +++ b/bin/v-change-sys-hostname @@ -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