mirror of
https://github.com/juewuy/ShellCrash.git
synced 2026-03-11 07:51:45 +00:00
Merge branch 'master' into dev
# Conflicts: # ShellCrash.tar.gz # bin/version # scripts/menus/5_task.sh # version
This commit is contained in:
@@ -4,15 +4,16 @@ __IS_LIB_LOGGER=1
|
||||
|
||||
#日志工具
|
||||
. "$CRASHDIR"/libs/web_json.sh
|
||||
#$1日志内容$2显示颜色$3是否推送
|
||||
#$1日志内容$2显示颜色$3是否推送$4是否覆盖上一条
|
||||
logger() {
|
||||
TMPDIR=/tmp/ShellCrash
|
||||
[ -n "$2" -a "$2" != 0 ] && printf "\033[%sm%s\033[0m\n" "$2" "$1"
|
||||
log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1"
|
||||
[ "$4" = on ] && sed -i "/$1/d" "$TMPDIR"/ShellCrash.log
|
||||
echo "$log_text" >>"$TMPDIR"/ShellCrash.log
|
||||
[ "$(wc -l "$TMPDIR"/ShellCrash.log | awk '{print $1}')" -gt 199 ] && sed -i '1,20d' "$TMPDIR"/ShellCrash.log
|
||||
#推送远程日志
|
||||
[ -z "$3" ] && {
|
||||
[ "$3" != off ] && {
|
||||
[ -n "$device_name" ] && log_text="$log_text($device_name)"
|
||||
[ -n "$push_TG" ] && {
|
||||
url="https://api.telegram.org/bot${push_TG}/sendMessage"
|
||||
|
||||
@@ -1,27 +1,38 @@
|
||||
|
||||
crondir="$(crond -h 2>&1 | grep -oE 'Default:.*' | awk -F ":" '{print $2}')"
|
||||
crondir="$(crond -h 2>&1 | grep -oE 'Default:.*' | awk -F ":" '{print $2}'| tr -d ' ')"
|
||||
[ ! -w "$crondir" ] && crondir="/etc/storage/cron/crontabs"
|
||||
[ ! -w "$crondir" ] && crondir="/var/spool/cron/crontabs"
|
||||
[ ! -w "$crondir" ] && crondir="/var/spool/cron"
|
||||
[ -z "$USER" ] && USER=$(whoami 2>/dev/null)
|
||||
tmpcron=/tmp/cron_tmp
|
||||
touch "$tmpcron"
|
||||
|
||||
croncmd() { #定时任务工具
|
||||
if [ -w "$crondir" ] && [ -n "$USER" ];then
|
||||
[ "$1" = "-l" ] && cat "$crondir"/"$USER" 2>/dev/null
|
||||
[ -f "$1" ] && cat "$1" >"$crondir"/"$USER"
|
||||
killall -HUP crond 2>/dev/null
|
||||
elif [ -n "$(crontab -h 2>&1 | grep '\-l')" ]; then
|
||||
cronadd() { #定时任务工具
|
||||
if crontab -h 2>&1 | grep -q '\-l'; then
|
||||
crontab "$1"
|
||||
else
|
||||
cat "$1" >"$crondir"/"$USER" && cru a REFRESH "0 0 1 1 * /bin/true" 2>/dev/null
|
||||
fi
|
||||
}
|
||||
cronload() { #定时任务工具
|
||||
if [ -f "$crondir/$USER" ];then
|
||||
cat "$crondir"/"$USER" 2>/dev/null
|
||||
elif crontab -h 2>&1 | grep -q '\-l'; then
|
||||
crontab -l
|
||||
else
|
||||
echo "找不到可用的crond或者crontab应用!No available crond or crontab application can be found!"
|
||||
fi
|
||||
}
|
||||
cronset() { #定时任务设置
|
||||
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
|
||||
croncmd -l >"$tmpcron"
|
||||
sed -i "/$1/d" "$tmpcron"
|
||||
echo "$2" >>"$tmpcron"
|
||||
croncmd "$tmpcron"
|
||||
rm -f "$tmpcron"
|
||||
cronload | grep -v '^$' | grep -vF "$1" >"$tmpcron"
|
||||
[ -n "$2" ] && echo "$2" >>"$tmpcron"
|
||||
cronadd "$tmpcron"
|
||||
#华硕/Padavan固件存档在本地,其他则删除
|
||||
if [ -d /jffs ] || [ -d /etc/storage/ShellCrash ];then
|
||||
mv -f "$tmpcron" "$CRASHDIR"/task/cron
|
||||
else
|
||||
rm -f "$tmpcron"
|
||||
fi
|
||||
sleep 1
|
||||
}
|
||||
|
||||
@@ -13,18 +13,26 @@ webget(){
|
||||
#参数【$1】代表下载目录,【$2】代表在线地址
|
||||
#参数【$3】代表输出显示,【$4】不启用重定向
|
||||
#参数【$5】代表验证证书,【$6】使用自定义UA
|
||||
[ -n "$6" ] && agent="--user-agent \"$6\""
|
||||
[ -n "$6" ] && agent="--user-agent $6"
|
||||
if wget --help 2>&1 | grep -q 'show-progress' >/dev/null 2>&1; then
|
||||
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
|
||||
[ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
|
||||
[ "$5" = "skipceroff" ] && certificate='' || certificate='--no-check-certificate'
|
||||
if [ "$5" = "skipceroff" ] || [ "$skip_cert" = OFF ];then
|
||||
certificate=''
|
||||
else
|
||||
certificate='--no-check-certificate'
|
||||
fi
|
||||
wget -Y on $agent $progress $redirect $certificate --timeout=3 -O "$1" "$url" && return 0 #成功则退出否则重试
|
||||
wget -Y off $agent $progress $redirect $certificate --timeout=5 -O "$1" "$2"
|
||||
return $?
|
||||
elif curl --version >/dev/null 2>&1; then
|
||||
[ "$3" = "echooff" ] && progress='-s' || progress='-#'
|
||||
[ "$4" = "rediroff" ] && redirect='' || redirect='-L'
|
||||
[ "$5" = "skipceroff" ] && certificate='' || certificate='-k'
|
||||
if [ "$5" = "skipceroff" ] || [ "$skip_cert" = OFF ];then
|
||||
certificate=''
|
||||
else
|
||||
certificate='-k'
|
||||
fi
|
||||
if curl --version | grep -q '^curl 8.' && ckcmd base64; then
|
||||
auth_b64=$(printf '%s' "$authentication" | base64)
|
||||
result=$(curl $agent -w '%{http_code}' --connect-timeout 3 --proxy-header "Proxy-Authorization: Basic $auth_b64" $progress $redirect $certificate -o "$1" "$url")
|
||||
|
||||
Reference in New Issue
Block a user