diff --git a/files/update_mastodon.sh b/files/update_mastodon.sh index 4568f96..4b7bd79 100755 --- a/files/update_mastodon.sh +++ b/files/update_mastodon.sh @@ -91,34 +91,40 @@ if [ "${DEBUG}" == "true" ]; then echo "Changing to Mastodon's home directory '${mastodon_home}'..." fi cd "${mastodon_home}" || exit 3 -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 > \"${backup_file}\"" -else +current_tag=$(git name-rev --name-only HEAD | awk 'BEGIN {FS="/"} {print($2)}') +if [ "${current_tag}" != "${tag}" ]; then if [ "${DEBUG}" == "true" ]; then - echo "Creating a backup of the database in '${backup_file}'..." + echo "Fetching from repository..." fi - sudo -u postgres pg_dump mastodon | gzip -c > "${backup_file}" + "${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 > \"${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 + 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 +else + echo "Current branch is already '${tag}'" + exit 0 fi -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