Created
August 22, 2023 20:47
-
-
Save Eventyret/156833b1295515bb31ea2ada52be60e4 to your computer and use it in GitHub Desktop.
Dokku Setup
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
#!/bin/bash | |
function update_packages() { | |
echo -e "\nπ¦ Updating packages... π¦\n" | |
apt-get update -y | |
apt-get upgrade -y | |
apt-get dist-upgrade -y | |
apt-get autoremove -y | |
apt-get autoclean -y | |
} | |
function upgrade_release() { | |
echo -e "\nπ Upgrading release... π\n" | |
do-release-upgrade -f DistUpgradeViewNonInteractive | |
} | |
function create_new_user() { | |
echo -e "\nπ€ Creating a new user... π€\n" | |
read -p "Enter a username (default: ubuntu): " NEW_USER_INPUT | |
NEW_USER=${NEW_USER_INPUT:-ubuntu} | |
echo -e "\nπ€ Using username: $NEW_USER π€\n" | |
adduser $NEW_USER | |
echo -e "\nπ₯ Adding $NEW_USER to sudo group... π₯\n" | |
usermod -aG sudo $NEW_USER | |
} | |
function dokku_setup() { | |
echo -e "\nπ₯ Downloading and executing Dokku installation script... π₯\n" | |
wget -NP . https://dokku.com/bootstrap.sh | |
DOKKU_TAG=v0.31.0 bash bootstrap.sh | |
read -p "Please provide your domain (or press enter if you don't have one): " DOMAIN | |
if [ -z "$DOMAIN" ]; then | |
IP_ADDRESS=$(hostname -I | awk '{print $1}') | |
echo -e "\nYou didn't provide a domain. Here's the IP address of your host: $IP_ADDRESS\n" | |
else | |
echo -e "\nπ Configuring server domain... π\n" | |
dokku domains:set-global $DOMAIN | |
fi | |
while true; do | |
read -p "Please provide the PUBLIC SSH KEY for the dokku user (This is mandatory): " PUBLIC_KEY | |
if [ -z "$PUBLIC_KEY" ]; then | |
echo "The PUBLIC SSH KEY is mandatory. Please provide a valid key." | |
else | |
break | |
fi | |
done | |
echo -e "\nπ Adding ssh key to the dokku user... π\n" | |
echo "$PUBLIC_KEY" | dokku ssh-keys:add admin | |
} | |
function dokku_plugins() { | |
echo -e "\nπ Installing Dokku plugins... π\n" | |
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres | |
sudo dokku plugin:install https://github.com/dokku/dokku-mongo.git mongo | |
sudo dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql | |
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git | |
while true; do | |
read -p "Please provide your email for Let's Encrypt (This is mandatory): " EMAIL | |
if [ -z "$EMAIL" ]; then | |
echo "The email is mandatory for Let's Encrypt. Please provide a valid email." | |
else | |
break | |
fi | |
done | |
sudo dokku letsencrypt:set --global email $EMAIL | |
sudo dokku git:set --global deploy-branch main | |
} | |
function post_setup() { | |
echo -e "\nπ₯ Adding $NEW_USER to the required groups... π₯\n" | |
usermod -aG adm,dokku,docker $NEW_USER | |
echo -e "\nπ« Disabling root SSH login... π«\n" | |
sed -i 's/^PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config | |
service ssh restart | |
} | |
# Check if the system is Debian or Ubuntu | |
function is_debian_or_ubuntu() { | |
if grep -qE "Debian|Ubuntu" /etc/os-release; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# Ask users to star your gist | |
function ask_to_star_gist() { | |
echo -e "\nβοΈ Please consider starring our GitHub Gist: [Your GitHub Gist URL here] βοΈ\n" | |
} | |
# Menu for user interaction | |
echo -e "\nπ Welcome to the server setup! π\n" | |
echo "Please select an option:" | |
PS3='Enter your choice: ' | |
options=("Complete Setup" "Only Dokku" "Only Dokku Plugins" "Quit") | |
select opt in "${options[@]}" | |
do | |
case $opt in | |
"Complete Setup") | |
if is_debian_or_ubuntu; then | |
update_packages | |
upgrade_release | |
create_new_user | |
else | |
echo "The system is not Debian or Ubuntu. Skipping system upgrades and user creation." | |
fi | |
dokku_setup | |
dokku_plugins | |
post_setup | |
ask_to_star_gist | |
while true; do | |
read -p "Would you like to reboot now? (Y/n): " REBOOT_CHOICE | |
case $REBOOT_CHOICE in | |
[Yy]* ) | |
echo -e "\nπ REBOOTING NOW π\n" | |
reboot now | |
break | |
;; | |
[Nn]* ) | |
echo "Reboot canceled. Exiting..." | |
exit 1 | |
;; | |
*) | |
echo "Please answer with Y (yes) or n (no)." | |
;; | |
esac | |
done | |
break | |
;; | |
"Only Dokku") | |
dokku_setup | |
ask_to_star_gist | |
break | |
;; | |
"Only Dokku Plugins") | |
dokku_plugins | |
ask_to_star_gist | |
break | |
;; | |
"Quit") | |
ask_to_star_gist | |
echo "Exiting..." | |
break | |
;; | |
*) | |
echo "invalid option $REPLY" | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment