Add options to reinstall and skip backup

This commit is contained in:
Antonio J. Delgado 2024-02-16 18:29:46 +02:00
parent 0d1e12c6c9
commit d841795ff0

View file

@ -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 <TAG> Release tag or 'latest' (default)."
echo " -T|--token <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,6 +115,7 @@ if [ "${current_tag}" != "${tag}" ]; then
else
sudo -u mastodon git checkout "${tag}"
fi
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"
@ -114,6 +127,7 @@ if [ "${current_tag}" != "${tag}" ]; then
fi
sudo -u postgres pg_dump mastodon | gzip -c > "${backup_file}"
fi
fi
if [ "${DEBUG}" == "true" ]; then
echo "Running bundle install..."
fi