forked from power721/alist-tvbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·198 lines (171 loc) · 7.56 KB
/
init.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
#!/bin/sh
update_movie() {
LOCAL="0.0"
if [ -f /data/atv/base_version ]; then
LOCAL=$(head -n 1 </data/atv/base_version)
fi
REMOTE=$(head -n 1 </base_version)
echo "movie base version: $LOCAL $REMOTE"
if [ "$LOCAL" != "$REMOTE" ]; then
echo "upgrade movie data"
unzip -q -o /data.zip -d /data/atv/
cp /base_version /tmp/
rm -f /data/atv/sql/*.sql
fi
}
restore_database() {
if [ -f "/data/database.zip" ]; then
echo "=== restore database ==="
rm -f /data/atv.mv.db /data/atv.trace.db
java -cp /opt/atv/BOOT-INF/lib/h2-*.jar org.h2.tools.RunScript -url jdbc:h2:/data/atv -user sa -password password -script /data/database.zip -options compression zip
rm -f /data/database.zip /data/atv/base_version /data/atv/movie_version
fi
}
init() {
mkdir -p /var/lib/pxg /www/cgi-bin /index /data/atv /data/index /data/backup
if [ -d /index ]; then
rm -rf /index
fi
[ -h /data/log/log ] && unlink /data/log/log
ln -sf /data/index /
ln -sf /data/config .
cd /var/lib/pxg
unzip -q /var/lib/data.zip
mv data.db /opt/alist/data/data.db
sed -i 's!/"$after"!"$after"!' search
mv search /www/cgi-bin/search
mv sou /www/cgi-bin/sou
mv whatsnew /www/cgi-bin/whatsnew
mv header.html /www/cgi-bin/header.html
sed -i "s/127.0.0.1/0.0.0.0/" /opt/alist/data/config.json
sed '/location \/dav/i\ location ~* alist {\n deny all;\n }\n' nginx.conf >/etc/nginx/http.d/default.conf
mv mobi.tgz /www/mobi.tgz
cd /www/
tar zxf mobi.tgz
rm mobi.tgz
sqlite3 /opt/alist/data/data.db ".read /update.sql"
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppelWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" -T 30 -t 2 http://docker.xiaoya.pro/update/tvbox.zip -O tvbox.zip || \
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppelWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" --header="Host:docker.xiaoya.pro" -T 30 -t 2 http://104.21.17.247/update/tvbox.zip -O tvbox.zip || \
wget -T 30 -t 2 https://github.com/xiaoyaliu00/data/raw/main/tvbox.zip -O tvbox.zip || \
wget -T 30 -t 2 http://data.har01d.cn/tvbox.zip -O tvbox.zip || \
cp /tvbox.zip ./
unzip -q -o tvbox.zip
if [ -f /data/my.json ]; then
rm /www/tvbox/my.json
ln -s /data/my.json /www/tvbox/my.json
fi
if [ -f /data/iptv.m3u ]; then
ln -s /data/iptv.m3u /www/tvbox/iptv.m3u
fi
rm -f tvbox.zip index.zip index.txt version.txt update.zip
update_movie
}
echo "Install mode: $INSTALL"
cat data/app_version
version=$(head -n1 /docker.version)
echo "xiaoya version: $version"
uname -mor
date
restore_database
if [ -f /opt/alist/data/data.db ]; then
update_movie
echo "已经初始化成功"
else
init
fi
if [ ! -d /www/cat ]; then
mkdir /www/cat
unzip -q -o /cat.zip -d /www/cat
fi
[ -d /data/cat ] && cp -r /data/cat/* /www/cat/
if [ ! -d /www/pg ]; then
mkdir /www/pg
unzip -q -o /pg.zip -d /www/pg
fi
[ -d /data/pg ] && cp -r /data/pg/* /www/pg/
cd /tmp/
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppelWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" -T 10 -t 2 -q http://docker.xiaoya.pro/version.txt -O version.txt || \
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppelWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" --header="Host:docker.xiaoya.pro" -T 10 -t 2 -q http://104.21.17.247/version.txt -O version.txt || \
wget -T 10 -t 2 http://data.har01d.cn/version.txt -O version.txt
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppelWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" -T 30 -t 2 http://docker.xiaoya.pro/update/update.zip -O update.zip || \
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppelWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" --header="Host:docker.xiaoya.pro" -T 30 -t 2 http://104.21.17.247/update/update.zip -O update.zip || \
wget -T 30 -t 2 https://github.com/xiaoyaliu00/data/raw/main/update.zip -O update.zip || \
wget -T 30 -t 2 http://data.har01d.cn/update.zip -O update.zip
if [ ! -f update.zip ]; then
echo "Failed to download update database file, the database upgrade process has aborted"
else
unzip -o -q -P abcd update.zip
entries=$(grep -c 'INSERT INTO x_storages' update.sql)
echo "$(date) total $entries records"
if [ -f /opt/alist/data/data.db-shm ]; then
rm /opt/alist/data/data.db-shm
fi
if [ -f /opt/alist/data/data.db-wal ]; then
rm /opt/alist/data/data.db-wal
fi
sed -i 's/v3.9.2/v3.25.1/' update.sql
sqlite3 /opt/alist/data/data.db <<EOF
drop table x_storages;
drop table x_meta;
drop table x_setting_items;
.read update.sql
EOF
echo "$(date) update database successfully"
opentoken_url=$(cat opentoken_url.txt)
sed -i "s#https://api.nn.ci/alist/ali_open/token#$opentoken_url#" /opt/alist/data/config.json
rm -f update.zip update.sql opentoken_url.txt
fi
if [ ! -f version.txt ]; then
echo "Failed to download version.txt file, the index file upgrade process has aborted"
else
remote=$(head -n1 version.txt)
if [ ! -f /data/index/version.txt ]; then
echo 0.0.0 >/data/index/version.txt
fi
local=$(head -n1 /data/index/version.txt)
echo "index version: $local $remote"
latest=$(printf "$remote\n$local\n" | sort -r | head -n1)
if [ "$remote" = "$local" ]; then
echo "$(date) current index file version is updated, no need to upgrade"
elif [ "$remote" = "$latest" ]; then
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppelWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" -T 30 -t 2 http://docker.xiaoya.pro/update/index.zip -O index.zip || \
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppelWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" --header="Host:docker.xiaoya.pro" -T 40 -t 2 http://104.21.17.247/update/index.zip -O index.zip || \
wget -T 40 -t 2 http://data.har01d.cn/index.zip -O index.zip
if [ ! -f index.zip ]; then
echo "Failed to download index compressed file, the index file upgrade process has aborted"
else
unzip -o -q -P abcd index.zip
cat index.video.txt index.book.txt index.music.txt index.non.video.txt >/data/index/index.txt
mv index*.txt /data/index/
echo "$(date) update index successfully, your new version is $remote"
echo "$remote" >/data/index/version.txt
fi
else
echo "$(date) your current version is updated, no need to downgrade"
echo "$remote" >/data/index/version.txt
fi
rm -f index.* update.* version.txt
fi
LOCAL="0.0"
if [ -f /data/index/share_version ]; then
LOCAL=$(head -n 1 </data/index/share_version)
fi
unzip -q -o /index.share.zip -d /tmp
REMOTE=$(head -n 1 </tmp/share_version)
echo "share index version: $LOCAL $REMOTE"
if [ "$LOCAL" != "$REMOTE" ]; then
echo "upgrade share index"
mv /tmp/index.share.txt /data/index/index.share.txt
mv /tmp/share_version /data/index/share_version
grep -v "/🈴我的阿里分享/" /data/index/index.video.txt >/data/index/index.video.txt.1
grep -v "/🈴我的阿里分享/" /data/index/index.txt >/data/index/index.txt.1
mv /data/index/index.video.txt.1 /data/index/index.video.txt
mv /data/index/index.txt.1 /data/index/index.txt
cat /data/index/index.share.txt >> /data/index/index.video.txt
cat /data/index/index.share.txt >> /data/index/index.txt
fi
rm -f /tmp/index.share.txt
app_ver=$(head -n1 /opt/atv/data/app_version)
sqlite3 /opt/alist/data/data.db <<EOF
INSERT INTO x_storages VALUES(20000,'/©️ $version-$app_ver',0,'Alias',30,'work','{"paths":"/每日更新"}','','2022-11-12 13:05:12+00:00',0,'','','',0,'302_redirect','');
EOF