fix: replace fragile ssh archive one-liners with tools/archive-images.sh
Build Dev ISO / build-dev-iso (push) Failing after 3m18s
Build Dev ISO / build-dev-iso (push) Failing after 3m18s
The inline find -exec broke through the double shell hop (the remote shell consumed the ; separator). The script pipes its payload to remote bash via stdin, tolerates zero matches, and fails loudly on missing directories or failed moves.
This commit is contained in:
@@ -40,8 +40,7 @@ jobs:
|
|||||||
echo "KIOSK_ISO_FILENAME=${FILENAME}" >> "$GITHUB_ENV"
|
echo "KIOSK_ISO_FILENAME=${FILENAME}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Move old dev images to archive
|
- name: Move old dev images to archive
|
||||||
run: |
|
run: tools/archive-images.sh nclack@157.245.124.103 /mnt/infrastructure_data/files/images /mnt/infrastructure_data/files/images/archives 'radiantwave-kiosk-dev*'
|
||||||
ssh nclack@157.245.124.103 'find /mnt/infrastructure_data/files/images -maxdepth 1 -name "radiantwave-kiosk-dev*" -exec mv {} /mnt/infrastructure_data/files/images/archives/ ;'
|
|
||||||
|
|
||||||
- name: Copy kiosk ISO to fileserver
|
- name: Copy kiosk ISO to fileserver
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ jobs:
|
|||||||
echo "RPI_IMAGE_FILENAME=${FILENAME}" >> "$GITHUB_ENV"
|
echo "RPI_IMAGE_FILENAME=${FILENAME}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Move old Raspberry Pi images to archive
|
- name: Move old Raspberry Pi images to archive
|
||||||
run: |
|
run: tools/archive-images.sh nclack@157.245.124.103 /mnt/infrastructure_data/files/images /mnt/infrastructure_data/files/images/archives 'radiantwave-rpi*'
|
||||||
ssh nclack@157.245.124.103 'find /mnt/infrastructure_data/files/images -maxdepth 1 -name "radiantwave-rpi*" -exec mv {} /mnt/infrastructure_data/files/images/archives/ ;'
|
|
||||||
|
|
||||||
- name: Copy Raspberry Pi image to fileserver
|
- name: Copy Raspberry Pi image to fileserver
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
Executable
+56
@@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Archive old build images on the fileserver before publishing new ones.
|
||||||
|
#
|
||||||
|
# Usage: tools/archive-images.sh <ssh-target> <images-dir> <archive-dir> <pattern>...
|
||||||
|
#
|
||||||
|
# Zero matching files is fine (nothing to archive yet); a missing directory
|
||||||
|
# or a failed move aborts non-zero so CI stops before publishing.
|
||||||
|
# The remote half is piped to `bash -s` over stdin so there is no nested
|
||||||
|
# shell quoting to get wrong.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
die() { echo "error: $*" >&2; exit 1; }
|
||||||
|
|
||||||
|
(( $# >= 4 )) || die "usage: $0 <ssh-target> <images-dir> <archive-dir> <pattern>..."
|
||||||
|
|
||||||
|
target=$1 images_dir=$2 archive_dir=$3
|
||||||
|
shift 3
|
||||||
|
patterns=("$@")
|
||||||
|
|
||||||
|
for v in "$images_dir" "$archive_dir" "${patterns[@]}"; do
|
||||||
|
case $v in
|
||||||
|
*[\ space\'\"]*) die "unsafe argument (whitespace/quotes): $v" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Archiving previous images on $target:"
|
||||||
|
printf ' pattern: %s\n' "${patterns[@]}"
|
||||||
|
|
||||||
|
# Assignments prefixed to `bash -s` are parsed by the remote shell as
|
||||||
|
# environment variables for the script below; the quoted heredoc marker
|
||||||
|
# keeps every byte of the payload literal until bash executes it.
|
||||||
|
ssh "$target" "IMAGES_DIR=$images_dir ARCHIVE_DIR=$archive_dir bash -s" <<'REMOTE'
|
||||||
|
set -euo pipefail
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
|
if [ ! -d "$IMAGES_DIR" ]; then
|
||||||
|
echo "error: images dir not found: $IMAGES_DIR" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ ! -d "$ARCHIVE_DIR" ]; then
|
||||||
|
echo "error: archive dir not found: $ARCHIVE_DIR" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
moved=0
|
||||||
|
for pat in "${PATTERNS[@]}"; do
|
||||||
|
for f in "$IMAGES_DIR"/$pat; do
|
||||||
|
echo " archiving $(basename "$f")"
|
||||||
|
mv "$f" "$ARCHIVE_DIR/"
|
||||||
|
moved=$((moved + 1))
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Archived $moved file(s)."
|
||||||
|
REMOTE
|
||||||
Reference in New Issue
Block a user