Skip to content

Instantly share code, notes, and snippets.

@Eventyret
Created August 22, 2023 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eventyret/156833b1295515bb31ea2ada52be60e4 to your computer and use it in GitHub Desktop.
Save Eventyret/156833b1295515bb31ea2ada52be60e4 to your computer and use it in GitHub Desktop.
Dokku Setup
#!/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