summaryrefslogtreecommitdiff
path: root/upgrade.sh
diff options
context:
space:
mode:
authordoc <doc@filenotfound.org>2025-06-30 20:11:52 +0000
committerdoc <doc@filenotfound.org>2025-06-30 20:11:52 +0000
commit41e897f4945aaf8fbcdf0b12ac2f08c5e6ae0458 (patch)
treedb7c3520fd91abc3cf56b1a52095d23f3a80d059 /upgrade.sh
commit of legacy codeHEADmaster
Diffstat (limited to 'upgrade.sh')
-rwxr-xr-xupgrade.sh88
1 files changed, 88 insertions, 0 deletions
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