更新 RMxxx_rgmii_toolkit.sh
This commit is contained in:
parent
4b68890429
commit
f56cc1caf4
@ -436,34 +436,26 @@ WantedBy=multi-user.target" > "$cfun_service_path"
|
||||
|
||||
# Function to change hostname
|
||||
change_hostname() {
|
||||
# 显示当前主机名
|
||||
current_hostname=$(cat /etc/hostname)
|
||||
echo -e "\e[1;32mCurrent hostname: $current_hostname\e[0m"
|
||||
|
||||
# 提示用户输入新主机名
|
||||
echo -e "\e[1;32mEnter new hostname (or 'exit' to cancel):\e[0m"
|
||||
read new_hostname
|
||||
|
||||
if [ "$new_hostname" = "exit" ]; then
|
||||
echo -e "\e[1;31mHostname change cancelled.\e[0m"
|
||||
return
|
||||
# Check if simpleadmin is installed and change_hostname.sh exists
|
||||
if [ -f "/usrdata/simpleadmin/console/menu/change_hostname.sh" ]; then
|
||||
/usrdata/simpleadmin/console/menu/change_hostname.sh
|
||||
new_hostname=$(cat /etc/hostname)
|
||||
echo -e "\e[1;32mHostname has been changed to: $new_hostname\e[0m"
|
||||
echo -e "\e[1;33mPlease reboot the device for the change to take full effect.\e[0m"
|
||||
else
|
||||
# If script doesn't exist, download it from the project
|
||||
echo -e "\e[1;32mDownloading hostname change script...\e[0m"
|
||||
remount_rw
|
||||
mkdir -p /tmp/hostname_change
|
||||
curl -o /tmp/hostname_change/change_hostname.sh "$GITROOT/simpleadmin/console/menu/change_hostname.sh"
|
||||
chmod +x /tmp/hostname_change/change_hostname.sh
|
||||
/tmp/hostname_change/change_hostname.sh
|
||||
new_hostname=$(cat /etc/hostname)
|
||||
echo -e "\e[1;32mHostname has been changed to: $new_hostname\e[0m"
|
||||
echo -e "\e[1;33mPlease reboot the device for the change to take full effect.\e[0m"
|
||||
rm -rf /tmp/hostname_change
|
||||
remount_ro
|
||||
fi
|
||||
|
||||
# 验证主机名格式
|
||||
if ! echo "$new_hostname" | grep -qE '^[a-zA-Z0-9-]+$'; then
|
||||
echo -e "\e[1;31mInvalid hostname. Hostname can only contain letters, numbers, and hyphens.\e[0m"
|
||||
return
|
||||
fi
|
||||
|
||||
# 修改主机名
|
||||
remount_rw
|
||||
echo "$new_hostname" > /etc/hostname
|
||||
sed -i "s/127.0.1.1.*$/127.0.1.1\t$new_hostname/g" /etc/hosts
|
||||
hostname "$new_hostname"
|
||||
remount_ro
|
||||
|
||||
echo -e "\e[1;32mHostname has been changed to: $new_hostname\e[0m"
|
||||
echo -e "\e[1;33mPlease reboot the device for the change to take full effect.\e[0m"
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
||||
Loading…
Reference in New Issue
Block a user