Safe Automated Update
Added detection of next available version (as opposed to just latest) Automatic incremental updates with `tpc update next`.
This commit is contained in:
parent
eeecd047e0
commit
4491ff50ba
108
_bin/checkver.sh
108
_bin/checkver.sh
|
@ -1,6 +1,8 @@
|
||||||
#! /usr/bin/env bash
|
#! /usr/bin/env bash
|
||||||
SCRIPT_DIR=${SCRIPT_DIR:-"$( cd -- "$( dirname -- "$0" )" &> /dev/null && pwd )"}
|
SCRIPT_DIR=${SCRIPT_DIR:-"$( cd -- "$( dirname -- "$0" )" &> /dev/null && pwd )"}
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
# Function to compare semantic versions
|
# Function to compare semantic versions
|
||||||
compare_major_version() {
|
compare_major_version() {
|
||||||
local major_version1=$(echo $1 | cut -d. -f1)
|
local major_version1=$(echo $1 | cut -d. -f1)
|
||||||
|
@ -12,38 +14,86 @@ compare_major_version() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if [[ "${1}" =~ ^(-h|--help$) ]]; then
|
||||||
|
printf '%s\n' \
|
||||||
|
"Query runtipi's current version and compares with what is available online" \
|
||||||
|
"" \
|
||||||
|
"Usage:" \
|
||||||
|
" ${0##*/} -h | --help | [next] [<version>] " \
|
||||||
|
"" \
|
||||||
|
"Arguments:" \
|
||||||
|
" -h | --help Display usage" \
|
||||||
|
" version [optional] assume current version - auto-detected when ommitted" \
|
||||||
|
" next Show the next version (to current-version, see above)" \
|
||||||
|
"" \
|
||||||
|
"Exit codes:" \
|
||||||
|
" 0 (ok) if (next) and on the latest version" \
|
||||||
|
" if (next) and next version exist and is not a major version change" \
|
||||||
|
" or when listing versions (not 'next')" \
|
||||||
|
"" \
|
||||||
|
" 1 non operational (like --help)" \
|
||||||
|
" major versions do not match"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Get Current Version of Runtipi
|
# Get Current Version of Runtipi
|
||||||
runtipi_path=${RUNTIPI_DIR:-"$(cd -- "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"}
|
runtipi_path=${RUNTIPI_DIR:-"$(cd -- "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"}
|
||||||
[ -r "$runtipi_path/VERSION" ] || runtipi_path=${RUNTIPI_DIR:-"$(cd -- "${SCRIPT_DIR}/../../_" &> /dev/null && pwd )"}
|
current_version="$1"
|
||||||
current_version=$(cat "$runtipi_path/VERSION")
|
if [ "$current_version" == "next" ]; then
|
||||||
|
current_version="$2"
|
||||||
|
next_version_only=1
|
||||||
|
fi
|
||||||
|
if [ -z "$current_version" ]; then
|
||||||
|
[ -r "$runtipi_path/VERSION" ] || runtipi_path=${RUNTIPI_DIR:-"$(cd -- "${SCRIPT_DIR}/../../_" &> /dev/null && pwd )"}
|
||||||
|
current_version=$(cat "$runtipi_path/VERSION")
|
||||||
|
fi
|
||||||
|
|
||||||
# Get the latest release information from GitHub API
|
# Get the latest release information from GitHub API
|
||||||
latest_release=$(curl -sL \
|
latest_releases_page=1
|
||||||
-H "Accept: application/vnd.github+json" \
|
latest_releases=""
|
||||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
while [ $latest_releases_page -lt ${RELEASE_PAGE_LIMIT:-4} ]; do
|
||||||
https://api.github.com/repos/runtipi/runtipi/releases/latest)
|
tmp_releases="$(curl -sL \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
https://api.github.com/repos/runtipi/runtipi/releases\?page=${latest_releases_page} \
|
||||||
|
| grep -o '"tag_name": "[^"]*' | cut -d'"' -f4 | grep -E '^v[[:digit:]\.]+$' \
|
||||||
|
)" || break
|
||||||
|
|
||||||
|
[ -z "$tmp_releases" ] \
|
||||||
|
&& tmp_releases="EMPTY" && break \
|
||||||
|
|| true
|
||||||
|
|
||||||
|
latest_releases="$(printf '%s\n' ${latest_releases} ${tmp_releases})"
|
||||||
|
|
||||||
|
grep -q "^${current_version}$" <<<"${tmp_releases}" \
|
||||||
|
&& tmp_releases="" && break \
|
||||||
|
|| (( latest_releases_page+=1 ))
|
||||||
|
done
|
||||||
|
[ -n "$tmp_releases" ] \
|
||||||
|
&& next_version_only="" && current_version="${current_version} # !not-online!" \
|
||||||
|
|| tmp_releases=""
|
||||||
|
|
||||||
|
# List everything up to latest version (excluding the latest version)
|
||||||
|
latest_releases="$( <<<"${latest_releases}" sed -n '
|
||||||
|
0,/^'"${current_version//\./\\.}"'$/p
|
||||||
|
' | tac
|
||||||
|
)"
|
||||||
|
|
||||||
|
next_tag="$( head -n2 <<<"${latest_releases:-${current_version}}" | tail -n1 )"
|
||||||
|
latest_tag="$( tail -n1 <<<"${latest_releases:-${current_version}}")"
|
||||||
|
|
||||||
# Extract the tag name from the release information
|
if [ "$next_version_only" != "1" ]; then
|
||||||
tag_name=$(echo "$latest_release" | grep -o '"tag_name": "[^"]*' | cut -d'"' -f4)
|
printf 'current:\n %-10s\nonline:\n' "$current_version" >&2
|
||||||
|
[ ${#latest_releases} -eq 0 ] || printf ' %-10s\n' ${latest_releases} >&2
|
||||||
printf 'current: %-10s online: %-10s\n' "$current_version" "$tag_name" >&2
|
# Compare major version numbers
|
||||||
# Compare major version numbers
|
compare_major_version "$latest_tag" "$current_version"
|
||||||
compare_major_version "$tag_name" "$current_version"
|
elif [ "$next_tag" == "$current_version" ]; then
|
||||||
# major_version_match=$?
|
printf "on the latest version\n"
|
||||||
#
|
#printf "%s\n" "$current_version" >&2
|
||||||
# # Check if major versions are the same and if the latest release is newer than the current version
|
elif [ "$next_tag" != "$current_version" ]; then
|
||||||
# if [[ $major_version_match -eq 0 ]] && [[ "$tag_name" > "$current_version" ]]; then
|
printf "%s\n" "$next_tag"
|
||||||
# echo "A new release is available: $tag_name"
|
# Compare major version numbers
|
||||||
# cd $runtipi_path
|
compare_major_version "$next_tag" "$current_version"
|
||||||
# echo "Backing up current version"
|
fi
|
||||||
# if [ ! -d "$runtipi_path/backups" ]; then
|
|
||||||
# mkdir -p $runtipi_path/backups
|
|
||||||
# fi
|
|
||||||
# tar -czvf runtipi-backup-$current_version.tar.gz --exclude=media --exclude=backups *
|
|
||||||
# mv runtipi-backup-$current_version.tar.gz $runtipi_path/backups
|
|
||||||
# echo "Starting update"
|
|
||||||
# echo $runtipi_path/runtipi-cli update latest
|
|
||||||
# else
|
|
||||||
# echo "No new release found or major version mismatch"
|
|
||||||
# fi
|
|
||||||
|
|
|
@ -292,10 +292,30 @@ case "${1}" in
|
||||||
runtipi-cli start --env-file user-config/.env.local ${2:---no-permissions}
|
runtipi-cli start --env-file user-config/.env.local ${2:---no-permissions}
|
||||||
;;
|
;;
|
||||||
update)
|
update)
|
||||||
if [ -z "${2}" ]; then
|
if [[ "$2" =~ ^(-h|--help$|help$) ]]; then
|
||||||
${SCRIPT_DIR}/checkver.sh
|
printf '%s %-12s %s\n' \
|
||||||
|
"Query if upgrade is available, or perform auto update" "" "" \
|
||||||
|
"" "" "" \
|
||||||
|
"Usage:" "" ""\
|
||||||
|
" ${BASE_NAME} update -h | --help | [ -- [<args>] | [next] [version] ] " "" ""\
|
||||||
|
"" "" "" \
|
||||||
|
"Arguments:" "" ""\
|
||||||
|
"" "-h | --help" "Display usage" \
|
||||||
|
"" "" "" \
|
||||||
|
"" "-- [<args>]" "invoke checkver.sh with [optional] <args>" \
|
||||||
|
"" "version" "specify specific version" \
|
||||||
|
"" "next" "detect next version (version will assume current-version instead of detecting)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ -z "${2}" ] || [ "${2}" == '--' ]; then
|
||||||
|
${SCRIPT_DIR}/checkver.sh "${@:3}"
|
||||||
else
|
else
|
||||||
runtipi-cli update --env-file user-config/.env.local --no-permissions "${2:?Must supply version}" "${@:3}"
|
update_to="${2:?Must supply version}"
|
||||||
|
[ "${update_to}" != "auto" ] && [ "${update_to}" != "next" ] \
|
||||||
|
|| update_to=$(${SCRIPT_DIR}/checkver.sh next "${3}") || update_to=""
|
||||||
|
[ "${update_to}" == "on the latest version" ] && exit 0
|
||||||
|
[ -n "${update_to}" ] \
|
||||||
|
&& runtipi-cli update --env-file user-config/.env.local --no-permissions "${update_to}" "${@:4}"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
dls)
|
dls)
|
||||||
|
@ -319,8 +339,8 @@ case "${1}" in
|
||||||
setup)
|
setup)
|
||||||
ln -s $2 "$(cd -- "${SCRIPT_DIR}" && pwd)/${BASE_NAME}" "${3:-$HOME/.local/bin/}"
|
ln -s $2 "$(cd -- "${SCRIPT_DIR}" && pwd)/${BASE_NAME}" "${3:-$HOME/.local/bin/}"
|
||||||
;;
|
;;
|
||||||
edit)
|
editme)
|
||||||
${VISUAL:-${EDITOR:-vi}} $0
|
${VISUAL:-${EDITOR:-vi}} "$(readlink -f "$0")"
|
||||||
;;
|
;;
|
||||||
_load)
|
_load)
|
||||||
echo "alias ${BASE_NAME}cd='cd \"$SCRIPT_DIR/..\"'"
|
echo "alias ${BASE_NAME}cd='cd \"$SCRIPT_DIR/..\"'"
|
||||||
|
|
Loading…
Reference in New Issue