2019-06-08 14:15:49 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# XXX: This should be removed when elixir's releases get custom command support
|
2019-06-19 11:53:16 +00:00
|
|
|
|
|
|
|
detect_flavour() {
|
2019-06-22 02:20:36 +00:00
|
|
|
arch="$(uname -m)"
|
2019-06-19 11:53:16 +00:00
|
|
|
if [ "$arch" = "x86_64" ]; then
|
|
|
|
arch="amd64"
|
|
|
|
elif [ "$arch" = "armv7l" ]; then
|
|
|
|
arch="arm"
|
|
|
|
elif [ "$arch" = "aarch64" ]; then
|
|
|
|
arch="arm64"
|
|
|
|
else
|
|
|
|
echo "Unsupported arch: $arch" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if getconf GNU_LIBC_VERSION >/dev/null; then
|
|
|
|
libc_postfix=""
|
|
|
|
elif [ "$(ldd 2>&1 | head -c 9)" = "musl libc" ]; then
|
|
|
|
libc_postfix="-musl"
|
|
|
|
elif [ "$(find /lib/libc.musl* | wc -l)" ]; then
|
|
|
|
libc_postfix="-musl"
|
|
|
|
else
|
|
|
|
echo "Unsupported libc" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$arch$libc_postfix"
|
|
|
|
}
|
|
|
|
|
|
|
|
detect_branch() {
|
|
|
|
version="$(cut -d' ' -f2 <"$RELEASE_ROOT"/releases/start_erl.data)"
|
2019-07-02 15:47:53 +00:00
|
|
|
# Expected format: major.minor.patch_version(-number_of_commits_ahead_of_tag-gcommit_hash).branch
|
|
|
|
branch="$(echo "$version" | cut -d'.' -f 4)"
|
2019-06-19 11:53:16 +00:00
|
|
|
if [ "$branch" = "develop" ]; then
|
|
|
|
echo "develop"
|
|
|
|
elif [ "$branch" = "" ]; then
|
2019-10-14 15:39:56 +00:00
|
|
|
echo "stable"
|
2019-06-19 11:53:16 +00:00
|
|
|
else
|
2019-10-11 10:22:21 +00:00
|
|
|
# Note: branch name in version is of SemVer format and may only contain [0-9a-zA-Z-] symbols —
|
|
|
|
# if supporting releases for more branches, need to ensure they contain only these symbols.
|
2019-10-14 15:39:56 +00:00
|
|
|
echo "Can't detect the branch automatically, please specify it by using the --branch option." >&2
|
2019-06-19 11:53:16 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
update() {
|
|
|
|
set -e
|
2019-10-11 10:22:21 +00:00
|
|
|
NO_RM=false
|
|
|
|
|
|
|
|
while echo "$1" | grep "^-" >/dev/null; do
|
|
|
|
case "$1" in
|
|
|
|
--zip-url)
|
|
|
|
FULL_URI="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--no-rm)
|
|
|
|
NO_RM=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--flavour)
|
|
|
|
FLAVOUR="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--branch)
|
|
|
|
BRANCH="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--tmp-dir)
|
|
|
|
TMP_DIR="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
echo "invalid option: $1" 1>&2
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-06-19 11:53:16 +00:00
|
|
|
RELEASE_ROOT=$(dirname "$SCRIPTPATH")
|
2019-10-11 10:22:21 +00:00
|
|
|
uri="https://git.pleroma.social"
|
|
|
|
project_id="2"
|
|
|
|
project_branch="${BRANCH:-$(detect_branch)}"
|
|
|
|
flavour="${FLAVOUR:-$(detect_flavour)}"
|
|
|
|
tmp="${TMP_DIR:-/tmp}"
|
2019-06-19 11:53:16 +00:00
|
|
|
artifact="$tmp/pleroma.zip"
|
2019-10-11 10:22:21 +00:00
|
|
|
full_uri="${FULL_URI:-${uri}/api/v4/projects/${project_id}/jobs/artifacts/${project_branch}/download?job=${flavour}}"
|
2019-06-19 11:53:16 +00:00
|
|
|
echo "Downloading the artifact from ${full_uri} to ${artifact}"
|
|
|
|
curl "$full_uri" -o "${artifact}"
|
|
|
|
echo "Unpacking ${artifact} to ${tmp}"
|
|
|
|
unzip -q "$artifact" -d "$tmp"
|
|
|
|
echo "Copying files over to $RELEASE_ROOT"
|
2019-10-11 10:22:21 +00:00
|
|
|
if [ "$NO_RM" = false ]; then
|
|
|
|
echo "Removing files from the previous release"
|
2019-06-19 11:53:16 +00:00
|
|
|
rm -r "${RELEASE_ROOT:-?}"/*
|
|
|
|
fi
|
|
|
|
cp -rf "$tmp/release"/* "$RELEASE_ROOT"
|
|
|
|
echo "Removing temporary files"
|
|
|
|
rm -r "$tmp/release"
|
|
|
|
rm "$artifact"
|
|
|
|
echo "Done! Please refer to the changelog/release notes for changes and update instructions"
|
|
|
|
set +e
|
|
|
|
}
|
|
|
|
|
2019-06-13 19:16:57 +00:00
|
|
|
if [ -z "$1" ] || [ "$1" = "help" ]; then
|
2019-06-19 11:53:16 +00:00
|
|
|
# TODO: Just list the commands on `pleroma_ctl help` and output help for the individual command on `pleroma_ctl help $COMMAND`
|
2019-06-17 21:17:47 +00:00
|
|
|
echo "Usage: $(basename "$0") COMMAND [ARGS]
|
2019-06-09 10:33:44 +00:00
|
|
|
|
|
|
|
The known commands are:
|
|
|
|
|
2019-06-19 11:53:16 +00:00
|
|
|
create
|
|
|
|
Create database schema (needs to be executed only once)
|
|
|
|
|
|
|
|
migrate
|
|
|
|
Execute database migrations (needs to be done after updates)
|
|
|
|
|
|
|
|
rollback [VERSION]
|
|
|
|
Rollback database migrations (needs to be done before downgrading)
|
|
|
|
|
|
|
|
update [OPTIONS]
|
2019-10-11 10:22:21 +00:00
|
|
|
Update the instance.
|
2019-06-19 11:53:16 +00:00
|
|
|
|
2019-10-11 10:22:21 +00:00
|
|
|
Options:
|
|
|
|
--branch Update to a specified branch, instead of the latest version of the current one.
|
|
|
|
--flavour Update to a specified flavour (CPU architecture+libc), instead of the current one.
|
|
|
|
--zip-url Get the release from a specified url. If set, renders the previous 2 options inactive.
|
|
|
|
--no-rm Do not erase previous release's files.
|
|
|
|
--tmp-dir Download the temporary files to a specified directory.
|
2019-06-09 10:33:44 +00:00
|
|
|
|
|
|
|
and any mix tasks under Pleroma namespace, for example \`mix pleroma.user COMMAND\` is
|
2019-06-10 11:47:22 +00:00
|
|
|
equivalent to \`$(basename "$0") user COMMAND\`
|
2019-06-17 21:17:47 +00:00
|
|
|
|
|
|
|
By default pleroma_ctl will try calling into a running instance to execute non migration-related commands,
|
2019-10-11 10:22:21 +00:00
|
|
|
if for some reason this is undesired, set PLEROMA_CTL_RPC_DISABLED environment variable.
|
|
|
|
|
2019-06-09 10:33:44 +00:00
|
|
|
"
|
|
|
|
else
|
2024-05-22 22:35:38 +00:00
|
|
|
SCRIPT=$(realpath "$0")
|
2019-06-17 21:17:47 +00:00
|
|
|
SCRIPTPATH=$(dirname "$SCRIPT")
|
2019-06-19 11:53:16 +00:00
|
|
|
|
2019-10-11 10:22:21 +00:00
|
|
|
FULL_ARGS="$*"
|
|
|
|
|
|
|
|
ACTION="$1"
|
2019-10-24 20:28:59 +00:00
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
echo "$1" | grep "^-" >/dev/null
|
2019-10-18 21:37:39 +00:00
|
|
|
if [ $? -eq 1 ]; then
|
2019-10-11 10:22:21 +00:00
|
|
|
SUBACTION="$1"
|
2019-10-24 20:28:59 +00:00
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
shift
|
|
|
|
fi
|
2019-10-11 10:22:21 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$ACTION" = "update" ]; then
|
|
|
|
update "$@"
|
|
|
|
elif [ "$ACTION" = "migrate" ] || [ "$ACTION" = "rollback" ] || [ "$ACTION" = "create" ] || [ "$ACTION $SUBACTION" = "instance gen" ] || [ "$PLEROMA_CTL_RPC_DISABLED" = true ]; then
|
|
|
|
"$SCRIPTPATH"/pleroma eval 'Pleroma.ReleaseTasks.run("'"$FULL_ARGS"'")'
|
2019-06-17 21:17:47 +00:00
|
|
|
else
|
2019-10-11 10:22:21 +00:00
|
|
|
"$SCRIPTPATH"/pleroma rpc 'Pleroma.ReleaseTasks.run("'"$FULL_ARGS"'")'
|
2019-06-17 21:17:47 +00:00
|
|
|
fi
|
2019-06-09 10:33:44 +00:00
|
|
|
fi
|