From 41e897f4945aaf8fbcdf0b12ac2f08c5e6ae0458 Mon Sep 17 00:00:00 2001 From: doc Date: Mon, 30 Jun 2025 20:11:52 +0000 Subject: commit of legacy code --- upgrade.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 upgrade.sh (limited to 'upgrade.sh') diff --git a/upgrade.sh b/upgrade.sh new file mode 100755 index 0000000..58437b9 --- /dev/null +++ b/upgrade.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# ---- CONFIGURATION ---- +DOMAIN="your.mastodon.domain" # Replace this with your real domain +ACCOUNT_USERNAME="administration" +SCRIPT_PATH="/root/finish_upgrade.sh" +LOGFILE="/root/mastodon_upgrade_$(date +%F_%H-%M-%S).log" +exec > >(tee -a "$LOGFILE") 2>&1 +set -e + +echo "===== Mastodon 20.04 โ†’ 22.04 Upgrade Starter =====" + +read -p "โ— Have you backed up your system and database? (yes/no): " confirmed +if [[ "$confirmed" != "yes" ]]; then + echo "โŒ Aborting. Please take a backup." + exit 1 +fi + +echo "๐Ÿ”ง Updating system..." +apt update && apt upgrade -y +apt install update-manager-core curl -y + +echo "๐Ÿ›‘ Stopping Mastodon..." +systemctl stop mastodon-web mastodon-sidekiq mastodon-streaming + +echo "๐Ÿ” Preparing post-reboot upgrade finalization..." + +# ---- Create finish_upgrade.sh ---- +cat << EOF > $SCRIPT_PATH +#!/bin/bash +LOGFILE="/root/mastodon_post_upgrade_\$(date +%F_%H-%M-%S).log" +exec > >(tee -a "\$LOGFILE") 2>&1 +set -e + +echo "===== Post-Reboot Finalization Script =====" + +echo "๐Ÿ”„ Restarting Mastodon services..." +systemctl daemon-reexec +systemctl daemon-reload +systemctl start mastodon-web mastodon-sidekiq mastodon-streaming + +echo "โœ… Checking service status..." +systemctl status mastodon-web --no-pager +systemctl status mastodon-sidekiq --no-pager +systemctl status mastodon-streaming --no-pager + +echo "๐ŸŒ Homepage check..." +if curl --silent --fail https://$DOMAIN >/dev/null; then + echo "โœ… Homepage is reachable." +else + echo "โŒ Homepage failed to load." +fi + +echo "๐Ÿ“ฃ Posting announcement toot..." +cd /home/mastodon/live +sudo -u mastodon -H bash -c ' +RAILS_ENV=production bundle exec rails runner " +acct = Account.find_by(username: \\"$ACCOUNT_USERNAME\\") +if acct + PostStatusService.new.call(acct, text: \\"โœ… Server upgrade to Ubuntu 22.04 complete. We\\'re back online!\\") +end +"' + +echo "๐Ÿงน Cleaning up..." +apt autoremove -y && apt autoclean -y + +echo "๐Ÿšซ Removing rc.local to prevent rerun..." +rm -f /etc/rc.local +rm -f $SCRIPT_PATH + +echo "โœ… Post-upgrade steps complete." +EOF + +chmod +x $SCRIPT_PATH + +# ---- Set rc.local to run after reboot ---- +cat << EOF > /etc/rc.local +#!/bin/bash +bash $SCRIPT_PATH +exit 0 +EOF + +chmod +x /etc/rc.local + +echo "" +echo "๐Ÿš€ Starting do-release-upgrade..." +sleep 3 +do-release-upgrade -- cgit v1.2.3