#!/bin/bash # Functions nuke_hugo () { clear; echo ""; # Nuke the existing Hugo installation echo -e "\e[1;36mNuke the existing Hugo installation...\e[0m"; # Sleep so the screen can be read before moving on sleep 2; # Stop the Hugo dev-server echo ""; echo -e "\e[1;33mStop the Hugo dev-server...\e[0m"; killall hugo; echo -e "\e[32mDone\e[0m"; echo ""; # chown the remote web server directory (take ownership) echo -e "\e[1;33mchown the remote web server directory (take ownership)...\e[0m"; ssh -t foo@server 'sudo chown $USER:$USER -R /var/www/example.org'; echo -e "\e[32mDone\e[0m"; echo ""; # Remove any existing content on the remote web server echo -e "\e[1;33mRemove any existing content on the remote web server...\e[0m"; ssh -t foo@server 'rm -R /var/www/example.org/*'; echo -e "\e[32mDone\e[0m"; echo ""; # Remove any existing local Hugo '/public' content echo -e "\e[1;33mRemove any existing local Hugo '/public' content...\e[0m"; rm -R /path/to/local/hugo/public/*; echo -e "\e[32mDone\e[0m"; echo ""; # Build the new local Hugo website echo -e "\e[1;33mBuild the new local Hugo website...\e[0m"; (cd /path/to/local/hugo/ && hugo); echo -e "\e[32mDone\e[0m"; echo ""; # Copy the Hugo '/public' content to the remote web server echo -e "\e[1;33mCopy the Hugo '/public' content to the remote web server...\e[0m"; scp -r /path/to/local/hugo/public/* foo@server:/var/www/example.org/; echo -e "\e[32mDone\e[0m"; echo ""; # chown the remote web server directory (give ownership to www-data) echo -e "\e[1;33mchown the remote web server directory (give ownership to www-data)...\e[0m"; ssh -t foo@server 'sudo chown www-data:www-data -R /var/www/example.org'; echo -e "\e[32mDone\e[0m"; echo ""; # Backup (rsync) the working directory echo ""; echo -e "\e[1;33mBackup (rsync) the working directory...\e[0m"; rsync -a -P --delete -v --exclude '.git' /path/to/local/hugo /path/to/git/hugo; echo -e "\e[32mDone\e[0m"; echo ""; # Clear out the Hugo generated '/public' folder before syncing (no need to store this in Forgejo) echo -e "\e[1;33mClear out the Hugo generated '/public' folder before syncing (no need to store this in Forgejo)...\e[0m"; rm -R /path/to/git/hugo/public/*; echo -e "\e[32mDone\e[0m"; echo ""; # Push '/path/to/git/hugo/' to Forgejo echo -e "\e[1;33mPush '/path/to/git/hugo/' to Forgejo...\e[0m"; cd /path/to/git/hugo/; git add .; git commit -m 'Modified' .; git push -u origin main; echo -e "\e[32mDone\e[0m"; echo ""; # Start the Hugo dev-server echo -e "\e[1;33mStart the hugo dev-server...\e[0m"; hugo server -s /path/to/local/hugo; echo -e "\e[32mDone\e[0m"; echo ""; } # Start by clearing the Terminal window clear echo ""; echo -e "\e[1;34mUse \e[1;36mCtrl-c\e[1;34m to \e[1;31mExit\e[1;34m and close the window...\e[0m"; echo ""; echo -e "\e[1;31mNuke\e[1;34m will:"; echo -e " Stop the Hugo dev-server"; echo -e " chown the remote web server directory (take ownership)"; echo -e " Remove any existing content on the remote web server"; echo -e " Remove any existing local Hugo '/public' content"; echo -e " Build the new local Hugo website"; echo -e " Copy the Hugo '/public' content to the remote web server"; echo -e " chown the remote web server directory (give ownership to www-data)"; echo -e " Backup (rsync) the working directory"; echo -e " Clear out the Hugo generated '/public' folder before syncing (no need to store this in Forgejo)"; echo -e " Push '/path/to/git/hugo/' to Forgejo"; echo -e " Start the Hugo dev-server"; echo ""; # Loop while true; do options=("Nuke") echo -e "\e[1;36mChoose an option:\e[0m" select opt in "${options[@]}"; do case $REPLY in 1) nuke_hugo; break ;; *) echo "Whoops, choose again, option '$REPLY' is invalid..." >&2 esac done done