2019-06-08 16:15:49 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# XXX: This should be removed when elixir's releases get custom command support
|
2019-06-19 13:53:16 +02:00
|
|
|
|
|
|
|
detect_flavour() {
|
2019-06-22 04:20:36 +02:00
|
|
|
arch="$(uname -m)"
|
2019-06-19 13:53:16 +02: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 17:47:53 +02: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 13:53:16 +02:00
|
|
|
if [ "$branch" = "develop" ]; then
|
|
|
|
echo "develop"
|
|
|
|
elif [ "$branch" = "" ]; then
|
2019-10-14 17:39:56 +02:00
|
|
|
echo "stable"
|
2019-06-19 13:53:16 +02:00
|
|
|
else
|
2019-10-11 12:56:45 +02: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 17:39:56 +02:00
|
|
|
echo "Can't detect the branch automatically, please specify it by using the --branch option." >&2
|
2019-06-19 13:53:16 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
update() {
|
|
|
|
set -e
|
2019-10-11 12:56:45 +02: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 13:53:16 +02:00
|
|
|
RELEASE_ROOT=$(dirname "$SCRIPTPATH")
|
2019-10-11 12:56:45 +02: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 13:53:16 +02:00
|
|
|
artifact="$tmp/pleroma.zip"
|
2019-10-11 12:56:45 +02:00
|
|
|
full_uri="${FULL_URI:-${uri}/api/v4/projects/${project_id}/jobs/artifacts/${project_branch}/download?job=${flavour}}"
|
2019-06-19 13:53:16 +02: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 12:56:45 +02:00
|
|
|
if [ "$NO_RM" = false ]; then
|
|
|
|
echo "Removing files from the previous release"
|
2019-06-19 13:53:16 +02: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 21:16:57 +02:00
|
|
|
if [ -z "$1" ] || [ "$1" = "help" ]; then
|
2019-06-19 13:53:16 +02: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 23:17:47 +02:00
|
|
|
echo "Usage: $(basename "$0") COMMAND [ARGS]
|
2019-06-09 12:33:44 +02:00
|
|
|
|
|
|
|
The known commands are:
|
|
|
|
|
2019-06-19 13:53:16 +02: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 12:56:45 +02:00
|
|
|
Update the instance.
|
2019-06-19 13:53:16 +02:00
|
|
|
|
2019-10-11 12:56:45 +02: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 12:33:44 +02:00
|
|
|
|
|
|
|
and any mix tasks under Pleroma namespace, for example \`mix pleroma.user COMMAND\` is
|
2019-06-10 13:47:22 +02:00
|
|
|
equivalent to \`$(basename "$0") user COMMAND\`
|
2019-06-17 23:17:47 +02:00
|
|
|
|
|
|
|
By default pleroma_ctl will try calling into a running instance to execute non migration-related commands,
|
2019-10-11 12:56:45 +02:00
|
|
|
if for some reason this is undesired, set PLEROMA_CTL_RPC_DISABLED environment variable.
|
|
|
|
|
2019-06-09 12:33:44 +02:00
|
|
|
"
|
|
|
|
else
|
2019-06-17 23:17:47 +02:00
|
|
|
SCRIPT=$(readlink -f "$0")
|
|
|
|
SCRIPTPATH=$(dirname "$SCRIPT")
|
2019-06-19 13:53:16 +02:00
|
|
|
|
2019-10-11 12:56:45 +02:00
|
|
|
FULL_ARGS="$*"
|
|
|
|
|
|
|
|
ACTION="$1"
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [ "$(echo \"$1\" | grep \"^-\" >/dev/null)" = false ]; then
|
|
|
|
SUBACTION="$1"
|
|
|
|
shift
|
|
|
|
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 23:17:47 +02:00
|
|
|
else
|
2019-10-11 12:56:45 +02:00
|
|
|
"$SCRIPTPATH"/pleroma rpc 'Pleroma.ReleaseTasks.run("'"$FULL_ARGS"'")'
|
2019-06-17 23:17:47 +02:00
|
|
|
fi
|
2019-06-09 12:33:44 +02:00
|
|
|
fi
|