#!/bin/bash
function install_fail() {
echo "Installation failed"
exit 1
}
function Help(){
echo "Usage: install.sh [option]"
echo "Options:"
echo " -h: Show this help message and exit"
echo " -d: Install only dependencies"
echo " -p: Install only python dependencies (including playwright)"
echo " -b: Install just the bot"
echo " -l: Install the bot and the python dependencies"
}
while getopts ":hydpbl" option; do
case $option in
h)
Help exit 0;;
y)
ASSUME_YES=1;;
d)
DEPS_ONLY=1;;
p)
PYTHON_ONLY=1;;
b)
JUST_BOT=1;;
l)
BOT_AND_PYTHON=1;;
\?)
echo "Invalid option: -$OPTARG" >&2 Help exit 1;;
:)
echo "Option -$OPTARG requires an argument." >&2 Help exit 1;;
esac
done
function install_macos(){
if [ ! command -v brew &> /dev/null ]; then
echo "Installing Homebrew"
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
if [[ "uname -m" == "x86_64" ]]; then
echo "export PATH=/usr/local/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
fi
else
echo "Homebrew is already installed"
fi
echo "Installing required Packages"
if [! command --version python3 &> /dev/null ]; then
echo "Installing python3"
brew install python@3.10
else
echo "python3 already installed."
fi
brew install tcl-tk python-tk
}
function install_arch(){
echo "Installing required packages"
sudo pacman -S --needed python3 tk git && python3 -m ensurepip unzip || install_fail
}
function install_deb(){
echo "Installing required packages"
sudo apt install python3 python3-dev python3-tk python3-pip unzip || install_fail
}
function install_fedora(){
echo "Installing required packages"
sudo dnf install python3 python3-tkinter python3-pip python3-devel unzip || install_fail
}
function install_centos(){
echo "Installing required packages"
sudo yum install -y python3 || install_fail
sudo yum install -y python3-tkinter epel-release python3-pip unzip|| install_fail
}
function get_the_bot(){
echo "Downloading the bot"
rm -rf RedditVideoMakerBot-master
curl -sL https://github.com/elebumm/RedditVideoMakerBot/archive/refs/heads/master.zip -o master.zip
unzip master.zip
rm -rf master.zip
}
function install_python_dep(){
echo "Installing python dependencies"
cd RedditVideoMakerBot-master
pip3 install -r requirements.txt
cd ..
}
function install_playwright(){
echo "Installing playwright"
cd RedditVideoMakerBot-master
python3 -m playwright install
python3 -m playwright install-deps
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"
if [ -x "$(command -v pacman)" ]; then
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"
fi
cd ..
}
function install_deps(){
if [ "$(uname)" == "Darwin" ]; then
install_macos || install_fail
elif [ -x "$(command -v pacman)" ]; then
install_arch || install_fail
elif [ -x "$(command -v apt-get)" ]; then
install_deb || install_fail
elif [ -x "$(command -v dnf)" ]; then
install_fedora || install_fail
elif [ -x "$(command -v yum)" ]; then
install_centos || install_fail
else
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
https://github.com/elebumm/RedditVideoMakerBot"
exit 1
fi
}
function install_main(){
echo "Installing..."
if [[ ASSUME_YES -eq 1 ]]; then
echo "Assuming yes"
else
echo "Continue? (y/n)"
read answer
if [ "$answer" != "y" ]; then
echo "Aborting"
exit 1
fi
fi
if [[ DEPS_ONLY -eq 1 ]]; then
echo "Installing only dependencies"
install_deps
elif [[ PYTHON_ONLY -eq 1 ]]; then
echo "Installing only python dependencies"
install_python_dep
install_playwright
elif [[ JUST_BOT -eq 1 ]]; then
echo "Installing only the bot"
get_the_bot
elif [[ BOT_AND_PYTHON -eq 1 ]]; then
echo "Installing only the bot and python dependencies"
get_the_bot
install_python_dep
else
echo "Installing all"
install_deps
get_the_bot
install_python_dep
install_playwright
fi
DIR="./RedditVideoMakerBot-master"
if [ -d "$DIR" ]; then
printf "\nThe bot is installed, want to run it?"
if [[ ASSUME_YES -eq 1 ]]; then
echo "Assuming yes"
else
echo "Continue? (y/n)"
read answer
if [ "$answer" != "y" ]; then
echo "Aborting"
exit 1
fi
fi
cd RedditVideoMakerBot-master
python3 main.py
fi
}
install_main