From fe4597d118ff563f1367fa9ab6d98067bb335cac Mon Sep 17 00:00:00 2001 From: taynpg Date: Mon, 29 Jul 2024 12:51:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=81=E7=94=A8Ubuntu=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update_operator.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 update_operator.sh 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 +