From d841795ff0179f45118b498d7eb96b5adac68cbc Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Fri, 16 Feb 2024 18:29:46 +0200 Subject: [PATCH] Add options to reinstall and skip backup --- files/update_mastodon.sh | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/files/update_mastodon.sh b/files/update_mastodon.sh index dba5058..936c7b8 100755 --- a/files/update_mastodon.sh +++ b/files/update_mastodon.sh @@ -2,6 +2,8 @@ set -euo pipefail tag=latest dummy=false +no_backup=false +reinstall=false token="" function usage() { @@ -12,6 +14,8 @@ function usage() { echo " -t|--tag Release tag or 'latest' (default)." echo " -T|--token Github token with read access to public repositories." echo " -D|--dummy|--dry-run Run in Dry-mode without actually updating but showing the commands to execute." + echo " -r|--reinstall Allow to reinstall the same tag." + echo " -n|--no-backup Don't do a backup of the database before the upgrade." } while [ $# -gt 0 ] @@ -40,6 +44,14 @@ do shift dummy=true ;; + '-n'|'--no-backup') + shift + no_backup=true + ;; + '-r'|'--reinstall') + shift + reinstall=true + ;; *) message "Unknown parameter '$1'" p shift @@ -86,7 +98,7 @@ if [ "${DEBUG}" == "true" ]; then fi cd "${mastodon_home}/live" || exit 3 current_tag=$(git name-rev --name-only HEAD | awk 'BEGIN {FS="/"} {print($2)}') -if [ "${current_tag}" != "${tag}" ]; then +if [ "${current_tag}" != "${tag}" ] || [ "${reinstall}" ]; then if [ "${DEBUG}" == "true" ]; then echo "Fetching from repository..." fi @@ -103,16 +115,18 @@ if [ "${current_tag}" != "${tag}" ]; then else sudo -u mastodon git checkout "${tag}" fi - current_date=$(date +%Y-%m-%d-%H-%M-%S) - mkdir -p /var/backups/postgres - backup_file="/var/backups/postgres/pgdump_pre_update_mastodon_to_${tag}_${current_date}.sql.gz" - if [ "${dummy}" == "true" ]; then - echo "sudo -u postgres pg_dump mastodon | gzip -c > \"${backup_file}\"" - else - if [ "${DEBUG}" == "true" ]; then - echo "Creating a backup of the database in '${backup_file}'..." + if [ "${no_backup}" == "false" ]; then + current_date=$(date +%Y-%m-%d-%H-%M-%S) + mkdir -p /var/backups/postgres + backup_file="/var/backups/postgres/pgdump_pre_update_mastodon_to_${tag}_${current_date}.sql.gz" + if [ "${dummy}" == "true" ]; then + echo "sudo -u postgres pg_dump mastodon | gzip -c > \"${backup_file}\"" + else + if [ "${DEBUG}" == "true" ]; then + echo "Creating a backup of the database in '${backup_file}'..." + fi + sudo -u postgres pg_dump mastodon | gzip -c > "${backup_file}" fi - sudo -u postgres pg_dump mastodon | gzip -c > "${backup_file}" fi if [ "${DEBUG}" == "true" ]; then echo "Running bundle install..."