From 422d1098cd89beaeed81cc40488252233e2ca0ad Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 27 Apr 2026 18:33:03 -0500 Subject: feat: consolidate zfssnapshot and zfsrollback into one subcommand-driven script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: zfssnapshot and zfsrollback were two separate scripts with overlapping pre-flight checks (zfs / fzf / root) and parallel UX patterns (description sanitization in one, fzf selection in the other). Users had to remember which script was for which operation, and a "list" view meant typing the raw `zfs list -t snapshot` command. There was no path to destroy individual snapshots short of `zfs destroy` directly, which is dangerous without a confirmation flow. Solution: rewrite zfssnapshot as a single multi-subcommand script (list, create, rollback, delete). Drop installer/zfsrollback. The new script uses a source-guard at the bottom (`if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then main "$@"; fi`) so bats can source it without triggering the install-time pre-flight checks, matching the pattern in installer/archangel. Pure helpers (sanitize_description, validate_description, format_snapshot_name) get extracted as named functions so they're testable in isolation. The destructive flows (rollback, delete) keep the explicit "yes" confirmation prompt, the genesis-snapshot warning, and the recursive-rollback-destroys-newer-snapshots warning. Delete uses fzf --multi so the user can pick several snapshot names at once. Updated build.sh to copy only the consolidated script. Dropped the zfsrollback profiledef permission line. Updated Makefile, README, scripts/sanity-test.sh, and testing-strategy.org to reflect the single-script layout. Bats: 147 → 168 (+21). Coverage spans sanitize_description (normal / boundary / error), validate_description (alphanumerics, hyphens, underscores accepted; spaces, slashes, shell metacharacters, empty rejected), format_snapshot_name (timestamp + description composition), and main subcommand dispatch (list / create / rollback / delete / help / unknown). Lint clean. The zfs-, fzf-, and arch-chroot-shelling subcommand bodies stay VM-tested per testing-strategy.org. --- build.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'build.sh') diff --git a/build.sh b/build.sh index 06399ec..cc6686a 100755 --- a/build.sh +++ b/build.sh @@ -386,10 +386,9 @@ info "Copying custom scripts..." cp "$INSTALLER_DIR/archangel" "$PROFILE_DIR/airootfs/usr/local/bin/" cp -r "$INSTALLER_DIR/lib" "$PROFILE_DIR/airootfs/usr/local/bin/" cp "$INSTALLER_DIR/install-claude" "$PROFILE_DIR/airootfs/usr/local/bin/" -# Copy zfssnapshot and zfsrollback for ZFS management -info "Copying zfssnapshot and zfsrollback..." +# Copy zfssnapshot for ZFS snapshot management (list/create/rollback/delete) +info "Copying zfssnapshot..." cp "$INSTALLER_DIR/zfssnapshot" "$PROFILE_DIR/airootfs/usr/local/bin/" -cp "$INSTALLER_DIR/zfsrollback" "$PROFILE_DIR/airootfs/usr/local/bin/" # Copy example config for unattended installs mkdir -p "$PROFILE_DIR/airootfs/root" @@ -411,9 +410,6 @@ if grep -q "file_permissions=" "$PROFILE_DIR/profiledef.sh"; then sed -i '/^file_permissions=(/,/)/ { /)/ i\ ["/usr/local/bin/zfssnapshot"]="0:0:755" }' "$PROFILE_DIR/profiledef.sh" - sed -i '/^file_permissions=(/,/)/ { - /)/ i\ ["/usr/local/bin/zfsrollback"]="0:0:755" - }' "$PROFILE_DIR/profiledef.sh" sed -i '/^file_permissions=(/,/)/ { /)/ i\ ["/usr/local/bin/lib/common.sh"]="0:0:755" }' "$PROFILE_DIR/profiledef.sh" -- cgit v1.2.3