Last active
March 30, 2021 17:38
-
-
Save BlueSlimee/0d5132e25326e5d2cce98ead0466a0af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SUPERUSER=sudo | |
function welcome_screen() { | |
echo "Chino Kafuu first run setup" | |
echo "Stream Arular by M.I.A." | |
echo "---------------------------" | |
} | |
function install_debian_based_deps() { | |
$SUPERUSER apt-get update | |
$SUPERUSER apt-get install \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
gnupg | |
} | |
function check_for_lsb_release() { | |
if [ ! -x "$(command -v lsb_release)" ]; then | |
if [ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]; then | |
echo "Missing lsb_release. I'll install it, but next time I might not." | |
$SUPERUSER apt-get install lsb-release -y | |
else | |
echo "Missing lsb_release. Are you a Linux user even? Install it and try again. I'd install it for you, but I only speak apt-get." | |
exit 1 | |
fi | |
fi | |
} | |
function check_for_curl() { | |
if [ ! -x "$(command -v curl)" ]; then | |
echo "Bruh, this system doesn't have curl installed" | |
echo "This is ghetto. I'm leaving. Install curl." | |
exit 1 | |
fi | |
} | |
function check_requirements() { | |
detect_docker | |
check_for_lsb_release | |
check_for_curl | |
DISTRO=$(lsb_release -i | cut -f 2-) | |
case $DISTRO in | |
CentOS) | |
echo "Detected CentOS (who even uses CentOS? tf)" | |
$SUPERUSER yum install -y yum-utils | |
$SUPERUSER yum-config-manager \ | |
--add-repo \ | |
https://download.docker.com/linux/centos/docker-ce.repo || exit 1 | |
$SUPERUSER dnf install docker-ce docker-ce-cli containerd.io -y || exit 1 | |
;; | |
Fedora) | |
echo "Detected Fedora system (who even uses Fedora? tf)" | |
$SUPERUSER dnf -y install dnf-plugins-core | |
$SUPERUSER dnf config-manager \ | |
--add-repo \ | |
https://download.docker.com/linux/fedora/docker-ce.repo || exit 1 | |
$SUPERUSER dnf install docker-ce docker-ce-cli containerd.io -y || exit 1 | |
;; | |
Ubuntu) | |
echo "Detected Ubuntu system." | |
install_debian_based_deps | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg || exit 1 | |
echo \ | |
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ | |
$(lsb_release -cs) stable" | $SUPERUSER tee /etc/apt/sources.list.d/docker.list > /dev/null || exit 1 | |
$SUPERUSER apt-get update || exit 1 | |
$SUPERUSER apt-get install docker-ce docker-ce-cli containerd.io -y || exit 1 | |
;; | |
Debian) | |
echo "Detected Debian system." | |
install_debian_based_deps | |
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg || exit 1 | |
echo \ | |
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \ | |
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null || exit 1 | |
$SUPERUSER apt-get update || exit 1 | |
$SUPERUSER apt-get install docker-ce docker-ce-cli containerd.io -y || exit 1 | |
;; | |
*) | |
echo "$DISTRO isn't compatible (yet!)." | |
exit 1 | |
;; | |
esac | |
start_docker | |
echo "Docker is R2G; Installing Chino Kafuu." | |
install_chino | |
exit 0 | |
} | |
function install_chino() { | |
if [ -f ".env" ]; then | |
echo "Pulling docker images..." | |
echo "Pulling WatchTower..." | |
docker run -d \ | |
--name watchtower \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
--restart=always \ | |
containrrr/watchtower | |
echo "Pulling Tokamak..." | |
docker run -d \ | |
--name tokamak \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
--restart=always \ | |
--publish 127.0.0.1:1234:1234/tcp \ | |
rabbithousecorp/tokamak:latest | |
echo "Pulling Chino Kafuu..." | |
docker run -d \ | |
--name chino-stable \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
--env-file .env \ | |
--restart=always \ | |
rabbithousecorp/chinokafuu:dev | |
echo "Done. Chino Kafuu and its dependencies should be running just fine now." | |
echo "Also, the bot will automatically start on boot." | |
docker ps | |
echo "Installation script leaving! Bye." | |
exit 0 | |
fi | |
echo "Missing .env file. Please get the .env file." | |
exit 1 | |
} | |
function detect_docker() { | |
if [ -x "$(command -v docker)" ]; then | |
echo "Docker is already installed, skipping installation process." | |
install_chino | |
exit 0 | |
fi | |
} | |
function check_sudo() { | |
if [ -x "$(command -v sudo)" ]; then | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script should be ran with sudo. Try that." | |
exit 1 | |
fi | |
check_requirements | |
else | |
SUPERUSER="" | |
echo "This is interesting, your system doesn't have sudo installed. Running commands without sudo." | |
check_requirements | |
fi | |
} | |
function start_docker() { | |
if [ -x "$(command -v systemctl)" ]; then | |
$SUPERUSER systemctl start docker | |
elif [ -x "$(command -v rc-update)" ]; then | |
echo "A hippie was detected! (I mean, an OpenRC user.)" | |
$SUPERUSER rc-update add docker boot | |
$SUPERUSER service start docker | |
else | |
if [ -x "$(command -v service)" ]; then | |
echo "I tried making docker start at boot, but I couldn't detect your init system." | |
echo "Since service is avaliable, I'll be able to proceed. However," | |
echo "If you want for Chino to start at boot, you'll have to do it manually." | |
$SUPERUSER service start docker | |
else | |
echo "I couldn't figure out how to start docker in this enviroment." | |
echo "Currently supported systems: OpenRC, SystemD or a system with \"service\" avaliable." | |
echo "This is what you get for trying to be a hippie. Sorry." | |
exit 1 | |
fi | |
fi | |
} | |
welcome_screen | |
check_sudo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment