#!/bin/sh set -eu cd "$(dirname "$0")/.." php_bin=${LAYSITE_PHP:-php} composer_bin=${LAYSITE_COMPOSER:-composer} target=${1:-check} if [ "$target" = check ]; then git fetch origin --tags git describe --tags --always git tag --list 'v[0-9]*' --sort=-version:refname | awk '/^v[0-9]+\.[0-9]+\.[0-9]+$/' exit 0 fi if ! printf '%s\n' "$target" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$' || [ "$#" -ne 2 ]; then printf '%s\n' 'Usage: bin/update.sh check | vX.Y.Z /path/snapshot.tar' >&2 exit 2 fi if [ -n "$(git status --porcelain)" ]; then printf '%s\n' 'Commit or set aside local source changes before updating.' >&2 exit 1 fi git fetch origin --tags current=$(git rev-parse HEAD) next=$(git rev-parse --verify "refs/tags/$target^{commit}") git merge-base --is-ancestor "$current" "$next" "$php_bin" bin/backup.php export "$2" if git switch --detach "$next" && "$composer_bin" install --no-dev --prefer-dist --no-interaction --no-scripts && "$php_bin" bin/install.php then printf 'Updated to %s. Start Webman with the original site environment.\n' "$target" else git switch --detach "$current" "$composer_bin" install --no-dev --prefer-dist --no-interaction --no-scripts printf 'Update failed. The prior source version is checked out and the backup is at %s.\n' "$2" >&2 exit 1 fi