script/update_operator.sh
2024-07-29 12:51:02 +08:00

46 lines
1.2 KiB
Bash
Executable File

#!/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