-
Notifications
You must be signed in to change notification settings - Fork 389
/
install.sh
executable file
·255 lines (208 loc) · 8.13 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/usr/bin/env bash
clear
# Clear screen before running any commands
REQUIREMENTS_INSTALLED=0
# Implemented in install_MAIN
DEPS_ONLY=0
# Implemented at bottom of file
PDEPS_ONLY=0
# Implemented at bottom of file
ASSUME_YES=0
# Implemented in confirm function
print_usage() {
# Display Usage
echo "Usage: $0 [-y] [-d] [-c] [-p] [-h]"
echo
echo "Installer script for The YouTube Spammer Purge application."
echo
echo "Options:"
echo " -y Assume yes: Skip confirmation prompts."
echo " -d Only install OS-Specific dependencies."
echo " -c Skip installing OS-Specific dependencies."
echo " This could be useful to those who have unsupported systems"
echo " -p Only install Python dependencies"
echo " -h Print this Help."
echo
}
# Get the options
while getopts ":hdcyp" option; do
case $option in
h) # display Help
print_usage
exit;;
d) # Install dependencies only
DEPS_ONLY=1;;
c) # Skip installing dependencies
REQUIREMENTS_INSTALLED=1;;
p) # Install Python dependencies only
PDEPS_ONLY=1;;
y) # Assume YES
ASSUME_YES=1;;
\?) # Invalid option
echo "Error: Invalid option. See option -h for help."
exit 1 ;;
esac
done
# Credit to https://stackoverflow.com/questions/29436275/how-to-prompt-for-yes-or-no-in-bash
# Slightly edited
confirm() {
[[ $ASSUME_YES -eq 1 ]] && echo "Assuming YES." && return 0
while true; do
read -r -p "$* [y/n]: " yn
if [[ "$yn" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
return 0
fi
if [[ "$yn" =~ ^([nN][oO]|[nN])+$ ]]; then
return 1
fi
done
}
install_fail () {
echo "Install Failed."
exit 1
}
install_debian () {
sudo apt-get install python3 python3-dev python3-tk python3-pip git || install_fail
}
install_fedora () {
sudo dnf install python3 python3-tkinter python3-pip git python3-devel || install_fail
}
install_centos () {
sudo yum install -y python3 || install_fail
rpm -q epel-release &> /dev/null || EPEL=0
sudo yum install -y python3-tkinter epel-release python3-pip git || install_fail
# Honestly not sure why it's installing epel and then uninstalling
[[ $EPEL -eq 0 ]] && sudo yum remove -y epel-release
}
install_arch () {
sudo pacman -S --needed python3 tk git && python3 -m ensurepip || install_fail
}
install_macos() {
echo "This script will install Homebrew, along with YT-Spammer-Purge's requirements."
echo "Continue installation?"
confirm && echo "Ok, installing requirements." || install_fail
if test ! "$(which brew)"; then
#Install homebrew
echo "Installing homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# Install python3.10 & git or fail out
brew install python@3.10 && \
brew install tcl-tk && \
brew install python-tk && \
brew install git || \
install_fail
}
install_python_requirements () {
python3 -m pip install -q -r requirements.txt --user && \
echo "Python requirements installed." || exit 1
# Pip should give an error if it fails.
}
install_os_requirements () {
echo "YT-Spammer-Purge has a few OS-Specific requirements that you will need to install."
# Check for known OS's
INSTALLED=0
case "$(uname -s)" in
Darwin*) install_macos && INSTALLED=1 || install_fail;;
# Mac
#CYGWIN*) do_something;;
# Cygwin Emulator -- Unimplemented
#MINGW*) do_something;;
# MINGW Emulator -- Unimplemented
esac
[[ -e /etc/debian_version ]] && install_debian && INSTALLED=1
[[ -e /etc/fedora-release ]] && install_fedora && INSTALLED=1
[[ -e /etc/centos-release ]] && install_centos && INSTALLED=1
[[ -e /etc/arch-release ]] && install_arch && INSTALLED=1
[[ $INSTALLED -eq 0 ]] && printf "You are on an unknown system. You will have to install the required packages manually.\nAfter installing your requirements, you can run install.sh -c to skip this step of the installation.\nContributions are welcome to add support for your system:\nhttps://github.com/ThioJoe/YT-Spammer-Purge" && exit 1
return 0
}
install_latest_release () {
echo "We are now going to download the code for YT-Spammer-Purge."
git clone https://github.com/ThioJoe/YT-Spammer-Purge
cd YT-Spammer-Purge || exit 5
# Use non-1 exit code for debugging
git checkout -q -m "$(git describe --abbrev=0 --tags)"
# Go to latest release
}
install_MAIN () {
clear
echo "We will now install YT-Spammer-Purge."
echo "Continue?"
confirm || install_fail
echo "Installing."
# Check what OS we're running on
# Check if we already installed the requirements -- git is needed to check for which mode to run.
[[ $REQUIREMENTS_INSTALLED -eq 0 ]] && install_os_requirements
echo "--------------------------"
install_latest_release
# install_latest_release cd's into YT-Spammer-Purge
# Since we've gotten python3 installed:
echo "--------------------------"
install_python_requirements
# Done!
printf "Dependencies and Program installed into .\YT-Spammer-Purge!\nNow follow these instructions to get a client_secrets.json file!\nhttps://github.com/ThioJoe/YT-Spammer-Purge/wiki/Instructions:-Obtaining-an-API-Key\n\nYou may run this script again inside your installation to update.\n"
exit 0
}
check_python_requirements () {
# This assumes we are in the YT-Spammer-Purge directory
echo "Checking installed requirements"
python3 -c "import pkg_resources; pkg_resources.require(open('requirements.txt',mode='r'))" &>/dev/null || install_python_requirements
}
update () {
# This assumes we are in the YT-Spammer-Purge directory
check_python_requirements
clear
echo "We will now attempt to update YT-Spammer-Purge."
echo "Current version is $(git describe --abbrev=0 --tags)"
echo "Continue?"
confirm || exit 1
echo "Updating..."
git fetch origin
echo "Latest version is $(git describe origin --abbrev=0 --tags)"
echo "Updating to this version."
git checkout -q -m "$(git describe origin --abbrev=0 --tags)"
install_python_requirements
# In case requirements are updated
echo "--------------------------"
echo "Updated!"
echo "Report any bugs to TJoe.io/bug-report"
exit 0
}
check_git_missing () {
[[ $(git remote get-url origin) == *"YT-Spammer-Purge"* ]] && return 0
# If this is a valid YT-Spammer-Purge install, return 0
# If this is a fork, with a name different than YT-Spammer-Purge, this check will fail.
# If you are running this on a fork, please replace every instance of 'YT-Spammer-Purge' with your fork name.
clear
echo "It looks like you downloaded a .zip of YT-Spammer-Purge"
echo "Automated updates do not work on these versions, but you may download the latest version of YT-Spammer-Purge using this script."
echo "If you choose to re-download the latest verion of YT-Spammer-Purge using this script, automated updates will be re-enabled."
echo "The latest YT-Spammer-Purge with automated updates will be downloaded to a sub-directory of the same name."
echo "Would you like to re-install YT-Spammer-Purge?"
confirm && echo "OK, installing." || exit 1
install_MAIN
exit 0
}
# Start running commands to choose what to do next.
[[ $DEPS_ONLY -eq 1 ]] && install_os_requirements && exit 0
[[ $PDEPS_ONLY -eq 1 ]] && install_python_requirements && exit 0
# Check if any of these commands are missing/failing:
# - git
# - python3
# - python3 -c "import tkinter"
#
if ( ! command -v git &> /dev/null ) | ( ! command -v python3 &> /dev/null ) | ( ! python3 -c "import tkinter" &>/dev/null )
then
echo "You are missing some required packages."
install_os_requirements
REQUIREMENTS_INSTALLED=1
fi
[[ -e YTSpammerPurge.py ]] && check_git_missing && update
# If YTSpammerPurge.py exists in the dir, check if it is a valid YT-Spammer-Purge install, and either re-install or update
# These will exit when they succeed
install_MAIN
# If get-url succeeds, update, else install
# Will exit if succeed
# Script should not reach this point, error if it does
exit 1