51 lines
1.5 KiB
Bash
Executable File
51 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
PACK_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
WORKSPACE="${1:-$(dirname -- "$PACK_DIR")}"
|
|
if [[ ! -d "$WORKSPACE" ]]; then
|
|
printf 'Project directory does not exist: %s\n' "$WORKSPACE" >&2
|
|
exit 1
|
|
fi
|
|
WORKSPACE="$(cd -- "$WORKSPACE" && pwd)"
|
|
DEST="$WORKSPACE/.agents/gewu"
|
|
|
|
echo '[1/3] Pulling GEWU agent updates...'
|
|
git -C "$PACK_DIR" pull --ff-only
|
|
|
|
echo '[2/3] Verifying the pulled pack...'
|
|
python3 "$PACK_DIR/scripts/manifest_tool.py" verify
|
|
|
|
if [[ ! -d "$DEST" || -L "$DEST" ]]; then
|
|
printf 'Installed GEWU pack not found or unsafe: %s\n' "$DEST" >&2
|
|
echo 'For a new project, use scripts/install.py install first.' >&2
|
|
exit 1
|
|
fi
|
|
if ! command -v rsync >/dev/null 2>&1; then
|
|
echo 'rsync is required to update the installed pack.' >&2
|
|
exit 1
|
|
fi
|
|
|
|
STAMP="$(date +%Y%m%d-%H%M%S)"
|
|
BACKUP="$WORKSPACE/.agents/gewu-backup-$STAMP"
|
|
if [[ -e "$BACKUP" ]]; then
|
|
printf 'Backup path already exists: %s\n' "$BACKUP" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Backing up the installed pack to $BACKUP..."
|
|
cp -a -- "$DEST" "$BACKUP"
|
|
|
|
echo '[3/3] Updating the installed pack...'
|
|
rsync -a --delete --exclude='.git' --exclude='__pycache__/' "$PACK_DIR/" "$DEST/"
|
|
|
|
if ! python3 "$DEST/scripts/manifest_tool.py" verify; then
|
|
echo 'Installed pack verification failed; restoring the backup...' >&2
|
|
rsync -a --delete "$BACKUP/" "$DEST/"
|
|
echo "Backup: $BACKUP" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo 'GEWU agent pack successfully updated and verified!'
|
|
echo "Backup: $BACKUP"
|