diff --git a/update_operator.sh b/update_operator.sh new file mode 100755 index 0000000..7822663 --- /dev/null +++ b/update_operator.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 On|Off" + exit 1 +fi + +ACTION=$1 + +if [ "$ACTION" == "On" ]; then + # 启用unattended-upgrades服务 + sudo systemctl enable unattended-upgrades.service + sudo systemctl start unattended-upgrades.service + + # 启用APT定时服务 + sudo systemctl enable apt-daily.timer + sudo systemctl start apt-daily.timer + sudo systemctl enable apt-daily-upgrade.timer + sudo systemctl start apt-daily-upgrade.timer + + # 启用APT配置中的自动更新 + sudo sed -i 's/"0"/"1"/' /etc/apt/apt.conf.d/20auto-upgrades + + echo "Automatic updates have been enabled." +elif [ "$ACTION" == "Off" ]; then + # 禁用unattended-upgrades服务 + sudo systemctl stop unattended-upgrades.service + sudo systemctl disable unattended-upgrades.service + + # 禁用APT定时服务 + sudo systemctl stop apt-daily.timer + sudo systemctl disable apt-daily.timer + sudo systemctl stop apt-daily-upgrade.timer + sudo systemctl disable apt-daily-upgrade.timer + + # 禁用APT配置中的自动更新 + sudo sed -i 's/"1"/"0"/' /etc/apt/apt.conf.d/20auto-upgrades + + echo "Automatic updates have been disabled." +else + echo "Invalid argument: $ACTION" + echo "Usage: $0 On|Off" + exit 1 +fi +