-
Notifications
You must be signed in to change notification settings - Fork 15
/
asf
405 lines (379 loc) · 12.6 KB
/
asf
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/bin/bash
#!/usr/bin/env bash
#Author:zsnmwy
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/ArchiSteamFarm:/opt/Manage_ArchiSteamFarm:/root/.nvm/versions/node/v8.11.1/bin
export PATH
DIR_PATH="/opt/ArchiSteamFarm"
ARCHISTEAMFARM_FILES_DIR="/opt/ArchiSteamFarm"
language=$(cat /opt/.env_language)
Judge_Echo_Information() {
if [ $language -eq 1 ]; then
echo -e "$1"
else
echo -e "$2"
fi
}
judge() {
if [[ $? -eq 0 ]]; then
echo -e "${OK} ${GreenBG} $1 完成 ${Font}"
else
echo -e "${Error} ${RedBG} $1 失败${Font}"
exit 1
fi
}
judge_asf() {
asf_id=$(pm2 ls | grep asf)
if [[ -n ${asf_id} ]]; then
return 0
else
return 1
fi
}
start() {
judge_asf
if [[ $? -eq 0 ]]; then
echo "asf 已经存在了!! 本次操作跳过~~"
exit 1
fi
dotnet ${DIR_PATH}/ArchiSteamFarm.dll
}
screen_start() {
judge_asf
if [[ $? -eq 0 ]]; then
echo "asf 已经存在了!! 本次操作跳过~~"
exit 1
fi
screen dotnet /opt/ArchiSteamFarm/ArchiSteamFarm.dll
}
start_bg() {
judge_asf
if [[ $? -eq 0 ]]; then
echo "asf 已经存在了!! 本次操作跳过~~"
exit 1
fi
cd "${DIR_PATH}"
pm2 start "dotnet ArchiSteamFarm.dll" -n asf
judge "启动方式: dotnet ${DIR_PATH}/ArchiSteamFarm.dll"
pm2 log asf
}
status() {
IPC_status=$(cat ${DIR_PATH}/config/ASF.json | grep -Po '"IPC": \K.*?(?=,)')
IPC_Password=$(cat ${DIR_PATH}/config/ASF.json | grep -Po '"IPCPassword": \K.*?(?=,)' | cut -d '"' -f2)
IPC_Port=$(cat ${ARCHISTEAMFARM_FILES_DIR}/config/ASF.json | grep http | cut -d '"' -f2 | cut -d '/' -f3 | cut -d ':' -f2)
if [[ ${IPC_status} == "true" ]]; then
echo -e "IPC 已经开启 \\n密码: ${IPC_Password} \\n端口: ${IPC_Port}"
else
echo "IPC 未开启"
fi
judge_asf
if [[ $? -eq 1 ]]; then
echo "[此处不检测 screen任务]asf 还没有启动哟"
exit 1
fi
pm2 ls
judge "列出PM2任务"
}
remove() {
judge_asf
if [[ $? -eq 1 ]]; then
echo "asf 还没有启动哟 本次操作跳过~~"
exit 1
fi
pm2 delete asf
judge "删除asf"
}
log() {
judge_asf
if [[ $? -eq 1 ]]; then
echo "asf 还没有启动哟 本次操作跳过~~"
exit 1
fi
pm2 log asf
judge "查看asf日志"
}
Choose_ipc_true_or_flase() {
Judge_Echo_Information "是否开启IPC?" "Use the IPC ?"
echo -e "\\n"
Judge_Echo_Information "1.开启 \n2.不开启" "1 Yes. Please trun on it. \n2 No. I don't want to use it."
read -r -p "请输入数字 | Please fill in a number." IPC_Config
case $IPC_Config in
1)
IPC_Config="true"
Before_Ipc_line_number=$(cat ${ARCHISTEAMFARM_FILES_DIR}/config/ASF.json -n | grep "\"IPC\":" | awk '{print $1}')
Now_Icp_string="\"IPC\": ${IPC_Config},"
sed -i ''"$(echo "${Before_Ipc_line_number}")"'c '"$(echo "${Now_Icp_string}")"'' ${DIR_PATH}/config/ASF.json
judge "Change IPC"
;;
2) IPC_Config="false"
Before_Ipc_line_number=$(cat ${ARCHISTEAMFARM_FILES_DIR}/config/ASF.json -n | grep "\"IPC\":" | awk '{print $1}')
Now_Icp_string="\"IPC\": ${IPC_Config},"
sed -i ''"$(echo "${Before_Ipc_line_number}")"'c '"$(echo "${Now_Icp_string}")"'' ${DIR_PATH}/config/ASF.json
judge "Change IPC"
;;
*) Choose_ipc_true_or_flase
;;
esac
}
Change_IPC_Password() {
while true; do
#clear
echo -e "\n"
read -r -s -p "输入你的IPC密码 (越复杂越好):" ipc_password_first
echo -e "\n"
echo -e "\n"
read -r -s -p "再次输入你的IPC密码 (越复杂越好):" ipc_password_second
if [[ "${ipc_password_second}" != "${IPC_Port}" ]]; then
if [[ ${ipc_password_first} == ${ipc_password_second} ]]; then
Before_Ipc_Password_line_number=$(cat ${ARCHISTEAMFARM_FILES_DIR}/config/ASF.json -n | grep "IPCPassword" | awk '{print $1}')
Now_Icp_Password_string="\"IPCPassword\": \"${ipc_password_second}\","
sed -i ''"$(echo "${Before_Ipc_Password_line_number}")"'c '"$(echo "${Now_Icp_Password_string}")"'' ${DIR_PATH}/config/ASF.json
break
else
echo -e "${Error} ${RedBG} 两次输入的密码不正确 ! 重新输入 ${Font}"
sleep 2
fi
else
echo -e "${Error} ${RedBG} IPC密码和IPC端口不能够相同 ${Font}"
sleep 2
fi
done
}
Change_IPC_Port() {
while true; do
echo -e "请输入IPC监听端口 [1-65535]"
stty erase '^H' && read -r -p "(默认端口:1242 ):" ipc_port
[[ -z "${ipc_port}" ]] && ipc_port="1242"
expr ${ipc_port} + 0 &>/dev/null
if [[ $? -eq 0 ]]; then
if [[ ${ipc_port} -ge 1 ]] && [[ ${ipc_port} -le 65535 ]]; then
echo && echo "========================"
echo -e " 端口 : ${Red_background_prefix} ${ipc_port} ${Font_color_suffix}"
echo "========================" && echo
port_exist_check ${ipc_port}
echo -e "${Info} ${GreenBG} 尝试修改IPC端口 ${Font}"
Before_Ipc_Port_line_number=$(cat ${ARCHISTEAMFARM_FILES_DIR}/config/ASF.json -n | grep "http://" | awk '{print $1}')
Ipc_ip=$(cat ${ARCHISTEAMFARM_FILES_DIR}/config/ASF.json | grep -Po '"http://\K.*?(?=:)')
Now_Ipc_Port_string="\"http://${Ipc_ip}:${ipc_port}/\""
sed -i ''"$(echo "${Before_Ipc_Port_line_number}")"'c '"$(echo "${Now_Ipc_Port_string}")"'' ${DIR_PATH}/config/ASF.json
IPC_Port=$(cat ${ARCHISTEAMFARM_FILES_DIR}/config/ASF.json | grep http | cut -d '"' -f2 | cut -d '/' -f3 | cut -d ':' -f2)
if [[ "${IPC_Port}" == "${ipc_port}" ]]; then
echo -e "${OK} ${GreenBG} 修改IPC端口成功 ${Font}"
sleep 3
exit 0
else
echo -e "${Error} ${RedBG} 修改IPC端口失败 换个端口再试试?${Font}"
sleep 3
exit 1
fi
else
echo "输入错误, 请输入正确的端口。"
sleep 2
fi
else
echo "输入错误, 请输入正确的端口。"
sleep 2
fi
done
}
port_exist_check() {
if [[ 0 -eq $(lsof -i:"$1" | wc -l) ]]; then
echo -e "${OK} ${GreenBG} $1 端口未被占用 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} 检测到 $1 端口被占用,以下为 $1 端口占用信息 ${Font}"
lsof -i:"$1"
echo -e "${OK} ${GreenBG} 5s 后将尝试自动 kill 占用进程 ${Font}"
sleep 5
lsof -i:"$1" | awk '{print $2}' | grep -v "PID" | xargs kill -9
echo -e "${OK} ${GreenBG} kill 完成 ${Font}"
sleep 1
fi
}
User_Manage_Panel() {
if [[ -e ${ARCHISTEAMFARM_FILES_DIR} ]]; then
cd ${ARCHISTEAMFARM_FILES_DIR}/config
ls -1 | grep -Po '.*\.json' | grep -v minimal | grep -v example | grep -v ASF | awk -F '.' 'BEGIN{print "\n\n""STEAM ACCOUNT""\n""------------------""\n" }{print NR,"\t",$1}END{print "------------------""\n\n"}'
echo -e "
因为已经采用了AES加密,这里没有密码修改功能
密码错了,重启ASF再输就行了
这里也没有账号配置的修改,直接开IPC功能,网页改更快啦~~~
1.增加Steam账号
2.删除Steam账号
3.退出
"
echo -e "${Info} ${RedBG} 请问你想?(输入数字) ${Font}" && read aNumber
case $aNumber in
1)
User_Manage_Panel_Add_Steam_Account
;;
2)
User_Manage_Panel_Delete_Steam_Account
;;
3)
exit 0
;;
*)
User_Manage_Panel
;;
esac
else
echo -e "${Info} ${RedBG} 没有安装ArchiSteamFarm 请先安装 ${Font}"
fi
}
# Get steam account name
Steam_information_account_Get() {
while true; do
#clear
echo -e "\n"
read -r -p "输入你的steam账号名:" Steam_account_first
echo -e "\n"
read -r -p "再次输入你的steam账号名:" Steam_account_second
if [[ -n ${Steam_account_second} ]]; then
if [[ ${Steam_account_first} == "${Steam_account_second}" ]]; then
break
else
echo -e "${Error} ${RedBG} 两次输入的账号名称不正确 ! 请重新输入 ${Font}"
sleep 2
fi
else
echo -e "${Error} ${RedBG} 请输入你的steam账号 ${Font}"
sleep 2
fi
done
}
User_Manage_Panel_Add_Steam_Account() {
Steam_information_account_Get
while true; do
cd ${ARCHISTEAMFARM_FILES_DIR}/config
check_account=$(cd ${ARCHISTEAMFARM_FILES_DIR}/config && ls | grep ${Steam_account_second})
if [[ -z ${check_account} ]]; then
Bot_Add
check_account=$(cd ${ARCHISTEAMFARM_FILES_DIR}/config && ls | grep ${Steam_account_second})
if [[ ! -z ${check_account} ]]; then
echo -e "${Info} ${GreenBG} 成功添加账号配置文件 ${check_account} ${Font}"
ls -1 | grep -Po '.*\.json' | grep -v minimal | grep -v example | grep -v ASF | awk -F '.' 'BEGIN{print "\n\n""STEAM ACCOUNT\n------------------\n" }{print NR,"\t",$1}END{print "------------------""\n\n"}'
sleep 3
exit 0
else
echo -e "${Error} ${RedBG} 添加失败 请检查${ARCHISTEAMFARM_FILES_DIR}/config文件夹 ${Font}"
sleep 3
exit 1
fi
else
echo -e "${Error} ${RedBG} 请检查现有账号与新建的账号是否重复${Font}"
ls -1 | grep -Po '.*\.json' | grep -v minimal | grep -v example | grep -v ASF | awk -F '.' 'BEGIN{print "\n\n""STEAM ACCOUNT\n------------------\n" }{print NR,"\t",$1}END{print "------------------""\n\n"}'
sleep 4
fi
done
}
# 添加一个机器人/BOT 配置文件名为账号名
Bot_Add() {
echo -e "${Info} ${GreenBG} 准备添加BOT ${Font}"
touch ${ARCHISTEAMFARM_FILES_DIR}/config/${Steam_account_second}.json
cat >${ARCHISTEAMFARM_FILES_DIR}/config/${Steam_account_second}.json <<EOF
{
"PasswordFormat": 1,
"SteamLogin": "Steam_account_account_second",
"SteamPassword": "",
"Enabled": true
}
EOF
sed -i 's/Steam_account_account_second/'"$(echo "${Steam_account_second}")"'/' "${ARCHISTEAMFARM_FILES_DIR}/config/${Steam_account_second}.json"
judge "ADD BOT"
}
User_Manage_Panel_Delete_Steam_Account() {
cd ${ARCHISTEAMFARM_FILES_DIR}/config
ls -1 | grep -Po '.*\.json' | grep -v minimal | grep -v example | grep -v ASF | awk -F '.' 'BEGIN{print "\n\n""STEAM ACCOUNT\n------------------" }{print NR,"\t",$1}END{print "------------------""\n\n"}'
echo -e "
${Info} ${RedBG} 你现在正进行着高风险操作---删除Steam账号数据${Font}
${Info} ${RedBG} 你现在正进行着高风险操作---删除Steam账号数据${Font}
${Info} ${RedBG} 你现在正进行着高风险操作---删除Steam账号数据${Font}
${Info} ${RedBG} 此操作会把相关账号的数据从ASF的config目录全部删除!!!!${Font}
${Info} ${RedBG} 后果自负 作者免责${Font}
"
echo -e "${Info} ${GreenBG}是否继续删除Steam账号数据?${Font}"
stty erase '^H' && read -p "(默认: N):" account_delete_yn
[[ -z "${account_delete_yn}" ]] && account_delete_yn="n"
if [[ "${account_delete_yn}" == [Yy] ]]; then
while true; do
cd ${ARCHISTEAMFARM_FILES_DIR}/config
ls -1 | grep -Po '.*\.json' | grep -v minimal | grep -v example | grep -v ASF | awk -F '.' 'BEGIN{print "\n\n""STEAM ACCOUNT\n------------------" }{print NR,"\t",$1}END{print "------------------""\n\n"}'
echo -e "${Info} ${GreenBG}输入你想要删除的Steam账号名${Font}" && read account_delete
echo -e "${Info} ${GreenBG}再次输入你想要删除的Steam账号名${Font}" && read account_delete_second
if [[ ${account_delete} == ${account_delete_second} ]]; then
judge_asf
if [[ $? -eq 0 ]]; then
pm2 delete asf
fi
cd ${ARCHISTEAMFARM_FILES_DIR}/config
rm ${account_delete_second}.*
local check_account=$(cd ${ARCHISTEAMFARM_FILES_DIR}/config && ls | grep ${account_delete_second})
if [[ -z ${check_account} ]]; then
echo -e "${OK} ${GreenBG} 删除账号${account_delete_second} 成功${Font}"
sleep 4
exit 0
else
echo -e "${Error} ${RedBG} 删除账号${account_delete_second} 失败${Font}"
sleep 4
exit 1
fi
else
echo -e "${Error} ${RedBG} 两次输入Steam账号名不同 请再次尝试输入${Font}"
sleep 2
fi
done
else
echo -e "${Info} ${GreenBG}跳过 不删除账号${Font}"
fi
}
case "$1" in
-s | --start | start)
start
;;
-scr | --screen | screen)
screen_start
;;
-l | --log | log)
log
;;
-r | --remove | remove)
remove
;;
-st | --status | status)
status
;;
-c | change_ipc_password)
Change_IPC_Password
;;
-C | change_ipc_port)
Change_IPC_Port
;;
-ipc | ipc)
Choose_ipc_true_or_flase
;;
-bg | --background | background)
start_bg
;;
-acc | --account | account)
User_Manage_Panel
;;
*) echo "
使用方法
asf
==========asf启动方式=========================
-s | --start 正常启动,不后台
-scr | --screen 在screen内启动asf,不会检测任务是否存在
==========PM2管理asf快捷选项===================
-bg | --background 把asf丢到PM2里面后台,可自动重启(推荐)
-l | --log 列出日志
-r | --remove 从PM2中移除asf任务
-st | --status 查看当前asf的状态
==========IPC相关快速设置项====================
-ipc | 是否启用IPC
-c | 更改IPC密码
-C | 更改IPC端口号
==========steam 账号管理====================
-acc | --account steam 账号管理
"
;;
esac