79 lines
2.5 KiB
Bash
Executable file
79 lines
2.5 KiB
Bash
Executable file
#!/bin/bash
|
|
set -euo pipefail
|
|
tag=latest
|
|
dummy=false
|
|
token=""
|
|
|
|
function usage() {
|
|
echo "Usage:"
|
|
echo "$(basename "${0}") [-t|--tag <TAG>] [-T|--token <GITHUB_TOKEN>] [-d|--debug]"
|
|
echo ""
|
|
echo " -d|--debug Show more debug information."
|
|
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."
|
|
}
|
|
|
|
while [ $# -gt 0 ]
|
|
do
|
|
case "${1}" in
|
|
"-h"|"-?"|"--help")
|
|
shift
|
|
usage
|
|
exit 0
|
|
;;
|
|
"-d"|"--debug")
|
|
shift
|
|
export DEBUG=true
|
|
;;
|
|
"-t"|"--tag")
|
|
shift
|
|
tag="${1}"
|
|
shift
|
|
;;
|
|
"-T"|"--token")
|
|
shift
|
|
token="${1}"
|
|
shift
|
|
;;
|
|
'-D'|'--dummy'|'--dry-run')
|
|
shift
|
|
dummy=true
|
|
;;
|
|
*)
|
|
message "Unknown parameter '$1'" p
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
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')
|
|
else
|
|
releases=$(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 | jq '.[]|.tag_name')
|
|
if ! echo "${releases}" | pgrep "${tag}"; then
|
|
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"
|
|
else
|
|
pre_command=""
|
|
fi
|
|
|
|
mastodon_home=$(grep "^mastodon:" /etc/passwd | awk 'BEGIN {FS=":"} {print($7)}')
|
|
if [ ! -d "${mastodon_home}" ]; then
|
|
printf "The home for the user mastodon '%s', doesn't exist." "${mastodon_home}"
|
|
exit 2
|
|
fi
|
|
|
|
cd "${mastodon_home}" || exit 3
|
|
"${pre_command}" sudo -u mastodon git fetch
|
|
"${pre_command}" sudo -u mastodon git checkout "${tag}"
|
|
current_date=$(date +%Y-%m-%d-%H-%M-%S)
|
|
"${pre_command}" sudo -u postgres pg_dump mastodon > "/var/backup/pgdump_pre_update_mastodon_to_${tag}_${current_date}.sql"
|
|
"${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
|