-
Notifications
You must be signed in to change notification settings - Fork 37
/
auto.sh
178 lines (146 loc) · 3.69 KB
/
auto.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
#Creator of script: SirJosh3917
#Creator of anime-dl: Xonshiz
#May (5) 5th, 2018 - Updated June (6) 10th, 2018
#check if root
#https://askubuntu.com/questions/15853/how-can-a-script-check-if-its-being-run-as-root
is_root() {
if ! [ $(id -u) = 0 ]; then
echo "Please run this script as root."
echo "Running \'sudo\' on this script..."
SCRIPT_NAME=$(basename "$0")
CMD="sudo ./${SCRIPT_NAME}"
eval ${CMD}
exit $?
fi
}
#shamelessly stolen/modified from https://install.pi-hole.net
distro_check() {
DISTRO_OS=""
DISTRO_DEBIAN="debian"
PKG_MANAGER=""
PKG_INSTALL=""
if command -v apt-get &> /dev/null; then
DISTRO_OS=(${DISTRO_DEBIAN})
PKG_MANAGER="apt-get"
PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install"
# elif command -v rpm &> /dev/null; then
# if command -v dnf &> /dev/null; then
# PKG_MANAGER="dnf"
# elif
# PKG_MANAGER="yum"
# fi
else
echo "Your linux distro is not supporeted."
exit
fi
if [ ${DISTRO_OS} == ${DISTRO_DEBIAN} ]; then
return 0;
else
echo "Your linux distro either isn\'t supported, or somebody didn\'t finish coding the distro_check..."
exit
fi
return 0;
}
get_distro() {
DISTRO_DEBIAN_7=0
DISTRO_DEBIAN_8=1
DISTRO_DEBIAN_9=2
RETURN=-1
if [ ${DISTRO_OS} == ${DISTRO_DEBIAN} ]; then
lsb_release -a > tmp_distro
if grep "stretch" tmp_distro; then
RETURN=${DISTRO_DEBIAN_9}
elif grep "jessie" tmp_distro; then
RETURN=${DISTRO_DEBIAN_8}
elif grep "wheezy" tmp_distro; then
RETURN=${DISTRO_DEBIAN_7}
else
echo "Version of debian not supported."
RETURN=-1;
fi
fi
rm tmp_distro
return ${RETURN}
}
install_ffmpeg() {
${PKG_INSTALL} ffmpeg
}
install_mkvmerge() {
wget -q -O - https://mkvtoolnix.download/gpg-pub-moritzbunkus.txt | sudo apt-key add -
get_distro
DISTRO=$?
if [ ${DISTRO} == ${DISTRO_DEBIAN_9} ]; then
deb https://mkvtoolnix.download/debian/ stretch main
deb-src https://mkvtoolnix.download/debian/ stretch main
elif [ ${DISTRO} == ${DISTRO_DEBIAN_8} ]; then
deb https://mkvtoolnix.download/debian/ jessie main
deb-src https://mkvtoolnix.download/debian/ jessie main
elif [ ${DISTRO} == ${DISTRO_DEBIAN_7} ]; then
deb https://mkvtoolnix.download/debian/ wheezy main
deb-src https://mkvtoolnix.download/debian/ wheezy main
else echo "Distro unsupported."; return 1; fi
apt update
${PKG_INSTALL} mkvtoolnix
}
install_nodejs() {
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
${PKG_INSTALL} nodejs
}
install_animedl() {
wget https://github.com/Xonshiz/anime-dl/archive/master.tar.gz
tar -xzf master.tar.gz
mv anime-dl-master anime-dl #rename to anime-dl
rm master.tar.gz
SCRIPTS_DIR="anime-dl/anime_dl/"
#make it runnable
chmod -R +x ${SCRIPTS_DIR}
chmod -R 755 ${SCRIPTS_DIR}
}
install_curl() {
${PKG_INSTALL} curl
}
install_pip() {
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
rm get-pip.py
}
install_dependencies() {
pip install cfscrape
pip install tqdm
pip install bs4
}
ensure_animedl_installed() {
#find "Anime_DL downloads anime from" in the --help
FIND="Anime_DL downloads anime from"
SCRIPTS_DIR="anime-dl/anime_dl/"
RETURN=1
cd ${SCRIPTS_DIR}
./__main__.py --help > ../../tmp_help
cd ..; cd ..
if grep "${FIND}" tmp_help; then
echo "anime-dl installed!";
RETURN=0
else
echo "anime-dl not installed...";
RETURN=1
fi
rm tmp_help
return ${RETURN}
}
#make sure we're root so we can install packages
is_root
distro_check
if [ $? == 0 ]; then
install_ffmpeg
install_mkvmerge
install_nodejs
install_curl
install_pip
install_dependencies
install_animedl
ensure_animedl_installed
exit $?
else
echo "no"
exit
fi