#!/bin/bash # # Runnable self-check for compat32ctl. # Exercises argument handling and the --dry-run previews, so it runs anywhere # (no root, no Slackware pkgtools required). Exits nonzero on any failure. # # Copyright (C) 2026 Danilo M. # SPDX-License-Identifier: GPL-2.0-only # set -u cd "$(dirname "$0")" failed=0 pass() { printf 'ok - %s\n' "$1"; } fail() { printf 'FAIL - %s\n' "$1"; failed=1; } # --- syntax --------------------------------------------------------------- if bash -n compat32ctl; then pass "syntax (bash -n)"; else fail "syntax (bash -n)"; fi # --- argument handling ---------------------------------------------------- ./compat32ctl >/dev/null 2>&1 && fail "no args -> usage, nonzero" || pass "no args -> usage, nonzero" ./compat32ctl help >/dev/null 2>&1 && pass "help -> 0" || fail "help -> 0" ./compat32ctl bogus >/dev/null 2>&1 && fail "unknown cmd -> nonzero" || pass "unknown cmd -> nonzero" # --- dry-run previews ----------------------------------------------------- sync_out=$(./compat32ctl sync -n 2>&1) printf '%s' "$sync_out" | grep -q 'mirror -c -e -v' && pass "sync -n shows lftp mirror -v" || fail "sync -n shows lftp mirror -v" printf '%s' "$sync_out" | grep -q 'cmd:show-status on' && pass "sync -n enables lftp status" || fail "sync -n enables lftp status" printf '%s' "$sync_out" | grep -q 'md5sum -c --ignore-missing' && pass "sync -n shows md5 verify" || fail "sync -n shows md5 verify" install_out=$(./compat32ctl install -n 2>&1) printf '%s' "$install_out" | grep -q 'upgradepkg --install-new' && pass "install -n shows upgradepkg" || fail "install -n shows upgradepkg" [ "$install_out" = "$(./compat32ctl update -n 2>&1)" ] && pass "update -n matches install -n" || fail "update -n matches install -n" # --- remove refuses without root ------------------------------------------ if [ "$(id -u)" -ne 0 ]; then ./compat32ctl remove >/dev/null 2>&1 && fail "remove (real) refuses non-root" || pass "remove (real) refuses non-root" fi # --- remove discovery ----------------------------------------------------- tmp=$(mktemp -d) touch "$tmp/aaa_libraries-compat32-16.0-x86_64-1compat32" \ "$tmp/compat32-tools-3.10-noarch-18alien" \ "$tmp/unrelated-1.0-x86_64-1" remove_out=$(PKGDIR="$tmp" ./compat32ctl remove -n 2>&1) rm -rf "$tmp" printf '%s' "$remove_out" | grep -q 'aaa_libraries-compat32-16.0-x86_64-1compat32' && pass "remove -n finds compat32 libs" || fail "remove -n finds compat32 libs" printf '%s' "$remove_out" | grep -q 'compat32-tools-3.10-noarch-18alien' && pass "remove -n finds compat32-tools" || fail "remove -n finds compat32-tools" printf '%s' "$remove_out" | grep -q 'unrelated' && fail "remove -n skips unrelated" || pass "remove -n skips unrelated" # --- remove on an empty package db ---------------------------------------- tmp=$(mktemp -d) PKGDIR="$tmp" ./compat32ctl remove -n >/dev/null 2>&1 && pass "remove -n empty db -> 0" || fail "remove -n empty db -> 0" rm -rf "$tmp" exit $failed