回退shell [

This commit is contained in:
whyour 2021-11-07 19:18:36 +08:00
parent 1b88853a8d
commit 62596f27ef
6 changed files with 44 additions and 44 deletions

View File

@ -6,7 +6,7 @@ get_token() {
add_cron_api() {
local currentTimeStamp=$(date +%s)
if [[ $# -eq 1 ]]; then
if [ $# -eq 1 ]; then
local schedule=$(echo "$1" | awk -F ":" '{print $1}')
local command=$(echo "$1" | awk -F ":" '{print $2}')
local name=$(echo "$1" | awk -F ":" '{print $3}')
@ -39,7 +39,7 @@ add_cron_api() {
update_cron_api() {
local currentTimeStamp=$(date +%s)
if [[ $# -eq 1 ]]; then
if [ $# -eq 1 ]; then
local schedule=$(echo "$1" | awk -F ":" '{print $1}')
local command=$(echo "$1" | awk -F ":" '{print $2}')
local name=$(echo "$1" | awk -F ":" '{print $3}')
@ -75,7 +75,7 @@ update_cron_api() {
update_cron_command_api() {
local currentTimeStamp=$(date +%s)
if [[ $# -eq 1 ]]; then
if [ $# -eq 1 ]; then
local command=$(echo "$1" | awk -F ":" '{print $1}')
local id=$(echo "$1" | awk -F ":" '{print $2}')
else

View File

@ -11,7 +11,7 @@ apk --no-cache add -f zlib-dev gcc jpeg-dev python3-dev musl-dev freetype-dev
echo -e "\nbot依赖安装成功...\n"
echo -e "2、下载bot所需文件...\n"
if [[ ! -d ${repo_path}/.git ]]; then
if [ ! -d ${repo_path}/.git ]; then
rm -rf ${repo_path}
git_clone_scripts ${url} ${repo_path} "main"
fi

View File

@ -27,7 +27,7 @@ remove_js_log() {
remove_empty_dir() {
cd $dir_log
for dir in $(ls); do
if [[ -d $dir ]] && [[ -z $(ls $dir) ]]; then
if [ -d $dir ] && [[ -z $(ls $dir) ]]; then
rm -rf $dir
fi
done

View File

@ -60,8 +60,8 @@ init_env() {
}
import_config() {
[[ -f $file_config_user ]] && . $file_config_user
[[ -f $file_env ]] && . $file_env
[ -f $file_config_user ] && . $file_config_user
[ -f $file_env ] && . $file_env
command_timeout_time=${CommandTimeoutTime:-"1h"}
github_proxy_url=${GithubProxyUrl:-""}
@ -101,7 +101,7 @@ gen_random_num() {
link_shell_sub() {
local link_path="$1"
local original_path="$2"
if [[ ! -L $link_path ]] || [[ $(readlink -f $link_path) != $original_path ]]; then
if [ ! -L $link_path ] || [[ $(readlink -f $link_path) != $original_path ]]; then
rm -f $link_path 2>/dev/null
ln -sf $original_path $link_path
fi
@ -110,7 +110,7 @@ link_shell_sub() {
link_shell() {
if [[ $is_termux -eq 1 ]]; then
local path="/data/data/com.termux/files/usr/bin/"
elif [[ $PATH == */usr/local/bin* ]] && [[ -d /usr/local/bin ]]; then
elif [[ $PATH == */usr/local/bin* ]] && [ -d /usr/local/bin ]; then
local path="/usr/local/bin/"
else
local path=""
@ -127,14 +127,14 @@ define_cmd() {
local cmd_prefix cmd_suffix
if type task &>/dev/null; then
cmd_suffix=""
if [[ -x "$dir_shell/task.sh" ]]; then
if [ -x "$dir_shell/task.sh" ]; then
cmd_prefix=""
else
cmd_prefix="bash "
fi
else
cmd_suffix=".sh"
if [[ -x "$dir_shell/task.sh" ]]; then
if [ -x "$dir_shell/task.sh" ]; then
cmd_prefix="$dir_shell/"
else
cmd_prefix="bash $dir_shell/"
@ -155,55 +155,55 @@ fix_config() {
make_dir $dir_raw
make_dir $dir_update_log
if [[ ! -s $file_config_user ]]; then
if [ ! -s $file_config_user ]; then
echo -e "复制一份 $file_config_sample$file_config_user,随后请按注释编辑你的配置文件:$file_config_user\n"
cp -fv $file_config_sample $file_config_user
echo
fi
if [[ ! -f $file_env ]]; then
if [ ! -f $file_env ]; then
echo -e "检测到config配置目录下不存在env.sh创建一个空文件用于初始化...\n"
touch $file_env
echo
fi
if [[ ! -f $file_task_before ]]; then
if [ ! -f $file_task_before ]; then
echo -e "复制一份 $file_task_sample$file_task_before\n"
cp -fv $file_task_sample $file_task_before
echo
fi
if [[ ! -f $file_task_after ]]; then
if [ ! -f $file_task_after ]; then
echo -e "复制一份 $file_task_sample$file_task_after\n"
cp -fv $file_task_sample $file_task_after
echo
fi
if [[ ! -f $file_extra_shell ]]; then
if [ ! -f $file_extra_shell ]; then
echo -e "复制一份 $file_extra_sample$file_extra_shell\n"
cp -fv $file_extra_sample $file_extra_shell
echo
fi
if [[ ! -s $file_auth_user ]]; then
if [ ! -s $file_auth_user ]; then
echo -e "复制一份 $file_auth_sample$file_auth_user\n"
cp -fv $file_auth_sample $file_auth_user
echo
fi
if [[ ! -s $file_notify_py ]]; then
if [ ! -s $file_notify_py ]; then
echo -e "复制一份 $file_notify_py_sample$file_notify_py\n"
cp -fv $file_notify_py_sample $file_notify_py
echo
fi
if [[ ! -s $file_notify_js ]]; then
if [ ! -s $file_notify_js ]; then
echo -e "复制一份 $file_notify_js_sample$file_notify_js\n"
cp -fv $file_notify_js_sample $file_notify_js
echo
fi
if [[ -s /etc/nginx/conf.d/default.conf ]]; then
if [ -s /etc/nginx/conf.d/default.conf ]; then
echo -e "检测到默认nginx配置文件清空...\n"
cat /dev/null > /etc/nginx/conf.d/default.conf
echo
@ -211,7 +211,7 @@ fix_config() {
}
npm_install_sub() {
if [[ $is_termux -eq 1 ]]; then
if [ $is_termux -eq 1 ]; then
npm install --production --no-bin-links --registry=https://registry.npm.taobao.org || npm install --production --no-bin-links
elif ! type pnpm &>/dev/null; then
npm install --production --registry=https://registry.npm.taobao.org || npm install --production
@ -248,7 +248,7 @@ npm_install_2() {
diff_and_copy() {
local copy_source=$1
local copy_to=$2
if [[ ! -s $copy_to ]] || [[ $(diff $copy_source $copy_to) ]]; then
if [ ! -s $copy_to ] || [[ $(diff $copy_source $copy_to) ]]; then
cp -f $copy_source $copy_to
fi
}
@ -256,7 +256,7 @@ diff_and_copy() {
update_depend() {
local dir_current=$(pwd)
if [[ ! -s $dir_scripts/package.json ]] || [[ $(diff $dir_sample/package.json $dir_scripts/package.json) ]]; then
if [ ! -s $dir_scripts/package.json ] || [[ $(diff $dir_sample/package.json $dir_scripts/package.json) ]]; then
cp -f $dir_sample/package.json $dir_scripts/package.json
npm_install_2 $dir_scripts
fi
@ -296,7 +296,7 @@ reset_romote_url() {
[[ $branch ]] && local part_cmd="origin/${branch}"
if [[ -d "$dir_work/.git" ]]; then
if [ -d "$dir_work/.git" ]; then
cd $dir_work
[[ -f ".git/index.lock" ]] && rm -f .git/index.lock >/dev/null
git remote set-url origin $url >/dev/null

View File

@ -39,7 +39,7 @@ gen_array_scripts() {
local i="-1"
cd $dir_scripts
for file in $(ls); do
if [[ -f $file ]] && [[ $file == *.js && $file != sendNotify.js ]]; then
if [ -f $file ] && [[ $file == *.js && $file != sendNotify.js ]]; then
let i++
array_scripts[i]=$(echo "$file" | perl -pe "s|$dir_scripts/||g")
array_scripts_name[i]=$(grep "new Env" $file | awk -F "'|\"" '{print $2}' | head -1)
@ -170,7 +170,7 @@ run_concurrent() {
for i in "${!array[@]}"; do
single_log_path="$log_dir/${single_log_time}_$((i + 1)).log"
eval cat $single_log_path $cmd
[[ -f $single_log_path ]] && rm -f $single_log_path
[ -f $single_log_path ] && rm -f $single_log_path
done
eval . $file_task_after "$@" $cmd

View File

@ -12,12 +12,12 @@ diff_cron() {
local list_task="$2"
local list_add="$3"
local list_drop="$4"
if [[ -s $list_task ]]; then
if [ -s $list_task ]; then
grep -vwf $list_task $list_scripts >$list_add
elif [[ ! -s $list_task ]] && [[ -s $list_scripts ]]; then
elif [ ! -s $list_task ] && [ -s $list_scripts ]; then
cp -f $list_scripts $list_add
fi
if [[ -s $list_scripts ]]; then
if [ -s $list_scripts ]; then
grep -vwf $list_scripts $list_task >$list_drop
else
cp -f $list_task $list_drop
@ -28,18 +28,18 @@ diff_cron() {
detect_config_version() {
## 识别出两个文件的版本号
ver_config_sample=$(grep " Version: " $file_config_sample | perl -pe "s|.+v((\d+\.?){3})|\1|")
[[ -f $file_config_user ]] && ver_config_user=$(grep " Version: " $file_config_user | perl -pe "s|.+v((\d+\.?){3})|\1|")
[ -f $file_config_user ] && ver_config_user=$(grep " Version: " $file_config_user | perl -pe "s|.+v((\d+\.?){3})|\1|")
## 删除旧的发送记录文件
[[ -f $send_mark ]] && [[ $(cat $send_mark) != $ver_config_sample ]] && rm -f $send_mark
[ -f $send_mark ] && [[ $(cat $send_mark) != $ver_config_sample ]] && rm -f $send_mark
## 识别出更新日期和更新内容
update_date=$(grep " Date: " $file_config_sample | awk -F ": " '{print $2}')
update_content=$(grep " Update Content: " $file_config_sample | awk -F ": " '{print $2}')
## 如果是今天,并且版本号不一致,则发送通知
if [[ -f $file_config_user ]] && [[ $ver_config_user != $ver_config_sample ]] && [[ $update_date == $(date "+%Y-%m-%d") ]]; then
if [[ ! -f $send_mark ]]; then
if [ -f $file_config_user ] && [[ $ver_config_user != $ver_config_sample ]] && [[ $update_date == $(date "+%Y-%m-%d") ]]; then
if [ ! -f $send_mark ]; then
local notify_title="配置文件更新通知"
local notify_content="更新日期: $update_date\n用户版本: $ver_config_user\n新的版本: $ver_config_sample\n更新内容: $update_content\n更新说明: 如需使用新功能请对照config.sample.sh将相关新参数手动增加到你自己的config.sh中否则请无视本消息。本消息只在该新版本配置文件更新当天发送一次。\n"
echo -e $notify_content
@ -47,7 +47,7 @@ detect_config_version() {
[[ $? -eq 0 ]] && echo $ver_config_sample >$send_mark
fi
else
[[ -f $send_mark ]] && rm -f $send_mark
[ -f $send_mark ] && rm -f $send_mark
fi
}
@ -55,7 +55,7 @@ detect_config_version() {
output_list_add_drop() {
local list=$1
local type=$2
if [[ -s $list ]]; then
if [ -s $list ]; then
echo -e "检测到有$type的定时任务\n"
cat $list
echo
@ -105,7 +105,7 @@ add_cron() {
cd $dir_scripts
for file in $(cat $list_add); do
local file_name=${file/${path}\_/}
if [[ -f $file ]]; then
if [ -f $file ]; then
cron_line=$(
perl -ne "{
print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*$file_name/
@ -153,7 +153,7 @@ update_repo() {
[[ ! $url =~ "https://ghproxy.com" ]] && formatUrl="${github_proxy_url}${url}"
fi
fi
if [[ -d ${repo_path}/.git ]]; then
if [ -d ${repo_path}/.git ]; then
reset_romote_url ${repo_path} "${formatUrl}" "${branch}"
git_pull_scripts ${repo_path} "${branch}"
else
@ -219,7 +219,7 @@ update_raw() {
fi
else
echo -e "下载 ${raw_file_name} 失败,保留之前正常下载的版本...\n"
[[ -f "$dir_raw/${raw_file_name}.new" ]] && rm -f "$dir_raw/${raw_file_name}.new"
[ -f "$dir_raw/${raw_file_name}.new" ] && rm -f "$dir_raw/${raw_file_name}.new"
fi
}
@ -227,7 +227,7 @@ update_raw() {
## 调用用户自定义的extra.sh
run_extra_shell() {
if [[ ${EnableExtraShell} == true ]]; then
if [[ -f $file_extra_shell ]]; then
if [ -f $file_extra_shell ]; then
echo -e "--------------------------------------------------------------\n"
. $file_extra_shell
else
@ -255,7 +255,7 @@ update_qinglong() {
patch_version
local no_restart="$1"
[[ -f $dir_root/package.json ]] && ql_depend_old=$(cat $dir_root/package.json)
[ -f $dir_root/package.json ] && ql_depend_old=$(cat $dir_root/package.json)
reset_romote_url ${dir_root} "${github_proxy_url}https://github.com/whyour/qinglong.git" "master"
git_pull_scripts $dir_root "master"
@ -265,14 +265,14 @@ update_qinglong() {
detect_config_version
update_depend
[[ -f $dir_root/package.json ]] && ql_depend_new=$(cat $dir_root/package.json)
[ -f $dir_root/package.json ] && ql_depend_new=$(cat $dir_root/package.json)
[[ "$ql_depend_old" != "$ql_depend_new" ]] && npm_install_2 $dir_root
else
echo -e "\n更新$dir_root失败,请检查原因...\n"
fi
local url="${github_proxy_url}https://github.com/whyour/qinglong-static.git"
if [[ -d ${ql_static_repo}/.git ]]; then
if [ -d ${ql_static_repo}/.git ]; then
reset_romote_url ${ql_static_repo} ${url} "master"
git_pull_scripts ${ql_static_repo} "master"
else
@ -344,13 +344,13 @@ diff_scripts() {
local list_drop="$dir_list_tmp/${repo}_drop.list"
diff_cron "$dir_list_tmp/${repo}_scripts.list" "$dir_list_tmp/${repo}_user.list" $list_add $list_drop
if [[ -s $list_drop ]]; then
if [ -s $list_drop ]; then
output_list_add_drop $list_drop "失效"
if [[ ${AutoDelCron} == true ]]; then
del_cron $list_drop $repo
fi
fi
if [[ -s $list_add ]]; then
if [ -s $list_add ]; then
output_list_add_drop $list_add "新"
if [[ ${AutoAddCron} == true ]]; then
add_cron $list_add $repo