From 4bcc226c4bf81982d2f2c65711a1fe82de236729 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Fri, 16 Feb 2024 15:19:29 +0200 Subject: [PATCH] Add debug --- files/update_mastodon.sh | 43 +++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/files/update_mastodon.sh b/files/update_mastodon.sh index 81d0bc5..d9b1b20 100755 --- a/files/update_mastodon.sh +++ b/files/update_mastodon.sh @@ -53,6 +53,9 @@ if [ -z "${token}" ]; then fi if [ "${tag}" == "latest" ]; then tag=$(curl -L -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${token}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/mastodon/mastodon/releases/latest | jq '.tag_name') + if [ "${DEBUG}" == "true" ]; then + echo "Latest tag is '${tag}'" + fi else if [ "${DEBUG}" == "true" ]; then echo "Looking for tag '${tag}'..." @@ -67,13 +70,13 @@ else next_page=$(grep '< link: ' "${tmpfile}" | sed 's/< link: //g' | sed 's/, /\n/g' | grep 'rel="next"' | grep -o 'https://[^>]*') done if ! pgrep "${tag}" "${releases_file}"; then - echo "The tag '%s' is not part of the releases:\n%s" "${tag}" "${releases}" + printf "The tag '%s' is not part of the releases:\n%s" "${tag}" "${releases}" exit 1 fi fi if [ "${dummy}" == "true" ]; then - pre_command="echo" + pre_command="echo " else pre_command="" fi @@ -84,16 +87,38 @@ if [ ! -d "${mastodon_home}" ]; then exit 2 fi +if [ "${DEBUG}" == "true" ]; then + echo "Changing to Mastodon's home directory '${mastodon_home}'..." +fi cd "${mastodon_home}" || exit 3 -"${pre_command}" sudo -u mastodon git fetch -"${pre_command}" sudo -u mastodon git checkout "${tag}" +if [ "${DEBUG}" == "true" ]; then + echo "Fetching from repository..." +fi +"${pre_command}"sudo -u mastodon git fetch +if [ "${DEBUG}" == "true" ]; then + echo "Changing to reference '${tag}'..." +fi +"${pre_command}"sudo -u mastodon git checkout "${tag}" 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 > \"/var/backups/postgres/pgdump_pre_update_mastodon_to_${tag}_${current_date}.sql.gz\"" + echo "sudo -u postgres pg_dump mastodon | gzip -c > \"${backup_file}\"" else - sudo -u postgres pg_dump mastodon | gzip -c > "/var/backups/postgres/pgdump_pre_update_mastodon_to_${tag}_${current_date}.sql.gz" + 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 -"${pre_command}" sudo -u mastodon bundle install -"${pre_command}" sudo -u mastodon yarn install --frozen-lockfile -"${pre_command}" sudo systemctl restart mastodon-sidekiq.service mastodon-web.service mastodon-streaming mastodon-streaming@4000.service +if [ "${DEBUG}" == "true" ]; then + echo "Running bundle install..." +fi +"${pre_command}"sudo -u mastodon bundle install +if [ "${DEBUG}" == "true" ]; then + echo "Running yarm install..." +fi +"${pre_command}"sudo -u mastodon yarn install --frozen-lockfile +if [ "${DEBUG}" == "true" ]; then + echo "Restarting Mastodon services..." +fi +"${pre_command}"sudo systemctl restart mastodon-sidekiq.service mastodon-web.service mastodon-streaming mastodon-streaming@4000.service