Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
elebumm
GitHub Repository: elebumm/RedditVideoMakerBot
Path: blob/master/install.sh
326 views
1
#!/bin/bash
2
3
# If the install fails, then print an error and exit.
4
function install_fail() {
5
echo "Installation failed"
6
exit 1
7
}
8
9
# This is the help fuction. It helps users withe the options
10
function Help(){
11
echo "Usage: install.sh [option]"
12
echo "Options:"
13
echo " -h: Show this help message and exit"
14
echo " -d: Install only dependencies"
15
echo " -p: Install only python dependencies (including playwright)"
16
echo " -b: Install just the bot"
17
echo " -l: Install the bot and the python dependencies"
18
}
19
20
# Options
21
while getopts ":hydpbl" option; do
22
case $option in
23
# -h, prints help message
24
h)
25
Help exit 0;;
26
# -y, assumes yes
27
y)
28
ASSUME_YES=1;;
29
# -d install only dependencies
30
d)
31
DEPS_ONLY=1;;
32
# -p install only python dependencies
33
p)
34
PYTHON_ONLY=1;;
35
b)
36
JUST_BOT=1;;
37
l)
38
BOT_AND_PYTHON=1;;
39
# if a bad argument is given, then throw an error
40
\?)
41
echo "Invalid option: -$OPTARG" >&2 Help exit 1;;
42
:)
43
echo "Option -$OPTARG requires an argument." >&2 Help exit 1;;
44
esac
45
done
46
47
# Install dependencies for MacOS
48
function install_macos(){
49
# Check if homebrew is installed
50
if [ ! command -v brew &> /dev/null ]; then
51
echo "Installing Homebrew"
52
# if it's is not installed, then install it in a NONINTERACTIVE way
53
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
54
# Check for what arcitecture, so you can place path.
55
if [[ "uname -m" == "x86_64" ]]; then
56
echo "export PATH=/usr/local/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
57
fi
58
# If not
59
else
60
# Print that it's already installed
61
echo "Homebrew is already installed"
62
fi
63
# Install the required packages
64
echo "Installing required Packages"
65
if [! command --version python3 &> /dev/null ]; then
66
echo "Installing python3"
67
brew install python@3.10
68
else
69
echo "python3 already installed."
70
fi
71
brew install tcl-tk python-tk
72
}
73
74
# Function to install for arch (and other forks like manjaro)
75
function install_arch(){
76
echo "Installing required packages"
77
sudo pacman -S --needed python3 tk git && python3 -m ensurepip unzip || install_fail
78
}
79
80
# Function to install for debian (and ubuntu)
81
function install_deb(){
82
echo "Installing required packages"
83
sudo apt install python3 python3-dev python3-tk python3-pip unzip || install_fail
84
}
85
86
# Function to install for fedora (and other forks)
87
function install_fedora(){
88
echo "Installing required packages"
89
sudo dnf install python3 python3-tkinter python3-pip python3-devel unzip || install_fail
90
}
91
92
# Function to install for centos (and other forks based on it)
93
function install_centos(){
94
echo "Installing required packages"
95
sudo yum install -y python3 || install_fail
96
sudo yum install -y python3-tkinter epel-release python3-pip unzip|| install_fail
97
}
98
99
function get_the_bot(){
100
echo "Downloading the bot"
101
rm -rf RedditVideoMakerBot-master
102
curl -sL https://github.com/elebumm/RedditVideoMakerBot/archive/refs/heads/master.zip -o master.zip
103
unzip master.zip
104
rm -rf master.zip
105
}
106
107
#install python dependencies
108
function install_python_dep(){
109
# tell the user that the script is going to install the python dependencies
110
echo "Installing python dependencies"
111
# cd into the directory
112
cd RedditVideoMakerBot-master
113
# install the dependencies
114
pip3 install -r requirements.txt
115
# cd out
116
cd ..
117
}
118
119
# install playwright function
120
function install_playwright(){
121
# tell the user that the script is going to install playwright
122
echo "Installing playwright"
123
# cd into the directory where the script is downloaded
124
cd RedditVideoMakerBot-master
125
# run the install script
126
python3 -m playwright install
127
python3 -m playwright install-deps
128
# give a note
129
printf "Note, if these gave any errors, playwright may not be officially supported on your OS, check this issues page for support\nhttps://github.com/microsoft/playwright/issues"
130
if [ -x "$(command -v pacman)" ]; then
131
printf "It seems you are on and Arch based distro.\nTry installing these from the AUR for playwright to run:\nenchant1.6\nicu66\nlibwebp052\n"
132
fi
133
cd ..
134
}
135
136
# Install depndencies
137
function install_deps(){
138
# if the platform is mac, install macos
139
if [ "$(uname)" == "Darwin" ]; then
140
install_macos || install_fail
141
# if pacman is found
142
elif [ -x "$(command -v pacman)" ]; then
143
# install for arch
144
install_arch || install_fail
145
# if apt-get is found
146
elif [ -x "$(command -v apt-get)" ]; then
147
# install fro debian
148
install_deb || install_fail
149
# if dnf is found
150
elif [ -x "$(command -v dnf)" ]; then
151
# install for fedora
152
install_fedora || install_fail
153
# if yum is found
154
elif [ -x "$(command -v yum)" ]; then
155
# install for centos
156
install_centos || install_fail
157
# else
158
else
159
# print an error message and exit
160
printf "Your OS is not supported\n Please install python3, pip3 and git manually\n After that, run the script again with the -pb option to install python and playwright dependencies\n If you want to add support for your OS, please open a pull request on github\n
161
https://github.com/elebumm/RedditVideoMakerBot"
162
exit 1
163
fi
164
}
165
166
# Main function
167
function install_main(){
168
# Print that are installing
169
echo "Installing..."
170
# if -y (assume yes) continue
171
if [[ ASSUME_YES -eq 1 ]]; then
172
echo "Assuming yes"
173
# else, ask if they want to continue
174
else
175
echo "Continue? (y/n)"
176
read answer
177
# if the answer is not yes, then exit
178
if [ "$answer" != "y" ]; then
179
echo "Aborting"
180
exit 1
181
fi
182
fi
183
# if the -d (only dependencies) options is selected install just the dependencies
184
if [[ DEPS_ONLY -eq 1 ]]; then
185
echo "Installing only dependencies"
186
install_deps
187
elif [[ PYTHON_ONLY -eq 1 ]]; then
188
# if the -p (only python dependencies) options is selected install just the python dependencies and playwright
189
echo "Installing only python dependencies"
190
install_python_dep
191
install_playwright
192
# if the -b (only the bot) options is selected install just the bot
193
elif [[ JUST_BOT -eq 1 ]]; then
194
echo "Installing only the bot"
195
get_the_bot
196
# if the -l (bot and python) options is selected install just the bot and python dependencies
197
elif [[ BOT_AND_PYTHON -eq 1 ]]; then
198
echo "Installing only the bot and python dependencies"
199
get_the_bot
200
install_python_dep
201
# else, install everything
202
else
203
echo "Installing all"
204
install_deps
205
get_the_bot
206
install_python_dep
207
install_playwright
208
fi
209
210
DIR="./RedditVideoMakerBot-master"
211
if [ -d "$DIR" ]; then
212
printf "\nThe bot is installed, want to run it?"
213
# if -y (assume yes) continue
214
if [[ ASSUME_YES -eq 1 ]]; then
215
echo "Assuming yes"
216
# else, ask if they want to continue
217
else
218
echo "Continue? (y/n)"
219
read answer
220
# if the answer is not yes, then exit
221
if [ "$answer" != "y" ]; then
222
echo "Aborting"
223
exit 1
224
fi
225
fi
226
cd RedditVideoMakerBot-master
227
python3 main.py
228
fi
229
}
230
231
# Run the main function
232
install_main
233
234