-
Notifications
You must be signed in to change notification settings - Fork 355
/
ins_pkg.sh
147 lines (138 loc) · 4.69 KB
/
ins_pkg.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
#!/usr/bin/env sh
# shellcheck disable=SC2005,2188
<<'COMMENT'
cron: 16 */2 * * *
new Env('签到依赖');
COMMENT
. utils_env.sh
get_some_path
alpine_pkgs="bash curl gcc git jq libffi-dev make musl-dev openssl-dev perl perl-app-cpanminus perl-dev py3-pip python3 python3-dev wget"
py_reqs="bs4 cryptography dateparser feedparser peewee pyaes pyppeteer requests rsa schedule tomli"
js_pkgs="@iarna/toml axios cron-parser crypto-js got"
pl_mods="File::Slurp JSON5 TOML::Dumper"
install() {
count=0
flag=$1
while true; do
echo ".......... $2 begin .........."
result=$3
if [ "$result" -gt 0 ]; then
flag=0
else
flag=1
fi
if [ $flag -eq "$1" ]; then
echo "---------- $2 succeed ----------"
break
else
count=$((count + 1))
if [ $count -eq 6 ]; then
echo "!! 自动安装失败,请尝试进入容器后执行 $2 !!"
break
fi
echo ".......... retry in 5 seconds .........."
sleep 5
fi
done
}
install_alpine_pkgs() {
apk update
apk_info=" $(apk info) "
for i in $alpine_pkgs; do
if expr "$apk_info" : ".*\s${i}\s.*" >/dev/null; then
echo "$i 已安装"
else
install 0 "apk add $i" "$(apk add --no-cache "$i" | grep -c 'OK')"
fi
done
}
install_py_reqs() {
pip3 install --upgrade pip
pip3_freeze="$(pip3 freeze)"
for i in $py_reqs; do
if expr "$pip3_freeze" : ".*${i}" >/dev/null; then
echo "$i 已安装"
else
install 0 "pip3 install $i" "$(pip3 install "$i" | grep -c 'Successfully')"
fi
done
}
install_js_pkgs_initial() {
if [ -d "${SCR_PATH}/OreosLab_checkinpanel_master" ]; then
cd "${SCR_PATH}/OreosLab_checkinpanel_master" &&
cp "${REPO_PATH}/OreosLab_checkinpanel_master/package.json" "${SCR_PATH}/OreosLab_checkinpanel_master/package.json"
elif [ -d "/ql/scripts" ] && [ ! -f "/ql/scripts/package.bak.json" ]; then
cd /ql/scripts || exit
rm -rf node_modules
rm -rf .pnpm-store
mv package-lock.json package-lock.bak.json
mv package.json package.bak.json
mv pnpm-lock.yaml pnpm-lock.bak.yaml
install 1 "npm install -g package-merge" "$(echo "$(npm install -g package-merge && npm ls -g package-merge)" | grep -cE '(empty)|ERR')" &&
export NODE_PATH="/usr/local/lib/node_modules" &&
node -e \
"const merge = require('package-merge');
const fs = require('fs');
const dst = fs.readFileSync('/ql/repo/OreosLab_checkinpanel_master/package.json');
const src = fs.readFileSync('/ql/scripts/package.bak.json');
fs.writeFile('/ql/scripts/package.json', merge(dst, src), function (err) {
if (err) {
console.log(err);
}
console.log('package.json merged successfully!');
});"
fi
npm install
}
install_js_pkgs_each() {
is_empty=$(npm ls "$1" | grep empty)
has_err=$(npm ls "$1" | grep ERR)
if [ "$is_empty" = "" ] && [ "$has_err" = "" ]; then
echo "$1 已正确安装"
elif [ "$has_err" != "" ]; then
uninstall_js_pkgs "$1"
else
install 1 "npm install $1" "$(echo "$(npm install --force "$1" && npm ls --force "$1")" | grep -cE '(empty)|ERR')"
fi
}
uninstall_js_pkgs() {
npm uninstall "$1"
rm -rf "$(pwd)"/node_modules/"$1"
rm -rf /usr/local/lib/node_modules/lodash/*
npm cache clear --force
}
install_js_pkgs_all() {
install_js_pkgs_initial
for i in $js_pkgs; do
install_js_pkgs_each "$i"
done
npm ls --depth 0
}
install_pl_mods() {
if command -v cpm >/dev/null 2>&1; then
echo "App::cpm 已安装"
else
install 1 "cpanm -fn App::cpm" "$(cpanm -fn App::cpm | grep -c "FAIL")"
if ! command -v cpm >/dev/null 2>&1; then
if [ -f ./cpm ]; then
chmod +x cpm && ./cpm --version
else
cp -f /ql/repo/OreosLab_checkinpanel_master/cpm ./ && chmod +x cpm && ./cpm --version
if [ ! -f ./cpm ]; then
curl -fsSL https://cdn.jsdelivr.net/gh/Oreomeow/checkinpanel/cpm >cpm && chmod +x cpm && ./cpm --version
fi
fi
fi
fi
for i in $pl_mods; do
if [ -f "$(perldoc -l "$i")" ]; then
echo "$i 已安装"
else
install 1 "cpm install -g $i" "$(cpm install -g "$i" | grep -c "FAIL")"
fi
done
}
install_alpine_pkgs
install_py_reqs
install_js_pkgs_all
install_pl_mods