-
Notifications
You must be signed in to change notification settings - Fork 59
/
install.sh
239 lines (209 loc) · 7.52 KB
/
install.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
# Friendly Telegram (telegram userbot)
# Copyright (C) 2018-2022 The Authors
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Modded by GeekTG Team
if [ ! -n "$BASH" ]; then
echo "Non-bash shell detected, fixing..."
bash -c '. <('"$(command -v curl >/dev/null && echo 'curl -Ls' || echo 'wget -qO-')"' https://github.com/GeekTG/Friendly-Telegram/raw/master/install.sh) '"$*"
exit $?
fi
# Modified version of https://stackoverflow.com/a/3330834/5509575
sp='/-\|'
spin() {
printf '\b%.1s' "$sp"
sp=${sp#?}${sp%???}
}
endspin() {
printf '\r%s\n' "$@"
}
runin() {
# Runs the arguments and spins once per line of stdout (tee'd to logfile), also piping stderr to logfile
{ "$@" 2>>../ftg-install.log || return $?; } | while read -r line; do
spin
printf "%s\n" "$line" >>../ftg-install.log
done
}
runout() {
# Runs the arguments and spins once per line of stdout (tee'd to logfile), also piping stderr to logfile
{ "$@" 2>>ftg-install.log || return $?; } | while read -r line; do
spin
printf "%s\n" "$line" >>ftg-install.log
done
}
errorin() {
endspin "$@"
cat ../ftg-install.log
}
errorout() {
endspin "$@"
cat ftg-install.log
}
# Banner generated with following command:
# pyfiglet -f smslant -w 50 friendly telegram | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/`/\\`/g' | sed 's/^/printf "%s\\n" "/m;s/$/"/m'
# Ugly, I know.
banner() {
clear
clear
printf "\n\e[7;30;41m ) \e[0m"
printf "\n\e[7;30;41m ( ( /( \e[0m"
printf "\n\e[7;30;41m )\\ ) ( ( )\\()) \e[0m"
printf "\n\e[7;30;41m(()/( )\\ )\\ |((_)\\ \e[0m"
printf "\n\e[7;30;41m /((\e[7;30;42m_\e[7;30;41m)\e[7;30;42m_\e[7;30;41m((\e[7;30;42m_\e[7;30;41m)((\e[7;30;42m_\e[7;30;41m)|\e[7;30;42m_\e[7;30;41m((\e[7;30;42m_\e[7;30;41m) \e[0m"
printf "\n\e[7;30;41m(_)\e[0m\e[7;30;42m/ __| __| __| |/ / \e[0m"
printf "\n\e[7;30;42m | (_ | _|| _| ' < \e[0m"
printf "\n\e[7;30;42m \\___|___|___|_|\\_\\ \e[0m\n\n"
}
##############################################################################
banner
printf '%s\n' "The process takes around 3-7 minutes"
printf '%s' "Installing now... "
##############################################################################
spin
touch ftg-install.log
if [ ! x"$SUDO_USER" = x"" ]; then
chown "$SUDO_USER:" ftg-install.log
fi
if [ ! x"" = x"$DYNO" ] && ! command -v python >/dev/null; then
# We are running in a heroku dyno without python, time to get ugly!
runout git clone https://github.com/heroku/heroku-buildpack-python || {
endspin "Bootstrap download failed!"
exit 1
}
rm -rf .heroku .cache .profile.d requirements.txt runtime.txt .env
mkdir .cache .env
echo "python-3.9.6" >runtime.txt
echo "pip" >requirements.txt
STACK=heroku-18 runout bash heroku-buildpack-python/bin/compile /app /app/.cache /app/.env ||
{
endspin "Bootstrap install failed!"
exit 1
}
rm -rf .cache
export PATH="/app/.heroku/python/bin:$PATH" # Prefer the bootstrapped python, incl. pip, over the system one.
fi
if [ -d "Friendly-Telegram/friendly-telegram" ]; then
cd Friendly-Telegram || {
endspin "Error: Install git package and re-run installer"
exit 6
}
DIR_CHANGED="yes"
fi
if [ -f ".setup_complete" ] || [ -d "friendly-telegram" -a ! x"" = x"$DYNO" ]; then
# If ftg is already installed by this script, or its in Heroku and installed
PYVER=""
if echo "$OSTYPE" | grep -qE '^linux-gnu.*'; then
PYVER="3"
fi
endspin "Existing installation detected"
clear
banner
"python$PYVER" -m friendly-telegram "$@"
exit $?
elif [ "$DIR_CHANGED" = "yes" ]; then
cd ..
fi
##############################################################################
echo "Installing..." >ftg-install.log
if echo "$OSTYPE" | grep -qE '^linux-gnu.*' && [ -f '/etc/debian_version' ]; then
PKGMGR="apt install -y"
if [ ! "$(whoami)" = "root" ]; then
# Relaunch as root, preserving arguments
if command -v sudo >/dev/null; then
endspin "Restarting as root..."
echo "Relaunching" >>ftg-install.log
sudo "$BASH" -c '. <('"$(command -v curl >/dev/null && echo 'curl -Ls' || echo 'wget -qO-')"' https://github.com/GeekTG/Friendly-Telegram/raw/master/install.sh) '"$*"
exit $?
else
PKGMGR="true"
fi
else
runout dpkg --configure -a
runout apt update
fi
PYVER="3"
elif echo "$OSTYPE" | grep -qE '^linux-gnu.*' && [ -f '/etc/arch-release' ]; then
PKGMGR="pacman -Sy --noconfirm"
if [ ! "$(whoami)" = "root" ]; then
# Relaunch as root, preserving arguments
if command -v sudo >/dev/null; then
endspin "Restarting as root..."
echo "Relaunching" >>ftg-install.log
sudo "$BASH" -c '. <('"$(command -v curl >/dev/null && echo 'curl -Ls' || echo 'wget -qO-')"' https://github.com/GeekTG/Friendly-Telegram/raw/master/install.sh) '"$*"
exit $?
else
PKGMGR="true"
fi
fi
PYVER="3"
elif echo "$OSTYPE" | grep -qE '^linux-android.*'; then
runout apt update
PKGMGR="apt install -y"
PYVER=""
elif echo "$OSTYPE" | grep -qE '^darwin.*'; then
if ! command -v brew >/dev/null; then
ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
fi
PKGMGR="brew install"
PYVER="3"
else
endspin "Unrecognised OS. Please follow https://ftg.geektg.ml/#installation"
exit 1
fi
##############################################################################
runout $PKGMGR "python$PYVER" git || { # skipcq
errorout "Core install failed."
exit 2
}
if echo "$OSTYPE" | grep -qE '^linux-gnu.*'; then
runout $PKGMGR "python$PYVER-dev" # skipcq
runout $PKGMGR "python$PYVER-pip" # skipcq
runout $PKGMGR python3 python3-pip git python3-dev libwebp-dev libz-dev libjpeg-dev libopenjp2-7 libtiff5 ffmpeg imamgemagick libffi-dev libcairo2 # skipcq
elif echo "$OSTYPE" | grep -qE '^linux-android.*'; then
runout $PKGMGR openssl libjpeg-turbo libwebp libffi libcairo build-essential libxslt libiconv # skipcq
elif echo "$OSTYPE" | grep -qE '^darwin.*'; then
runout $PKGMGR jpeg webp # skipcq
fi
runout $PKGMGR neofetch dialog # skipcq
##############################################################################
SUDO_CMD=""
if [ ! x"$SUDO_USER" = x"" ]; then
if command -v sudo >/dev/null; then
SUDO_CMD="sudo -u $SUDO_USER "
fi
fi
# shellcheck disable=SC2086
${SUDO_CMD}rm -rf Friendly-Telegram
# shellcheck disable=SC2086
runout ${SUDO_CMD}git clone https://github.com/GeekTG/Friendly-Telegram || {
errorout "Clone failed."
exit 3
}
cd Friendly-Telegram || {
endspin "Error: Install git package and re-run installer"
exit 7
}
# shellcheck disable=SC2086
runin ${SUDO_CMD}"python$PYVER" -m pip install --upgrade pip setuptools wheel --user
# shellcheck disable=SC2086
runin ${SUDO_CMD}"python$PYVER" -m pip install -r requirements.txt --upgrade --user --no-warn-script-location --disable-pip-version-check || {
errorin "Requirements failed!"
exit 4
}
endspin "Installation successful. Launching setup interface..."
rm -f ../ftg-install.log
touch .setup_complete
# shellcheck disable=SC2086,SC2015
${SUDO_CMD}"python$PYVER" -m friendly-telegram "$@" || {
echo "Python scripts failed"
exit 5
}