更新 scripts/system_optimize.sh

This commit is contained in:
joy 2025-07-15 17:28:43 +08:00
parent a9888b8de5
commit a337fcc88d
1 changed files with 8 additions and 0 deletions

View File

@ -151,6 +151,13 @@ update_grub_configuration() {
log_info "GRUB配置已更新" log_info "GRUB配置已更新"
} }
#修改主机名
rename_hostname(){
IP=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}' | grep `ip route | grep default | awk '{print $3}' | awk -F. '{print $1"."$2}' | head -1` | head -1 | sed 's/\./-/g')
hostnamectl set-hostname ${IP}
}
# 主函数:按顺序执行所有配置步骤 # 主函数:按顺序执行所有配置步骤
main() { main() {
log_info "开始系统配置..." log_info "开始系统配置..."
@ -161,6 +168,7 @@ main() {
synchronize_hardware_clock synchronize_hardware_clock
disable_nouveau_driver disable_nouveau_driver
update_grub_configuration update_grub_configuration
rename_hostname
log_info "系统配置完成!" log_info "系统配置完成!"
} }