forked from mindhuntr/cli-torrent-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·220 lines (190 loc) · 7.31 KB
/
setup.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
#!/usr/bin/env bash
PS1B=$PS1
set -euo pipefail
C_RED="\033[0;31m"
C_GREEN="\033[0;32m"
C_NONE="\033[0m"
# Get path of the dinga ding dang, dinga dang dong all symlinks
SOURCE="${BASH_SOURCE[0]}"
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" > /dev/null 2>&1 && pwd)"
LN_CMD_TORDL=('ln' '-sf' "$SCRIPT_DIR/tordl.sh")
LN_CMD_JAWN=("ln" "-sf" "$SCRIPT_DIR/littleredrooster.sh")
while [[ -h $SOURCE ]]; do
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" > /dev/null 2>&1 && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE = /* ]] || SOURCE="$SCRIPT_DIR/$SOURCE"
done
# This seems more like a fallback
if [[ $PATH =~ "$HOME/.local/bin" ]]; then
BIN_TORDL="$HOME/.local/bin/tordl"
BIN_CLUCKIN="$HOME/.local/bin/littleredrooster"
LN_CMD_TORDL+=("$BIN_TORDL")
LN_CMD_JAWN+=("$BIN_CLUCKIN")
BIN_DIR_SUDO=0
else
BIN_TORDL='/usr/local/bin/tordl'
BIN_CLUCKIN='/usr/local/bin/littleredrooster'
# On my system it always defaults to to this one
LN_CMD_TORDL=('sudo' "${LN_CMD_TORDL[@]}" "$BIN_TORDL")
LN_CMD_JAWN=('sudo' "${LN_CMD_JAWN[@]}" "$BIN_CLUCKIN")
BIN_DIR_SUDO=1
fi
eval "${LN_CMD_TORDL[@]}"
eval "${LN_CMD_JAWN[@]}"
XDG_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/torrentdl"
VENV_DIR="$XDG_CONFIG_DIR/.venv"
PYTHON_LATEST_VERSION=11
PYTHON_MIN_VERSION=8
PYTHON_DEFAULT_VERSION="$(python3 -V | tr -d '[A-Za-z]' | awk -F . '{print $2}')"
UNINSTALL=0
# HEN HOUSE BABY!
TORDL_BIN_PATH="${LN_CMD_TORDL[${#LN_CMD_TORDL[@]}-1]}"
JAWN_BIN_PATH="${LN_CMD_JAWN[${#LN_CMD_JAWN[@]}-1]}"
function print_help {
printf "${C_GREEN}-h | --help${C_NONE} : Print this help\n"
printf "${C_GREEN}-p=* | --python=*${C_NONE} : Use specific python3 minor version (8,9,10,11) [example: setup.sh -p=11]\n"
printf "${C_GREEN}-u | --uninstall${C_NONE} : Uninstall tordl from the System\n [example: setup.sh -u]"
}
for i in "$@"; do
case $i in
-p=*|--python=*)
PYTHON_DEFAULT_VERSION=""
PYTHON_LATEST_VERSION="${i#*=}"
if [[ -z $(which "python3.$PYTHON_LATEST_VERSION") ]]; then
printf "${C_RED}User set python3.$PYTHON_LATEST_VERSION not found on the System${C_NONE}"
exit 1
fi
;;
-u|--uninstall)
UNINSTALL=1
;;
-h|--help)
print_help
exit 0
;;
*)
echo "Unknown Argument $i"
exit 1
;;
esac
done
# Uninstall tordl + littleredrooster from the System
if (( $UNINSTALL == 1 )); then
printf "${C_GREEN}Uninstalling tordl + littleredrooster from the System...${C_NONE}\n"
echo "Removing $XDG_CONFIG_DIR..."
if [[ -e $XDG_CONFIG_DIR ]]; then
rm -rf "$XDG_CONFIG_DIR"
printf "${C_GREEN}${XDG_CONFIG_DIR} Removed ${C_NONE}\n"
else
printf "${C_RED}Unable to remove Config Dir $XDG_CONFIG_DIR, does not exist${C_NONE}\n"
fi
echo "Removing $TORDL_BIN_PATH..."
if [[ -e $TORDL_BIN_PATH ]]; then
if (( "$BIN_DIR_SUDO" == 0 )); then
rm $TORDL_BIN_PATH
printf "${C_GREEN}${TORDL_BIN_PATH} Removed ${C_NONE}\n"
else
sudo rm $TORDL_BIN_PATH
printf "${C_GREEN}${TORDL_BIN_PATH} Removed ${C_NONE}\n"
fi
else
printf "${C_RED}Unable to remove tordl bin Link $TORDL_BIN_PATH, does not exist${C_NONE}\n"
fi
echo "Removing $JAWN_BIN_PATH..."
if [[ -e $JAWN_BIN_PATH ]]; then
if (( "$BIN_DIR_SUDO" == 0 )); then
rm $JAWN_BIN_PATH
printf "${C_GREEN}${JAWN_BIN_PATH} Removed ${C_NONE}\n"
else
sudo rm $JAWN_BIN_PATH
printf "${C_GREEN}${JAWN_BIN_PATH} Removed ${C_NONE}\n"
fi
else
printf "${C_RED}Unable to remove littleredrooster bin Link $JAWN_BIN_PATH, does not exist${C_NONE}\n"
fi
exit 0
fi
printf ${C_GREEN}
if [[ -z "$PYTHON_DEFAULT_VERSION" ]]; then
echo "Using Python Version 3.$PYTHON_LATEST_VERSION"
else
echo "Using Python Version 3.$PYTHON_DEFAULT_VERSION"
fi
printf ${C_NONE}
if [[ -d $VENV_DIR ]]; then
while true; do
printf ${C_GREEN}
read -p 'Delete and re-install virtualenv? [y/N]: ' choice
printf ${C_NONE}
# Convert $choice to lowercase to keep things clean.
case "${choice,,}" in
'y')
rm -rf "$VENV_DIR"
# Now we can proceed.
break
;;
''|'n')
exit
;;
esac
done
# Not sure how this would happen.
# Maybe corruption or an accidental overwrite?
# Might as well plan for the worst.
elif [[ -e $VENV_DIR ]]; then
printf '%s\n' 'Broken virtualenv detected. Reinstalling...'
# Backup old venv in case it's still of some value.
# Won't overwrite existing files.
mv --backup=numbered "$VENV_DIR"{,.bak}
printf '${C_GREEN}%s %s\n\n' 'Created backup of virtualenv at' "$VENV_DIR.bak${C_NONE}"
fi
if [[ $PYTHON_DEFAULT_VERSION -ge $PYTHON_MIN_VERSION ]]; then
# if possible, use default system python version
PYTHON_BIN='python3'
else
# Default python version too low (or not found) try to find specific version
for (( i="$PYTHON_LATEST_VERSION"; i >= "$PYTHON_MIN_VERSION"; i--)); do
if [[ -n "$(which python3."$i")" ]]; then
PYTHON_BIN="python3.$i"
break
fi
done
if [[ -z $PYTHON_BIN ]]; then
# No suitable python version was found, inform user and exit
printf '${C_RED}%s\n' 'tordl requires Python 3.8 or higher.' \
'Please install it (on debian based systems: $ sudo apt-get install python3.8)${C_NONE}'
exit 1
fi
fi
printf '${C_GREEN}%s\n' "Using Python $PYTHON_BIN, located here: $(which $PYTHON_BIN)${C_NONE}\n"
virtualenv -p $PYTHON_BIN "$VENV_DIR"
PS1=$PS1B
. "$VENV_DIR/bin/activate"
pip3 install -r "$SCRIPT_DIR/requirements.txt"
clear
# Don't remove this or you'll screw up the whole jib
sudo chmod +x ./littleredrooster.sh
echo -e "
\e[31m
⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣶⣤⣴⣿⣧⣴⡆⠀⠀
⠀⠀⠀⠀⠠⣤⣄⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⢿⠟⢋⣡⢌⠉⠉⠀⠀⠀
⠀⠀⠀⠙⢿⣿⣷⣦⢰⣧⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣷⠺⠿⢷⡀⠀⠀
⠀⠀⠀⣠⣶⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⠀⠀⢸⣿⣇⠐⣶⡀⠀⠀⠀
⠀⠀⠁⣠⠶⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀⠀⠀⢀⣼⣿⣿⣦⣈⡁⠀⠀⠀
⠀⠀⠀⠀⢠⣾⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⠀⡾⠿⢿⣿⢿⣿⣿⣷⠀⠀⠀
⠀ ⠀⠀⠀⠘⠁⣴⣿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣤⡄⠘⢁⠘⠏⣁⠛⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡿⠁⢾⡟⠉⠻⣿⣿⣿⣿⣿⣿⣿⣿⣷⣴⣿⡄⣴⣿⠀⠀⠀⠀
⠀ ⠀⠀⠀⠀⠀⠘⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⠀⠀⠀
⠀ ⠀⠀⠀⠀⠀⠀⠙⠻⣿⣿⣿⣿⡿⠟⠋⠁⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠿⠿⠿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣶⣠⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⢉⣿⣿⡏⣿⡶⣤⣄⠀\e[0m"
echo -e "
\033[1m\033[5m*peck*\033[0m Congrats, you're a degenerate now. \033[1m\033[5m*peck*\033[0m"
# I removed the whole choice to bind to /usr/local/ bin or /.local/bin because it wasn't doing anything.
# The if command above was automatically choosing either path before the user was presented with the option...
# I don't know why that is...
# But I DO know that I can work on it later..