From 85dec1ec648aa64bb08755984b39c231bd06b772 Mon Sep 17 00:00:00 2001 From: Hyy2001X <1804430051@qq.com> Date: Sun, 4 Jul 2021 12:39:16 +0800 Subject: [PATCH] =?UTF-8?q?V6.3.2=20=E5=88=A0=E9=99=A4=E5=8F=82=E6=95=B0?= =?UTF-8?q?=20--corn-rm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scripts/AutoUpdate.sh | 56 ++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/Scripts/AutoUpdate.sh b/Scripts/AutoUpdate.sh index d7f6677..33f7200 100755 --- a/Scripts/AutoUpdate.sh +++ b/Scripts/AutoUpdate.sh @@ -38,7 +38,6 @@ SHELL_HELP() { -U 仅检查版本更新 -F 强制刷写固件 --skip 跳过固件 SHA256 比对校验 (危险) - --corn-rm 删除所有 AutoUpdate 定时任务 --bak 备份 Openwrt 配置文件到用户指定的目录 --clean 清理固件下载缓存 --check 检查 AutoUpdate 依赖软件包 @@ -80,6 +79,32 @@ EOF EXIT 0 } +GET_PID() { + local Result + while [[ $1 ]];do + Result=$(busybox ps | grep "$1" | grep -v "grep" | awk '{print $1}' | awk 'NR==1') + [[ -n ${Result} ]] && echo ${Result} + shift + done +} + +KILL_PID() { + while [[ $1 ]];do + kill -9 $1 2>/dev/null + shift + done +} + +UCI_GET() { + local Result="$(uci get $1.@$2[0].$3 2>/dev/null)" + [[ -n ${Result} ]] && echo "${Result}" +} + +UCI_SET() { + uci set $1.@$2[0].$3=$4 2>/dev/null + uci commit $1 +} + LIST_ENV() { local X cat /etc/AutoBuild/*_Variable | grep -v '#' | while read X;do @@ -109,7 +134,7 @@ EXIT() { RUN_TYPE="[UNKNOWN]" ;; esac - LOGGER "${RUN_TYPE} Command :[${Run_Command}] Finished." + LOGGER "Command :[${Run_Command}] Finished." exit } @@ -137,7 +162,7 @@ ECHO() { LOGGER() { [[ ! -f ${AutoUpdate_Log_Path}/AutoUpdate.log ]] && touch ${AutoUpdate_Log_Path}/AutoUpdate.log - echo "[$(date "+%Y-%m-%d-%H:%M:%S")] $*" >> ${AutoUpdate_Log_Path}/AutoUpdate.log + echo "[$(date "+%Y-%m-%d-%H:%M:%S")] [$(GET_PID AutoUpdate.sh)] $*" >> ${AutoUpdate_Log_Path}/AutoUpdate.log } CHECK_PKG() { @@ -225,10 +250,9 @@ CHANGE_GITHUB() { ECHO r "错误的 Github 地址,示例: https://github.com/Hyy2001X/AutoBuild-Actions" EXIT 1 } - UCI_Github_URL=$(uci get autoupdate.@common[0].github 2>/dev/null) + UCI_Github_URL=$(UCI_GET autoupdate common github) [[ -n ${UCI_Github_URL} && ! ${UCI_Github_URL} == $1 ]] && { - uci set autoupdate.@common[0].github=$1 - uci commit autoupdate + UCI_SET autoupdate common github $1 ECHO y "UCI 设置已更新!" } [[ ! ${Github} == $1 ]] && { @@ -590,6 +614,14 @@ AutoUpdate_Main() { while [[ $1 ]];do case "$1" in + --sleep) + shift + sleep $1 + ;; + --pid) + shift + GET_PID $* + ;; -V) shift case "$1" in @@ -665,16 +697,6 @@ AutoUpdate_Main() { -n | -f | -u | -T | --test | -P | --proxy | -F) PREPARE_UPGRADES $* ;; - --corn-rm) - [ ! -f /etc/crontabs/root ] && EXIT 1 - shift && [[ -n $* ]] && SHELL_HELP - [[ $(cat /etc/crontabs/root) =~ AutoUpdate ]] && { - sed -i '/AutoUpdate/d' /etc/crontabs/root >/dev/null 2>&1 - ECHO y "已删除所有 AutoUpdate 相关计划任务!" - /etc/init.d/cron restart - EXIT 0 - } || EXIT 1 - ;; -U) shift && [[ -n $* ]] && SHELL_HELP CHECK_UPDATES check @@ -738,7 +760,7 @@ AutoUpdate_Main() { done } -Version=V6.3.1 +Version=V6.3.2 AutoUpdate_Path=/tmp/AutoUpdate AutoUpdate_Log_Path=/tmp AutoUpdate_Script_URL=https://ghproxy.com/https://raw.githubusercontent.com/Hyy2001X/AutoBuild-Actions/master/Scripts/AutoUpdate.sh