-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·65 lines (57 loc) · 2.11 KB
/
update.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
#!/bin/bash
file_changed=false
wget -q -r -l4 -np -nH -E -A "*.html" –spider -D data.cquest.org https://data.cquest.org/ign/
> ./resources/temp.txt
for index in $(find ./ign/ -name "*.html")
do
p=$(echo $index | sed 's|index.html||') ;
path=${p:2} ;
cat $index | grep href | grep "7z\|zip\|gpkg" | grep -v torrent | sed 's| \{2,\}| |g' | sed 's|^.\{1,\}href="\([^"]\{1,\}\)"[^ ]\{1,\} \([^-]\{1,\}\)-\([^-]\{1,\}\)-\([^ ]\{1,\}\) \([^ ]\{1,\}\) \([0-9]\{1,\}\)|{"name":"\1","time":"\4-\3-\2T\5","size":\6,#|' | sed "s|#|\"path\":\"$path\"},|" | sort | uniq | grep "{" >> ./resources/temp.txt;
done
declare -A months
months=([Jan]='01' [Feb]='02' [Mar]='03' [Apr]='04' [May]='05' [Jun]='06' [Jul]='07' [Aug]='08' [Sep]='09' [Oct]='10' [Nov]='11' [Dec]='12') ;
for key in "${!months[@]}"
do
sed -i "s/-$key-/-${months[$key]}-/" ./resources/temp.txt
done
extracted=$(cat ./resources/temp.txt);
json="[${extracted::-2}]";
if jq -e . >/dev/null 2>&1 <<<"$json"
then
echo "archives = $json;" > ./resources/archives2.js
fi
if [ -f "./resources/archives2.js" ]
then
if [ -f "./resources/archives.js" ]
then
old_file=$(md5sum ./resources/archives.js | sed 's| [^ ]\{1,\}$||');
new_file=$(md5sum ./resources/archives2.js | sed 's| [^ ]\{1,\}$||');
if [ "$old_file" != "$new_file" ]
then
#echo "md5 mismatch";
old_size=$(wc -c ./resources/archives.js | sed 's| [^ ]\{1,\}$||');
new_size=$(wc -c ./resources/archives2.js | sed 's| [^ ]\{1,\}$||');
half_old_size=$(($old_size / 2));
if [ $new_size -gt $half_old_size ]
then
#echo "new file size greater than half of old file size";
rm ./resources/archives.js
mv ./resources/archives2.js ./resources/archives.js
file_changed=true
fi
fi
else
#echo "First archives.js";
mv ./resources/archives2.js ./resources/archives.js
file_changed=true
fi
fi
if [ "$file_changed" = true ]
then
git config user.name "github-actions (bot)"
git config user.email [email protected]
git add ./resources/archives.js
git commit -m "Generated new archives.js"
git push
./ign.sh
fi