Updated the update system to support multi channels (stable / pre-release).
This commit is contained in:
29
install.sh
29
install.sh
@@ -3,11 +3,12 @@
|
||||
set -euo pipefail
|
||||
|
||||
SOURCE_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SOURCE_VERSION="$(sed -n 's/^__version__ = "\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)"$/\1/p' "${SOURCE_ROOT}/ptlinux/__init__.py")"
|
||||
SEMVER_PATTERN='(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(beta|rc)\.(0|[1-9][0-9]*))?'
|
||||
SOURCE_VERSION="$(sed -n 's/^__version__ = "\([^"]*\)"$/\1/p' "${SOURCE_ROOT}/ptlinux/__init__.py")"
|
||||
VERSION="${PTLINUX_VERSION:-$SOURCE_VERSION}"
|
||||
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
|
||||
if [[ ! "$VERSION" =~ ^${SEMVER_PATTERN}$ ]]
|
||||
then
|
||||
printf 'Invalid launcher version: %s (expected X.Y.Z)\n' "$VERSION" >&2
|
||||
printf 'Invalid launcher version: %s (expected X.Y.Z, X.Y.Z-beta.N, or X.Y.Z-rc.N)\n' "$VERSION" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ "$VERSION" != "$SOURCE_VERSION" ]]
|
||||
@@ -15,6 +16,14 @@ then
|
||||
printf 'Launcher version %s does not match source version %s.\n' "$VERSION" "$SOURCE_VERSION" >&2
|
||||
exit 2
|
||||
fi
|
||||
case "$VERSION" in
|
||||
*-beta.*|*-rc.*)
|
||||
RELEASE_CHANNEL="prerelease"
|
||||
;;
|
||||
*)
|
||||
RELEASE_CHANNEL="stable"
|
||||
;;
|
||||
esac
|
||||
DATA_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}"
|
||||
BIN_HOME="${HOME}/.local/bin"
|
||||
APPLICATION_HOME="${DATA_HOME}/applications"
|
||||
@@ -212,6 +221,13 @@ then
|
||||
printf '%s\n' "Python 3.11 or newer is required." >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! "$PYTHON_BIN" -I -B -c \
|
||||
'import sys; sys.path.insert(0, sys.argv[1]); from ptlinux.update_resolver import validate_channel_version; validate_channel_version(sys.argv[2], sys.argv[3])' \
|
||||
"$SOURCE_ROOT" "$RELEASE_CHANNEL" "$VERSION"
|
||||
then
|
||||
printf '%s\n' "Launcher version and release channel validation failed." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
install -d -m 0755 "$APP_ROOT" "$RELEASES_ROOT" "$BIN_HOME" "$APPLICATION_HOME" "$PIXMAP_HOME"
|
||||
STAGING_RELEASE="${RELEASES_ROOT}/.${VERSION}.$$.staging"
|
||||
@@ -260,7 +276,8 @@ install -m 0644 \
|
||||
install -m 0644 "${SOURCE_ROOT}/ptdiag/__init__.py" "${STAGING_RELEASE}/ptdiag/__init__.py"
|
||||
install -m 0644 "${SOURCE_ROOT}/ptdiag/assbin.py" "${STAGING_RELEASE}/ptdiag/assbin.py"
|
||||
install -m 0644 "${SOURCE_ROOT}/ptdiag/logs.py" "${STAGING_RELEASE}/ptdiag/logs.py"
|
||||
printf '{\n "schema": 1,\n "version": "%s"\n}\n' "$VERSION" > "${STAGING_RELEASE}/release.json"
|
||||
printf '{\n "channel": "%s",\n "config_schema": 1,\n "minimum_config_schema": 1,\n "schema": 1,\n "tag": "v%s",\n "version": "%s"\n}\n' \
|
||||
"$RELEASE_CHANNEL" "$VERSION" "$VERSION" > "${STAGING_RELEASE}/release.json"
|
||||
chmod 0644 "${STAGING_RELEASE}/release.json"
|
||||
|
||||
if ! "$PYTHON_BIN" -I -B -c \
|
||||
@@ -301,7 +318,7 @@ CURRENT_TARGET=""
|
||||
if [[ -L "${APP_ROOT}/current" ]]
|
||||
then
|
||||
CURRENT_TARGET="$(readlink -- "${APP_ROOT}/current")"
|
||||
if [[ ! "$CURRENT_TARGET" =~ ^releases/[0-9]+\.[0-9]+\.[0-9]+$ ]]
|
||||
if [[ ! "$CURRENT_TARGET" =~ ^releases/${SEMVER_PATTERN}$ ]]
|
||||
then
|
||||
printf 'Existing launcher current link is unsafe: %s\n' "$CURRENT_TARGET" >&2
|
||||
exit 1
|
||||
@@ -319,7 +336,7 @@ fi
|
||||
if [[ -L "${APP_ROOT}/previous" ]]
|
||||
then
|
||||
PREVIOUS_TARGET="$(readlink -- "${APP_ROOT}/previous")"
|
||||
if [[ ! "$PREVIOUS_TARGET" =~ ^releases/[0-9]+\.[0-9]+\.[0-9]+$ \
|
||||
if [[ ! "$PREVIOUS_TARGET" =~ ^releases/${SEMVER_PATTERN}$ \
|
||||
|| ! -d "${APP_ROOT}/${PREVIOUS_TARGET}" ]]
|
||||
then
|
||||
printf 'Existing launcher previous link is unsafe or broken: %s\n' "$PREVIOUS_TARGET" >&2
|
||||
|
||||
Reference in New Issue
Block a user