This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
forked from qiandaoniaoren/jds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jd.sh
282 lines (259 loc) · 9.33 KB
/
jd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env bash
## Author: Evine Deng
## Source: https://github.com/EvineDeng/jd-base
## Modified: 2021-01-25
## Version: v3.7.1
## 路径
ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)}
[ ${JD_DIR} ] && HelpJd=jd || HelpJd=jd.sh
ScriptsDir=${ShellDir}/scripts
ConfigDir=${ShellDir}/config
FileConf=${ConfigDir}/config.sh
FileConfSample=${ShellDir}/sample/config.sh.sample
LogDir=${ShellDir}/log
ListScripts=($(cd ${ScriptsDir}; ls *.js | grep -E "j[drx]_"))
ListCron=${ConfigDir}/crontab.list
## 导入config.sh
function Import_Conf {
if [ -f ${FileConf} ]
then
. ${FileConf}
if [ -z "${Cookie1}" ]; then
echo -e "请先在config.sh中配置好Cookie...\n"
exit 1
fi
else
echo -e "配置文件 ${FileConf} 不存在,请先按教程配置好该文件...\n"
exit 1
fi
}
## 更新crontab
function Detect_Cron {
if [[ $(cat ${ListCron}) != $(crontab -l) ]]; then
crontab ${ListCron}
fi
}
## 用户数量UserSum
function Count_UserSum {
i=1
while [ $i -le 1000 ]; do
Tmp=Cookie$i
CookieTmp=${!Tmp}
[[ ${CookieTmp} ]] && UserSum=$i || break
let i++
done
}
## 组合Cookie和互助码子程序
function Combin_Sub {
CombinAll=""
i=1
while [ $i -le ${UserSum} ]
do
Tmp1=$1$i
Tmp2=${!Tmp1}
case $# in
1)
CombinAll="${CombinAll}&${Tmp2}"
;;
2)
CombinAll="${CombinAll}&${Tmp2}@$2"
;;
3)
if [ $(($i % 2)) -eq 1 ]; then
CombinAll="${CombinAll}&${Tmp2}@$2"
else
CombinAll="${CombinAll}&${Tmp2}@$3"
fi
;;
4)
case $(($i % 3)) in
1)
CombinAll="${CombinAll}&${Tmp2}@$2"
;;
2)
CombinAll="${CombinAll}&${Tmp2}@$3"
;;
0)
CombinAll="${CombinAll}&${Tmp2}@$4"
;;
esac
;;
esac
let i++
done
echo ${CombinAll} | perl -pe "{s|^&||; s|^@+||; s|&@|&|g; s|@+|@|g}"
}
## 组合Cookie、Token与互助码,用户自己的放在前面,我的放在后面
function Combin_All {
export JD_COOKIE=$(Combin_Sub Cookie)
export FRUITSHARECODES=$(Combin_Sub ForOtherFruit "db34eebcf9424eeeacd6afbfd07e27fc@238d48959bcb48328fd16121124fdb6a@a1284041121d46a894ddfeac7d8d8b6f@2d8bbe5a2fbf4843bc3598bbc4ad40e9@6d23ff5a3cb446e69b0fee7fec89baba@835957daa70342efa659c8d1138f93c6")
export PETSHARECODES=$(Combin_Sub ForOtherPet "MTAxODExNDYxMTEwMDAwMDAwNDAwODk4MzU=@MTE1NDQ5OTUwMDAwMDAwNDAyNzM4NDE=@MTAxODExNDYxMTAwMDAwMDAwNDA0MTY3NDc=@MTE1NDQ5OTUwMDAwMDAwNDIwNTU0MTE=@MTAxODc2NTEzNTAwMDAwMDAzMzc0OTcyOQ==")
export PLANT_BEAN_SHARECODES=$(Combin_Sub ForOtherBean "mxevgfcbhsvhipacfx67vvkbpxtfpmrljik7qsq@4npkonnsy7xi2jm3w3jbodaxuy3mvgrjkqumgja@npm7g47yodunjpamcthe4krkce@wsr6thb5bd25lhf6jmueldfii67p6ibkinrjwya@ckfols2jxbzmijih3cl57kzhqm@olmijoxgmjutys73edbyorqqiddzghknod2felq")
export DREAM_FACTORY_SHARE_CODES=$(Combin_Sub ForOtherDreamFactory "rV4tmxib8_smTh3fiLaS3w==@97mk3cZQ8f1yN7qOLEKJ9w==@gmLsVlqEoT8fK0XanRaASQ==@QqKN6JCXvCamq2KdUYGQHA==@tk4wFjbA-wJTLfMpcmvoBgxCuUGT-f5lP4lVuMpYOew=@NbgCcCRNat_f-3D81Yez1A==")
export DDFACTORY_SHARECODES=$(Combin_Sub ForOtherJdFactory "T024vP9wQBke_FfePRv3kfAPfB0qCjVWnYaS5kRrbA@T0225KkcRxsd8gaGdUz3l6YIdQCjVWnYaS5kRrbA@T010_7gmFUBBqgCjVWnYaS5kRrbA@T0205KkcGnhHqh2NaFKy7a5vCjVWnYaS5kRrbA@T01457s6F1tG9VDVJQCjVWnYaS5kRrbA@T0225KkcRkpNp1DXKRv0nfMNdACjVWnYaS5kRrbA")
export JDZZ_SHARECODES=$(Combin_Sub ForOtherJdzz)
export JDJOY_SHARECODES=$(Combin_Sub ForOtherJoy "diW2lAk_4rbY6UxB_Yc2XKt9zd5YaBeE@vybrbGLY_uoSukCWrD40VA==@SWayOxvHxM4=@LrGGh3MT1TXnQY68Wk6Yz6t9zd5YaBeE@2tT-69nyRXqP0LCwGOJ1uRXmUODYkzx6")
export JXNC_SHARECODES=$(Combin_Sub ForOtherJxnc)
export JXNCTOKENS=$(Combin_Sub TokenJxnc)
export BOOKSHOP_SHARECODES=$(Combin_Sub ForOtherBookShop)
export JD_CASH_SHARECODES=$(Combin_Sub ForOtherCash "IRk0bOu1b_8v7G_WznQW3odl@eU9Ya-m2Ya53pDjWyCIR1w@Yl5iObLqOQ@eU9YNorsObV8uSaTsip2@el1-O6ntZvgk9A@eU9YarjmNPgm-G_VwncU1g")
export JDNIAN_SHARECODES=$(Combin_Sub ForOtherNian "cgxZLWOBJL3d4w3AFQSq6h9rtk6Qi3R5BVTg2gF-XLMauv-8aS_MyUuSMFLCLhSz@cgxZdTXtI7_e7VyYXVOq7KQqXObyd-w3Zoa8o_Hu7q_zDM09UFWC10OnfQo@cgxZdTXtIu6OuArJAQSp5uL7-6UoOATguH4X2aRNutwcdCpcOZKW7THjNVs@cgxZbiTXceSCtUKFa2quuFIvQHXbX7s@cgxZdTXtftyEtUeTQE3vlkDAYflXxLewtOcL4kLKQPR2c-L3QJXD_l8@cgxZdifLc_-F6grLDUnljAl77tpbKJap8EApEyWS")
export JDNIANPK_SHARECODES=$(Combin_Sub ForOtherNianPk)
export JDSXSY_SHARECODES=$(Combin_Sub ForOtherImmortal "46xIs4YwE5Z7HhW91yWwOC6sT0FI1H0qrlPu7bOPihdxH9PSgKcYRxkNUhj2Fm8ayxSmgszJq@43xIs4YwE5Z7DsWOzDSL-N8ET3ci7F-t4JxcFhLwnGHfHQcZB9wUFXiGzK5euWKR_uGg@27xIs4YwE5Z7FHlFPHZntHR0DPewMEaoFHkxoL0A@40xIs4YwE5Z7DsWOzDHOfhQWMDoW23ePxhcYXeJ7CCAcZB9nCIN0HecUMUo-VsF@32xIs4YwE5Z7DtqI2XGZuRfEJQddvMgfcrzcoJbkQEMjzrGbg@43xIs4YwE5Z7DsWOzDSPOBWWdaS08bvFk2G1CeR8yQWN8EcZB9wBAH3Tp7SsuXIuZPeQ")
export JDSGMH_SHARECODES=$(Combin_Sub ForOtherSgmh "T024vP9wQBke_FfePRv3kfAPfB0qCjVWmIaW5kRrbA@T0225KkcRxsd8gaGdUz3l6YIdQCjVWmIaW5kRrbA@T010_7gmFUBBqgCjVWmIaW5kRrbA@T0205KkcGnhHqh2NaFKy7a5vCjVWmIaW5kRrbA@T01457s6F1tG9VDVJQCjVWmIaW5kRrbA@T0225KkcRkpNp1DXKRv0nfMNdACjVWmIaW5kRrbA")
}
## 转换JD_BEAN_SIGN_STOP_NOTIFY或JD_BEAN_SIGN_NOTIFY_SIMPLE
function Trans_JD_BEAN_SIGN_NOTIFY {
case ${NotifyBeanSign} in
0)
export JD_BEAN_SIGN_STOP_NOTIFY="true"
;;
1)
export JD_BEAN_SIGN_NOTIFY_SIMPLE="true"
;;
esac
}
## 转换UN_SUBSCRIBES
function Trans_UN_SUBSCRIBES {
export UN_SUBSCRIBES="${goodPageSize}\n${shopPageSize}\n${jdUnsubscribeStopGoods}\n${jdUnsubscribeStopShop}"
}
## 申明全部变量
function Set_Env {
Count_UserSum
Combin_All
Trans_JD_BEAN_SIGN_NOTIFY
Trans_UN_SUBSCRIBES
}
## 随机延迟子程序
function Random_DelaySub {
CurDelay=$((${RANDOM} % ${RandomDelay} + 1))
echo -e "\n命令未添加 \"now\",随机延迟 ${CurDelay} 秒后再执行任务,如需立即终止,请按 CTRL+C...\n"
sleep ${CurDelay}
}
## 随机延迟判断
function Random_Delay {
if [ -n "${RandomDelay}" ] && [ ${RandomDelay} -gt 0 ]; then
CurMin=$(date "+%M")
if [ ${CurMin} -gt 2 ] && [ ${CurMin} -lt 30 ]; then
Random_DelaySub
elif [ ${CurMin} -gt 31 ] && [ ${CurMin} -lt 59 ]; then
Random_DelaySub
fi
fi
}
## 使用说明
function Help {
echo -e "本脚本的用法为:"
echo -e "1. bash ${HelpJd} xxx # 如果设置了随机延迟并且当时时间不在0-2、30-31、59分内,将随机延迟一定秒数"
echo -e "2. bash ${HelpJd} xxx now # 无论是否设置了随机延迟,均立即运行"
echo -e "3. bash ${HelpJd} hangup # 重启挂机程序"
echo -e "4. bash ${HelpJd} resetpwd # 重置控制面板用户名和密码"
echo -e "\n针对用法1、用法2中的\"xxx\",无需输入后缀\".js\",另外,如果前缀是\"jd_\"的话前缀也可以省略。"
echo -e "当前有以下脚本可以运行(仅列出以jd_、jr_、jx_开头的脚本):"
cd ${ScriptsDir}
for ((i=0; i<${#ListScripts[*]}; i++)); do
Name=$(grep "new Env" ${ListScripts[i]} | awk -F "'|\"" '{print $2}')
echo -e "$(($i + 1)).${Name}:${ListScripts[i]}"
done
}
## nohup
function Run_Nohup {
for js in ${HangUpJs}
do
if [[ $(ps -ef | grep "${js}" | grep -v "grep") != "" ]]; then
ps -ef | grep "${js}" | grep -v "grep" | awk '{print $2}' | xargs kill -9
fi
done
for js in ${HangUpJs}
do
[ ! -d ${LogDir}/${js} ] && mkdir -p ${LogDir}/${js}
LogTime=$(date "+%Y-%m-%d-%H-%M-%S")
LogFile="${LogDir}/${js}/${LogTime}.log"
nohup node ${js}.js > ${LogFile} &
done
}
## pm2
function Run_Pm2 {
pm2 flush
for js in ${HangUpJs}
do
pm2 restart ${js}.js || pm2 start ${js}.js
done
}
## 运行挂机脚本
function Run_HangUp {
Import_Conf && Detect_Cron && Set_Env
HangUpJs="jd_crazy_joy_coin"
cd ${ScriptsDir}
if type pm2 >/dev/null 2>&1; then
Run_Pm2 2>/dev/null
else
Run_Nohup >/dev/null 2>&1
fi
}
## 重置密码
function Reset_Pwd {
cp -f ${ShellDir}/sample/auth.json ${ConfigDir}/auth.json
echo -e "控制面板重置成功,用户名:admin,密码:adminadmin\n"
}
## 运行京东脚本
function Run_Normal {
Import_Conf && Detect_Cron && Set_Env
FileNameTmp1=$(echo $1 | perl -pe "s|\.js||")
FileNameTmp2=$(echo $1 | perl -pe "{s|jd_||; s|\.js||; s|^|jd_|}")
SeekDir="${ScriptsDir} ${ScriptsDir}/backUp ${ConfigDir}"
FileName=""
WhichDir=""
for dir in ${SeekDir}
do
if [ -f ${dir}/${FileNameTmp1}.js ]; then
FileName=${FileNameTmp1}
WhichDir=${dir}
break
elif [ -f ${dir}/${FileNameTmp2}.js ]; then
FileName=${FileNameTmp2}
WhichDir=${dir}
break
fi
done
if [ -n "${FileName}" ] && [ -n "${WhichDir}" ]
then
[ $# -eq 1 ] && Random_Delay
LogTime=$(date "+%Y-%m-%d-%H-%M-%S")
LogFile="${LogDir}/${FileName}/${LogTime}.log"
[ ! -d ${LogDir}/${FileName} ] && mkdir -p ${LogDir}/${FileName}
cd ${WhichDir}
node ${FileName}.js | tee ${LogFile}
else
echo -e "\n在${ScriptsDir}、${ScriptsDir}/backUp、${ConfigDir}三个目录下均未检测到 $1 脚本的存在,请确认...\n"
Help
fi
}
## 命令检测
case $# in
0)
echo
Help
;;
1)
if [[ $1 == hangup ]]; then
Run_HangUp
elif [[ $1 == resetpwd ]]; then
Reset_Pwd
else
Run_Normal $1
fi
;;
2)
if [[ $2 == now ]]; then
Run_Normal $1 $2
else
echo -e "\n命令输入错误...\n"
Help
fi
;;
*)
echo -e "\n命令过多...\n"
Help
;;
esac