Skip to content

Instantly share code, notes, and snippets.

@y4kupkaya
Created November 15, 2023 11:49
Show Gist options
  • Save y4kupkaya/b8ef00231769120e2c6df7368162a135 to your computer and use it in GitHub Desktop.
Save y4kupkaya/b8ef00231769120e2c6df7368162a135 to your computer and use it in GitHub Desktop.
BasicBotsSetup
pprint() {
cred='\033[0;31m'
cgreen='\033[0;32m'
cyellow='\033[0;33m'
cblue='\033[0;34m'
cpurple='\033[0;35m'
eval "export color='$cpurple'"
[ ! -z $2 ] && eval "export color=\"\$$2\""
printf "$color $1"
}
color_reset() { printf '\033[0;37m'; }
yesnoprompt() {
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$(head -c 1)
stty $old_stty_cfg
echo "$answer" | grep -iq "^y"
}
update() {
pprint "\n\nUpdating package list.. " "cblue"
sudo apt update 2>&1 | grep "can be upgraded" &>/dev/null
if [ $? -eq 0 ]; then
pprint "UPDATE AVAILABLE" "cgreen"
pprint "\n\nDo you want to automatically upgrade (y/n)?" "cyellow"
if yesnoprompt; then
pprint "\n\nUpgrading packages.. "
sudo apt upgrade -y &>/dev/null &&
pprint "DONE!\n\n" "cgreen" || (
pprint "FAIL.\n\n" "cred"
exit 1
)
else
echo
fi
else
pprint "ALREADY UP TO DATE\n\n" "cgreen"
fi
}
packages() {
if ! command -v pip &>/dev/null; then
pprint "Couldn't found pip, installing now.. "
sudo apt install python3-pip -y 2>pypilog.txt 1>/dev/null &&
pprint "SUCCESS.\n\n" "cgreen" || (
pprint "FAIL.\n\n" "cred"
exit 1
)
fi
if ! command -v ffmpeg &>/dev/null; then
pprint "Couldn't found ffmpeg, installing now.. "
if sudo apt install ffmpeg -y &>/dev/null; then
pprint "SUCCESS.\n\n" "cgreen"
else
pprint "FAIL.\n\n" "cred"
pprint "You need to install ffmpeg manually in order to use , exiting..\n" "cblue"
exit 1
fi
fi
# Check ffmpeg version and warn user if necessary.
fv=$(grep -Po 'version (3.*?) ' <<<$(ffmpeg -version)) &&
pprint "Playing live streams not going to work since you have ffmpeg $fv, live streams are supported by version 4+.\n" "cblue"
}
node() {
#!/bin/bash
# Node.js'nin yüklü olup olmadığını kontrol et
if command -v node &>/dev/null; then
# Node.js sürümünü al
pprint "Node already installed, skipping.. " "cblue"
else
pprint "Couldn't found node, installing now.. " "cblue"
if curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash - &>/dev/null; then
sudo apt install -y nodejs &>/dev/null &&
pprint "SUCCESS.\n\n" "cgreen" || (
pprint "FAIL.\n\n" "cred"
)
else
pprint "FAIL.\n\n" "cred"
exit 1
fi
fi
}
installation() {
pprint "\n\nUpgrading pip and installing dependency packages.. "
pip3 install -U pip &>>pypilog.txt &&
pip3 install -U -r requirements.txt &>>pypilog.txt &&
pprint "DONE.\n" "cgreen" && return
pprint "FAIL.\n" "cred"
exit 1
}
clear
pprint "Welcome to BasicBotsSetup Installer\n\n" "cgreen"
pprint "If you see any error during Installation Process, Please refer to these files for logs: " "cblue"
pprint "\nFor node js errors , Checkout nodelog.txt" "cyellow"
pprint "\nFor pypi packages errors , Checkout pypilog.txt" "cyellow"
sleep 2
pprint "\n\nScript needs sudo privileges in order to update & install packages.\n" "cblue"
sudo test
update
packages
node
installation
pprint "\n\n\n\n\nBasicBotsSetup Installation Completed!" "cgreen"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment