工具软件:softwares=“vim tree bash-completion lrzsz wget setroubleshoot setools”
[root@vultrguest ~]# head -17 setup.sh #!/bin/bash####### COMMON SETTING# HOSTNAME: leave it blank if u don't want to change
hostname=vultr
# NETWORK : leave it blank if u don't want to change
ipv4_addresses=
ipv4_gateway=# NETWORK : if ip and gateway were given, change these as needed
interface=ens160
ipv4_dns=114.114.114.114
ipv4_method=manual
connection_autoconnect=yes
# TIMEZONE: leave it blank if u don't want to change
timezone=Asia/Shanghai
# SOFTTOOL: leave it blank if u don't want to change
softwares="vim tree bash-completion lrzsz wget setroubleshoot setools"[root@vultrguest ~]#
运行脚本
[root@vultrguest ~]# sh setup.sh
------- START INITIALIZATION WORK AT 2020-11-19 20:37:53
--- set hostname=vultr
--- set timezone to Asia/Shanghai
--- configure chronyd service
Last metadata expiration check: 0:03:23 ago on Thu 19 Nov 2020 08:34:31 PM CST.
Package chrony-3.5-1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
--- install softwares
Last metadata expiration check: 0:03:24 ago on Thu 19 Nov 2020 08:34:31 PM CST.
Package vim-enhanced-2:8.0.1763-13.el8.x86_64 is already installed.
Package tree-1.7.0-15.el8.x86_64 is already installed.
Package bash-completion-1:2.7-5.el8.noarch is already installed.
Package lrzsz-0.12.20-43.el8.x86_64 is already installed.
Package wget-1.19.5-8.el8_1.1.x86_64 is already installed.
Package setroubleshoot-3.3.22-2.el8.x86_64 is already installed.
Package setools-4.2.2-2.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
------- FINISH INITIALIZATION WORK AT 2020-11-19 20:37:56
[root@vultrguest ~]#
脚本
#!/bin/bash####### COMMON SETTING# HOSTNAME: leave it blank if u don't want to change
hostname=# NETWORK : leave it blank if u don't want to change
ipv4_addresses=
ipv4_gateway=# NETWORK : if ip and gateway were given, change these as needed
interface="ens160"
ipv4_dns=114.114.114.114
ipv4_method=manual
connection_autoconnect=yes
# TIMEZONE: leave it blank if u don't want to change
timezone=# SOFTTOOL: leave it blank if u don't want to change
softwares=""####### START SETTING# HEADecho"------- START INITIALIZATION WORK AT $(date +'%F %T')"# HOSTNAMEif[$hostname]thenecho""echo"--- set hostname=$hostname"
hostnamectl set-hostname $hostnamefi# NETWORKif[$ipv4_addresses]&&[$ipv4_gateway]thenecho""echo"--- set network"echo""# preparing
uuid=$(uuidgen $interface)echo"Set interface $interface ipv4.addresses to $ipv4_addresses"echo"Set interface $interface ipv4.gateway to $ipv4_gateway"echo"Set interface $interface ipv4.dns to $ipv4_dns"echo"Set interface $interface ipv4.method to $ipv4_method"echo"Set interface $interface uuid to $uuid"echo"Set interface $interface connection.autoconnect to $connection_autoconnect"# setting
nmcli c modify $interface connection.autoconnect $connection_autoconnect ipv4.method $ipv4_method \
ipv4.addresses $ipv4_addresses ipv4.gateway $ipv4_gateway ipv4.dns $ipv4_dnssed -i "s/^UUID.*/UUID=$uuid/g" /etc/sysconfig/network-scripts/ifcfg-$interface# reloading
nmcli c reload
nmcli c up $interfacefi####### TIMEZONE & TIME SYNC# Time Zoneif[$timezone]thenecho""echo"--- set timezone to $timezone"
timedatectl set-timezone $timezonefi# Time Syncecho""echo"--- configure chronyd service"
dnf install chrony -y
systemctl start chronyd
systemctl enable chronyd
####### INSTALL SOFTecho""echo"--- install softwares"
dnf install -y $softwares####### FINISH SETTINGecho""echo"------- FINISH INITIALIZATION WORK AT $(date +'%F %T')"