2024-09-12 11:16:10 +08:00
|
|
|
declare path="$1"
|
|
|
|
declare cron="$2"
|
2024-07-25 21:59:46 +08:00
|
|
|
|
|
|
|
if [[ -f "${path}/update.sh" ]];then
|
|
|
|
echo "该路径文件已经存在"
|
|
|
|
fi
|
|
|
|
|
2024-07-27 15:12:30 +08:00
|
|
|
echo '#!/bin/bash' > "${path}/update.sh"
|
|
|
|
|
|
|
|
if [[ -f "/usr/bin/apt" ]];then
|
2024-09-21 14:17:49 +08:00
|
|
|
echo 'sudo apt update -y' >> "${path}/update.sh"
|
|
|
|
echo 'sudo apt-get dist-upgrad -y' >> "${path}/update.sh"
|
2024-07-27 15:12:30 +08:00
|
|
|
elif [[ -f "/usr/bin/apt-get" ]];then
|
2024-09-21 14:17:49 +08:00
|
|
|
echo 'sudo apt-get update -y' >> "${path}/update.sh"
|
|
|
|
echo 'sudo apt dist-upgrade -y' >> "${path}/update.sh"
|
2024-09-22 23:13:33 +08:00
|
|
|
elif [[ -f "/usr/bin/pacman" ]];then
|
|
|
|
sudo pacman -Syu --noconfirm
|
2024-07-27 15:12:30 +08:00
|
|
|
else
|
|
|
|
rm "${path}/update.sh"
|
|
|
|
echo "暂不支持该系统配置自动更新软件"
|
|
|
|
exit
|
|
|
|
fi
|
2024-07-25 21:59:46 +08:00
|
|
|
|
|
|
|
chmod +x "${path}/update.sh"
|
2024-07-26 18:39:43 +08:00
|
|
|
|
|
|
|
declare cron_job="${cron} ${path}/update.sh"
|
|
|
|
(crontab -l 2>/dev/null | grep -v "update.sh") | sudo crontab -
|
|
|
|
(crontab -l 2>/dev/null; echo "$cron_job") | sudo crontab -
|
|
|
|
|
2024-07-25 21:59:46 +08:00
|
|
|
sudo systemctl restart cron 2>> /dev/null || echo "自动任务重启失败"
|