This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sh
executable file
·109 lines (96 loc) · 2.36 KB
/
generate.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
#!/bin/bash
# written by X. Jason Lyu
cd `dirname $0`
NEW_VER=""
CUR_VER=""
TMP_DIR="/tmp/dlc"
DLC_DIR="data"
VER_FILE="version"
DATA_DIR=""
REPO_URL="https://github.com/xjasonlyu/dlc-surge.git"
COMMIT=""
PYTHON3=`which python3`
getVersion()
{
TAG_URL="https://api.github.com/repos/v2ray/domain-list-community/releases/latest"
NEW_VER=`curl -s ${TAG_URL} --connect-timeout 10| grep 'tag_name' | cut -d\" -f4`
if [[ -f ${VER_FILE} ]]; then
CUR_VER=`cat ${VER_FILE}`
fi
}
downloadDlc()
{
# delete old files
if [[ ! -d ${TMP_DIR} ]]; then
mkdir -p ${TMP_DIR}
else
rm -rf ${TMP_DIR}/*
fi
# downloading...
DATA_DIR="${TMP_DIR}/domain-list-community-${NEW_VER}/data"
curl -s -L -H "Cache-Control: no-cache" -o ${TMP_DIR}/${NEW_VER}.zip "https://github.com/v2ray/domain-list-community/archive/${NEW_VER}.zip"
unzip -q ${TMP_DIR}/${NEW_VER}.zip -d ${TMP_DIR}
if [[ ! -d ${DATA_DIR} ]]; then
echo "data folder missing"
exit 1
fi
}
generateData()
{
# Create data folder
mkdir -p ${DLC_DIR}
# generate domain-list to files
for i in `ls ${DATA_DIR}`; do
${PYTHON3} ./convert.py ${DATA_DIR}/${i} | tee ${DLC_DIR}/${i} > /dev/null
done
# alias geolocatin-!cn -> !cn
[[ -f "${DLC_DIR}/geolocation-!cn" ]] && echo "copy geolocation-!cn to !cn" && cat "${DLC_DIR}/geolocation-!cn" | tee "${DLC_DIR}/!cn" > /dev/null
}
gitUpload()
{
if [[ ! -d .git ]]; then
git init
fi
# Refresh local copy
git pull origin master
# Add .gitignore
if [[ -f .gitignore ]]; then
git add .gitignore
fi
# add files to git
for i in `ls .`; do
git add ${i}
done
# commit
if [[ ! ${COMMIT} ]]; then
git commit -m "v${NEW_VER}"
else
git commit -m "${COMMIT}"
fi
# push
git remote add origin ${REPO_URL}
git remote -v
git push -u origin master
# complete
echo "Done!"
}
main()
{
getVersion
if [[ ${CUR_VER} == ${NEW_VER} ]] && [[ -d ${DLC_DIR} ]]; then
echo "v${CUR_VER} is the latest version"
else
echo "found new version v${NEW_VER}"
#
downloadDlc
#
generateData
# remove tmp files
rm -rf ${TMP_DIR}
fi
echo "${NEW_VER}" | tee ${VER_FILE} > /dev/null
# upload to Github
gitUpload
}
COMMIT=${1}
main