Skip to content

Commit a4a404e

Browse files
committed
Change system hostname
1 parent 1834f56 commit a4a404e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

bin/v-change-sys-hostname

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# info: change hostname
3+
# options: HOSTNAME
4+
#
5+
# The function for changing system hostname.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
domain=$1
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
source $VESTA/conf/vesta.conf
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
check_args '1' "$#" 'HOSTNAME'
25+
validate_format 'domain'
26+
27+
28+
#----------------------------------------------------------#
29+
# Action #
30+
#----------------------------------------------------------#
31+
32+
hostname $domain
33+
34+
# RHEL/CentOS
35+
if [ -e "/etc/redhat-release" ]; then
36+
touch /etc/sysconfig/network
37+
if [ -z "$(grep HOSTNAME /etc/sysconfig/network)" ]; then
38+
echo "HOSTNAME='$domain'" >> /etc/sysconfig/network
39+
else
40+
sed -i "s/HOSTNAME=.*/HOSTNAME='$domain'/" /etc/sysconfig/network
41+
fi
42+
fi
43+
44+
# Debian/Ubuntu
45+
if [ ! -e "/etc/redhat-release" ]; then
46+
echo "$domain" > /etc/hostname
47+
fi
48+
49+
50+
#----------------------------------------------------------#
51+
# Vesta #
52+
#----------------------------------------------------------#
53+
54+
# Logging
55+
log_event "$OK" "$EVENT"
56+
57+
exit

0 commit comments

Comments
 (0)