diff --git a/Scripts/sh/Helpcode2.8/code.sh b/Scripts/sh/Helpcode2.8/code.sh index dbccc36..820a23a 100644 --- a/Scripts/sh/Helpcode2.8/code.sh +++ b/Scripts/sh/Helpcode2.8/code.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -## Build 20210728-002 +## Build 20210805-002 ## 导入通用变量与函数 dir_shell=/ql/shell @@ -15,7 +15,7 @@ repo3='he1pu_JDHelp' #预设的 he1pu 仓库 repo4='shufflewzc_faker2' #预设的 shufflewzc 仓库 repo5='Wenmoux_scripts_wen_chinnkarahoi' #预设的 Wenmoux 仓库,用于读取口袋书店互助码。需提前拉取温某人的仓库或口袋书店脚本并完整运行。 repo6='Aaron-lv_sync_jd_scripts' #预设的 Aaron-lv 仓库 -repo=$repo4 #默认调用 shufflewzc 仓库脚本日志 +repo=$repo6 #默认调用 Aaron-lv 仓库脚本日志 ## 调试模式开关,默认是0,表示关闭;设置为1,表示开启 DEBUG="1" @@ -133,11 +133,12 @@ name_js=( "$repo"_jd_bookshop "$repo"_jd_cash "$repo"_jd_sgmh - "$repo6"_jd_cfd + "$repo"_jd_cfd "$repo"_jd_health "$repo"_jd_carnivalcity "$repo"_jd_city "$repo4"_jd_moneyTree_heip + "$repo"_jd_cfd ) name_config=( @@ -157,6 +158,7 @@ name_config=( Carni City MoneyTree + TokenJxnc ) name_chinese=( @@ -176,18 +178,6 @@ name_chinese=( 京东手机狂欢城 城城领现金 摇钱树 -) - -#仅输出互助码的环境变量 -name_js_only=( - "$repo6"_jd_cfd -) - -name_config_only=( - TokenJxnc -) - -name_chinese_only=( 京喜token ) @@ -422,38 +412,44 @@ local envs=$(eval echo "\$JD_COOKIE") local array=($(echo $envs | sed 's/&/ /g')) local user_sum=${#array[*]} local config_name=$1 +local chinese_name=$2 local config_name_my=My$config_name local config_name_for_other=ForOther$config_name +local ShareCode_dir="$dir_log/.ShareCode" +local ShareCode_log="$ShareCode_dir/$config_name.log" local i j k #更新配置文件中的互助码 -if [ -z "$(cat $file_task_before | grep "^$config_name_my\d")" ]; then - echo -e "\n${config_name_my}1=''\n" >> $file_task_before +[[ ! -d $ShareCode_dir ]] && mkdir -p $ShareCode_dir +[[ "$1" = "TokenJxnc" ]] && config_name_my=$1 +if [ ! -f $ShareCode_log ] || [ -z "$(cat $ShareCode_log | grep "^$config_name_my\d")" ]; then + echo -e "\n## $chinese_name\n${config_name_my}1=''\n" >> $ShareCode_log fi for ((i=1; i<=100; i++)); do + local new_code="$(cat $log_path | grep "^$config_name_my$i=.*'$" | sed "s/.*'\(.*\)'.*/\1/")" + local old_code="$(cat $ShareCode_log | grep "^$config_name_my$i=.*'$" | sed "s/.*'\(.*\)'.*/\1/")" if [[ $i -le $user_sum ]] && [[ ! -z "$(cat $log_path | grep "^$config_name_my$i=.*'$")" ]]; then - new_code="$(cat $log_path | grep "^$config_name_my$i=.*'$" | sed "s/.*'\(.*\)'.*/\1/")" - old_code="$(cat $file_task_before | grep "^$config_name_my$i=.*'$" | sed "s/.*'\(.*\)'.*/\1/")" - if [ -z "$(grep "^$config_name_my$i" $file_task_before)" ]; then - sed -i "/^$config_name_my$[$i-1]='.*'/ s/$/\n$config_name_my$i=\'\'/" $file_task_before + if [ -z "$(grep "^$config_name_my$i" $ShareCode_log)" ]; then + sed -i "/^$config_name_my$[$i-1]='.*'/ s/$/\n$config_name_my$i=\'\'/" $ShareCode_log fi if [ "$new_code" != "$old_code" ]; then # if [ $1 = "BookShop" ]; then # if [[ "$new_code" != "undefined" ]] && [[ "$new_code" != "{}" ]] && [[ "$new_code" != "" ]]; then -# sed -i "s/^$config_name_my$i='$old_code'$/$config_name_my$i='$new_code'/" $file_task_before +# sed -i "s/^$config_name_my$i='$old_code'$/$config_name_my$i='$new_code'/" $ShareCode_log # fi # else if [[ "$new_code" != "undefined" ]] && [[ "$new_code" != "{}" ]] || [[ "$new_code" = "" ]]; then - sed -i "s/^$config_name_my$i='$old_code'$/$config_name_my$i='$new_code'/" $file_task_before + sed -i "s/^$config_name_my$i='$old_code'$/$config_name_my$i='$new_code'/" $ShareCode_log fi # fi fi - elif [[ $i -gt $user_sum ]] && [[ $i -gt 1 ]] && [[ ! -z "$(cat $file_task_before | grep "^$config_name_my$i")" ]]; then - sed -i "/^$config_name_my$i/d" $file_task_before - elif [[ $i -eq 1 ]] && [[ ! -z "$(cat $file_task_before | grep "^$config_name_my$i")" ]]; then - sed -i "s/^$config_name_my$i='\S*'$/$config_name_my$i=''/" $file_task_before + elif [[ $i -gt $user_sum ]] && [[ $i -gt 1 ]] && [[ ! -z "$(cat $ShareCode_log | grep "^$config_name_my$i")" ]]; then + sed -i "/^$config_name_my$i/d" $ShareCode_log + elif [[ $i -eq 1 ]] && [[ ! -z "$(cat $ShareCode_log | grep "^$config_name_my$i")" ]]; then + sed -i "s/^$config_name_my$i='\S*'$/$config_name_my$i=''/" $ShareCode_log fi done +sed -i "1c ## 上次导入时间:$(date +%Y年%m月%d日\ %X)" $ShareCode_log } #更新配置文件中互助规则的函数 @@ -462,63 +458,34 @@ local envs=$(eval echo "\$JD_COOKIE") local array=($(echo $envs | sed 's/&/ /g')) local user_sum=${#array[*]} local config_name=$1 +local chinese_name=$2 local config_name_my=My$config_name local config_name_for_other=ForOther$config_name +local ShareCode_dir="$dir_log/.ShareCode" +local ShareCode_log="$ShareCode_dir/$config_name.log" local i j k #更新配置文件中的互助规则 -if [ -z "$(cat $file_task_before | grep "^$config_name_for_other\d")" ]; then - echo -e "${config_name_for_other}1=\"\"\n" >> $file_task_before +if [ -z "$(cat $ShareCode_log | grep "^$config_name_for_other\d")" ]; then + echo -e "${config_name_for_other}1=\"\"" >> $ShareCode_log fi for ((j=1; j<=100; j++)); do - if [[ $j -le $user_sum ]] && [[ ! -z "$(cat $log_path | grep "^$config_name_for_other$j=.*\"$")" ]]; then - new_rule="$(cat $log_path | grep "^$config_name_for_other$j=.*\"$" | sed "s/.*\"\(.*\)\".*/\1/")" - old_rule="$(cat $file_task_before | grep "^$config_name_for_other$j=.*\"$" | sed "s/.*\"\(.*\)\".*/\1/")" - if [ -z "$(grep "^$config_name_for_other$j" $file_task_before)" ]; then - sed -i "/^$config_name_for_other$[$j-1]=".*"/ s/$/\n$config_name_for_other$j=\"\"/" $file_task_before + local new_rule="$(cat $log_path | grep "^$config_name_for_other$j=.*\"$" | sed "s/.*\"\(.*\)\".*/\1/")" + local old_rule="$(cat $ShareCode_log | grep "^$config_name_for_other$j=.*\"$" | sed "s/.*\"\(.*\)\".*/\1/")" + if [[ $j -le $user_sum ]] && [[ ! -z $new_rule ]]; then + if [ -z "$(grep "^$config_name_for_other$j" $ShareCode_log)" ]; then + sed -i "/^$config_name_for_other$[$j-1]=".*"/ s/$/\n$config_name_for_other$j=\"\"/" $ShareCode_log fi if [ "$new_rule" != "$old_rule" ]; then - sed -i "s/^$config_name_for_other$j=\"$old_rule\"$/$config_name_for_other$j=\"$new_rule\"/" $file_task_before + sed -i "s/^$config_name_for_other$j=\"$old_rule\"$/$config_name_for_other$j=\"$new_rule\"/" $ShareCode_log fi - elif [[ $j -gt $user_sum ]] && [[ $j -gt 1 ]] && [[ ! -z "$(cat $file_task_before | grep "^$config_name_for_other$j")" ]]; then - sed -i "/^$config_name_for_other$j/d" $file_task_before - elif [[ $j -eq 1 ]] && [[ ! -z "$(cat $file_task_before | grep "^$config_name_for_other$j")" ]]; then - sed -i "s/^$config_name_for_other$j=\"\S*\"$/$config_name_for_other$j=\"\"/" $file_task_before - fi -done -} - -help_codes_only(){ -local envs=$(eval echo "\$JD_COOKIE") -local array=($(echo $envs | sed 's/&/ /g')) -local user_sum=${#array[*]} -local config_name=$1 -local config_name_my=My$config_name -local config_name_for_other=ForOther$config_name -local i j k - -#更新配置文件中的互助码 -if [ -z "$(cat $file_task_before | grep "^$config_name\d")" ]; then - echo -e "\n${config_name}1=''\n" >> $file_task_before -fi -for ((k=1; k<=100; k++)); do - if [[ $k -le $user_sum ]] && [[ ! -z "$(cat $log_path | grep "^$config_name$k=.*'$")" ]]; then - new_code="$(cat $log_path | grep "^$config_name$k=.*'$" | sed "s/.*'\(.*\)'.*/\1/")" - old_code="$(cat $file_task_before | grep "^$config_name$k=.*'$" | sed "s/.*'\(.*\)'.*/\1/")" - if [ -z "$(grep "^$config_name$k" $file_task_before)" ]; then - sed -i "/^$config_name$[$k-1]='.*'/ s/$/\n$config_name$k=\'\'/" $file_task_before - fi - if [ "$new_code" != "$old_code" ]; then - if [[ "$new_code" != "undefined" ]] && [[ "$new_code" != "{}" ]] || [[ "$new_code" = "" ]]; then - sed -i "s/^$config_name$k='$old_code'$/$config_name$k='$new_code'/" $file_task_before - fi - fi - elif [[ $k -gt $user_sum ]] && [[ $k -gt 1 ]] && [[ ! -z "$(cat $file_task_before | grep "^$config_name$k")" ]]; then - sed -i "/^$config_name$k/d" $file_task_before - elif [[ $k -eq 1 ]] && [[ ! -z "$(cat $file_task_before | grep "^$config_name$k")" ]]; then - sed -i "s/^$config_name$k='\S*'$/$config_name$k=''/" $file_task_before + elif [[ $j -gt $user_sum ]] && [[ $j -gt 1 ]] && [[ ! -z "$(cat $ShareCode_log | grep "^$config_name_for_other$j")" ]]; then + sed -i "/^$config_name_for_other$j/d" $ShareCode_log + elif [[ $j -eq 1 ]] && [[ ! -z "$(cat $ShareCode_log | grep "^$config_name_for_other$j")" ]]; then + sed -i "s/^$config_name_for_other$j=\"\S*\"$/$config_name_for_other$j=\"\"/" $ShareCode_log fi done +sed -i "1c ## 上次导入时间:$(date +%Y年%m月%d日\ %X)" $ShareCode_log } export_codes_sub_only(){ @@ -566,63 +533,46 @@ fi #更新互助码和互助规则 update_help(){ -#latest_log=$(ls -r $dir_code | head -1) -latest_log=$log_path case $UpdateType in 1) - if [ "$ps_num" -le $proc_num ] && [ -f $log_path ] && [ -f $file_task_before ]; then + if [ "$ps_num" -le $proc_num ] && [ -f $log_path ]; then backup_del - echo -e "\n#$cur_time 开始更新配置文件的互助码和互助规则" | tee -a $latest_log - for i in ${name_config[@]}; do - help_codes $i - help_rules $i + echo -e "\n#$cur_time 开始更新配置文件的互助码和互助规则" + for ((i = 0; i < ${#name_config[*]}; i++)); do + help_codes "${name_config[i]}" "${name_chinese[i]}" + [[ "${name_config[i]}" != "TokenJxnc" ]] && help_rules "${name_config[i]}" "${name_chinese[i]}" done - for i in ${name_config_only[@]}; do - help_codes_only $i - done - sed -i "4c ## 上次导入时间:$(date +%Y年%m月%d日\ %X)" /ql/config/task_before.sh - echo -e "\n#$cur_time 配置文件的互助码和互助规则已完成更新" | tee -a $latest_log + echo -e "\n#$cur_time 配置文件的互助码和互助规则已完成更新" elif [ ! -f $log_path ]; then - echo -e "\n#$cur_time 日志文件不存在,请检查后重试!" | tee -a $latest_log - elif [ ! -f $file_task_before ]; then - echo -e "\n#$cur_time 配置文件不存在,请检查后重试!" | tee -a $latest_log + echo -e "\n#$cur_time 日志文件不存在,请检查后重试!" fi ;; 2) - if [ "$ps_num" -le $proc_num ] && [ -f $log_path ] && [ -f $file_task_before ]; then + if [ "$ps_num" -le $proc_num ] && [ -f $log_path ]; then backup_del - echo -e "\n#$cur_time 开始更新配置文件的互助码,不更新互助规则" | tee -a $latest_log - for i in ${name_config[@]}; do - help_codes $i + echo -e "\n#$cur_time 开始更新配置文件的互助码,不更新互助规则" + for ((i = 0; i < ${#name_config[*]}; i++)); do + help_codes "${name_config[i]}" "${name_chinese[i]}" done - for i in ${name_config_only[@]}; do - help_codes_only $i - done - sed -i "4c ## 上次导入时间:$(date +%Y年%m月%d日\ %X)" /ql/config/task_before.sh - echo -e "\n#$cur_time 配置文件的互助码已完成更新" | tee -a $latest_log + echo -e "\n#$cur_time 配置文件的互助码已完成更新" elif [ ! -f $log_path ]; then - echo -e "\n#$cur_time 日志文件不存在,请检查后重试!" | tee -a $latest_log - elif [ ! -f $file_task_before ]; then - echo -e "\n#$cur_time 配置文件不存在,请检查后重试!" | tee -a $latest_log + echo -e "\n#$cur_time 日志文件不存在,请检查后重试!" fi ;; 3) - if [ "$ps_num" -le $proc_num ] && [ -f $log_path ] && [ -f $file_task_before ]; then + if [ "$ps_num" -le $proc_num ] && [ -f $log_path ]; then backup_del - echo -e "\n#$cur_time 开始更新配置文件的互助规则,不更新互助码" | tee -a $latest_log - for i in ${name_config[@]}; do - help_rules $i + echo -e "\n#$cur_time 开始更新配置文件的互助规则,不更新互助码" + for ((i = 0; i < ${#name_config[*]}; i++)); do + [[ "${name_config[i]}" != "TokenJxnc" ]] && help_rules "${name_config[i]}" "${name_chinese[i]}" done - sed -i "4c ## 上次导入时间:$(date +%Y年%m月%d日\ %X)" /ql/config/task_before.sh - echo -e "\n#$cur_time 配置文件的互助规则已完成更新" | tee -a $latest_log + echo -e "\n#$cur_time 配置文件的互助规则已完成更新" elif [ ! -f $log_path ]; then - echo -e "\n#$cur_time 日志文件不存在,请检查后重试!" | tee -a $latest_log - elif [ ! -f $file_task_before ]; then - echo -e "\n#$cur_time 配置文件不存在,请检查后重试!" | tee -a $latest_log + echo -e "\n#$cur_time 日志文件不存在,请检查后重试!" fi ;; *) - echo -e "\n#$cur_time 您已设置不更新配置文件的互助码和互助规则,跳过更新!" | tee -a $latest_log + echo -e "\n#$cur_time 您已设置不更新配置文件的互助码和互助规则,跳过更新!" ;; esac } @@ -633,13 +583,32 @@ local envs=$(eval echo "\$JD_COOKIE") local array=($(echo $envs | sed 's/&/ /g')) for ((m = 0; m < ${#pt_pin[*]}; m++)); do j=$((m + 1)) - echo -e "## 用户名 $j:${pt_pin[m]}\n## Cookie$j=\"${array[m]}\"" + echo -e "## 用户名 $j:${pt_pin[m]}\nCookie$j=\"${array[m]}\"" done } backup_del(){ -[[ $BACKUP = "1" ]] && mkdir -p $dir_config/bak/ && cp $file_task_before $dir_config/bak/task_before_$log_time.sh -[[ $CLEANBAK = "1" ]] && find $dir_config/bak/ -type f -mtime +$CLEANBAK_DAYS | xargs rm -rvf +local bak_ShareCode_full_path_list=$(find $dir_log/.bak_ShareCode/ -name "*.log") +local diff_time +[[ ! -d $dir_log/.bak_ShareCode ]] && mkdir -p $dir_log/.bak_ShareCode +if [[ $BACKUP = "1" ]]; then + for ((i = 0; i < ${#name_config[*]}; i++)); do + [[ -f $dir_log/.ShareCode/${name_config[i]}.log ]] && cp $dir_log/.ShareCode/${name_config[i]}.log $dir_log/.bak_ShareCode/${name_config[i]}_$log_time.log + done +fi +if [[ $CLEANBAK = "1" ]]; then + for log in $bak_ShareCode_full_path_list; do + local log_date=$(echo $log | awk -F "_" '{print $NF}' | cut -c1-10) + if [[ $(date +%s -d $log_date 2>/dev/null) ]]; then + if [[ $is_macos -eq 1 ]]; then + diff_time=$(($(date +%s) - $(date -j -f "%Y-%m-%d" "$log_date" +%s))) + else + diff_time=$(($(date +%s) - $(date +%s -d "$log_date"))) + fi + [[ $diff_time -gt $(($CLEANBAK_DAYS * 86400)) ]] && rm -vf $log + fi + done +fi } install_dependencies_normal(){ @@ -718,9 +687,11 @@ log_path="$dir_code/$log_time.log" make_dir "$dir_code" ps_num="$(ps | grep code.sh | grep -v grep | wc -l)" #[[ ! -z "$(ps -ef|grep -w 'code.sh'|grep -v grep)" ]] && ps -ef|grep -w 'code.sh'|grep -v grep|awk '{print $1}'|xargs kill -9 -export_all_codes | perl -pe "{s|京东种豆|种豆|; s|crazyJoy任务|疯狂的JOY|}" | tee $log_path +export_all_codes | perl -pe "{s|京东种豆|种豆|; s|crazyJoy任务|疯狂的JOY|}" sleep 5 update_help ## 修改curtinlv入会领豆配置文件的参数 [[ -f /ql/repo/curtinlv_JD-Script/OpenCard/OpenCardConfig.ini ]] && sed -i "4c JD_COOKIE = '$(echo $JD_COOKIE | sed "s/&/ /g; s/\S*\(pt_key=\S\+;\)\S*\(pt_pin=\S\+;\)\S*/\1\2/g;" | perl -pe "s| |&|g")'" /ql/repo/curtinlv_JD-Script/OpenCard/OpenCardConfig.ini + +exit diff --git a/Scripts/sh/Helpcode2.8/task_before.sh b/Scripts/sh/Helpcode2.8/task_before.sh index 2f9219e..1f61eb1 100644 --- a/Scripts/sh/Helpcode2.8/task_before.sh +++ b/Scripts/sh/Helpcode2.8/task_before.sh @@ -1,107 +1,45 @@ #!/usr/bin/env bash -# Build 20210727-001 - -## 东东农场: -MyFruit1='' - -ForOtherFruit1="" - - -## 东东萌宠: -MyPet1='' - -ForOtherPet1="" - - -## 种豆得豆: -MyBean1='' - -ForOtherBean1="" - - -## 京喜工厂: -MyDreamFactory1='' - -ForOtherDreamFactory1="" - - -## 东东工厂: -MyJdFactory1='' - -ForOtherJdFactory1="" - - -## 疯狂的JOY: -MyJoy1='' - -ForOtherJoy1="" - - -## 京东赚赚: -MyJdzz1='' - -ForOtherJdzz1="" - - -## 京喜农场: -MyJxnc1='' - -ForOtherJxnc1="" - - -## 口袋书店: -MyBookShop1='' - -ForOtherBookShop1="" - - -## 签到领现金: -MyCash1='' - -ForOtherCash1="" - - -## 闪购盲盒: -MySgmh1='' - -ForOtherSgmh1="" - - -## 京喜财富岛: -MyCfd1='' - -ForOtherCfd1="" - - -## 东东健康社区: -MyHealth1='' - -ForOtherHealth1="" - - -## 京东手机狂欢城: -MyCarni1='' - -ForOtherCarni1="" - - -## 城城领现金: -MyCity1='' - -ForOtherCity1="" - - -## 摇钱树: -MyMoneyTree1='' - -ForOtherMoneyTree1="" - - -## 京喜Token(用于京喜财富岛提现等) -TokenJxnc1='' - +# Build 20210805-001 +name_js=( + jd_fruit + jd_pet + jd_plantBean + jd_dreamFactory + jd_jdfactory + jd_crazy_joy + jd_jdzz + jd_jxnc + jd_bookshop + jd_cash + jd_sgmh + jd_cfd + jd_health + jd_carnivalcity + jd_city + jd_moneyTree_heip + jd_cfdtx +) +name_config=( + Fruit + Pet + Bean + DreamFactory + JdFactory + Joy + Jdzz + Jxnc + BookShop + Cash + Sgmh + Cfd + Health + Carni + City + MoneyTree + TokenJxnc +) env_name=( FRUITSHARECODES ## 1、东东农场互助码 PETSHARECODES ## 2、东东萌宠互助码 @@ -144,7 +82,7 @@ var_name=( ## 临时屏蔽某账号运行活动脚本 TempBlock_JD_COOKIE(){ source $file_env - local TempBlockCookieInterval=$(echo $TempBlockCookie | perl -pe "{s|~|-|; s|_|-|}" | sed 's/\(\d\+\)-\(\d\+\)/{\1..\2}/g') + local TempBlockCookieInterval="$(echo $TempBlockCookie | perl -pe "{s|~|-|; s|_|-|}" | sed 's/\(\d\+\)-\(\d\+\)/{\1..\2}/g')" local TempBlockCookieArray=($(eval echo $TempBlockCookieInterval)) local envs=$(eval echo "\$JD_COOKIE") local array=($(echo $envs | sed 's/&/ /g')) @@ -167,7 +105,7 @@ combine_sub() { local what_combine=$1 local combined_all="" local tmp1 tmp2 - local TempBlockCookieInterval=$(echo $TempBlockCookie | perl -pe "{s|~|-|; s|_|-|}" | sed 's/\(\d\+\)-\(\d\+\)/{\1..\2}/g') + local TempBlockCookieInterval="$(echo $TempBlockCookie | perl -pe "{s|~|-|; s|_|-|}" | sed 's/\(\d\+\)-\(\d\+\)/{\1..\2}/g')" local TempBlockCookieArray=($(eval echo $TempBlockCookieInterval)) local envs=$(eval echo "\$JD_COOKIE") local array=($(echo $envs | sed 's/&/ /g')) @@ -178,7 +116,7 @@ combine_sub() { local tmp2=${!tmp1} [[ ${tmp2} ]] && sum=$i || break done - for ((j = 1; j <= $user_sum; j++)); do + for ((j = 1; j <= $sum; j++)); do a=$temp_user_sum b=$sum if [[ $a -ne $b ]]; then @@ -203,10 +141,29 @@ combine_all() { done } +for ((i = 0; i < ${#env_name[*]}; i++)); do + export ${env_name[i]}="" +done + TempBlock_JD_COOKIE #if [[ $(ls $dir_code) ]]; then # latest_log=$(ls -r $dir_code | head -1) # . $dir_code/$latest_log - combine_all +# combine_all #fi + +for ((i = 0; i < ${#env_name[*]}; i++)); do + case $1 in + *${name_js[i]}.js | *${name_js[i]}.ts) + . $dir_log/.ShareCode/${name_config[i]}.log + result=$(combine_sub ${var_name[i]}) + if [[ $result ]]; then + export ${env_name[i]}=$result + fi + ;; + *) + export ${env_name[i]}="" + ;; + esac +done