diff options
| -rwxr-xr-x | mkhint | 48 | ||||
| -rwxr-xr-x | tests/mkhint_test.sh | 88 |
2 files changed, 125 insertions, 11 deletions
@@ -26,6 +26,14 @@ NVCHECKER_CONFIG="$HOME/.config/nvchecker/nvchecker.toml" # Missing file = empty list = phantom-dep handling is a no-op. PHANTOM_DEPS_FILE="$HOME/.config/mkhint/phantom-deps" +# Built-package repository (slackrepo output tree: <cat>/<pkg>/<pkg>-*.txz). +PACKAGES_DIR="/repo/" + +# ponytail: sourced config, defaults above win when file absent. A syntax-broken +# config aborts under `set -e` — acceptable for a single-user tool. +MKHINT_CONFIG="$HOME/.config/mkhint/config" +[[ -f "$MKHINT_CONFIG" ]] && source "$MKHINT_CONFIG" + # create the temp dir if not existing if [[ ! -d $TMP_DIR ]]; then mkdir $TMP_DIR @@ -820,14 +828,31 @@ update_hint_file() { echo; echo "==========================================" } -# Prompt to run slackrepo update after a hint file update -prompt_slackrepo() { +# True if a built package (.txz) for <pkg> exists in the repo. +pkg_in_repo() { local pkg="$1" + compgen -G "${PACKAGES_DIR%/}/*/${pkg}/${pkg}-*.txz" >/dev/null 2>&1 +} + +# Prompt to run `slackrepo <action> <pkgs...>`; no-op on empty list. +run_slackrepo() { + local action="$1"; shift + [[ $# -eq 0 ]] && return 0 local answer - read -r -p "Run 'slackrepo update $pkg'? [Y/n] " answer + read -r -p "Run 'slackrepo $action $*'? [Y/n] " answer answer="${answer:-Y}" if [[ "$answer" =~ ^[Yy]$ ]]; then - slackrepo update "$pkg" + slackrepo "$action" "$@" + fi +} + +# Single-package dispatch: update if already built, else build. +prompt_slackrepo() { + local pkg="$1" + if pkg_in_repo "$pkg"; then + run_slackrepo update "$pkg" + else + run_slackrepo build "$pkg" fi } @@ -995,14 +1020,15 @@ check_updates() { fi done - # Single slackrepo prompt for everything updated + # Split updated packages: existing → update, new → build. if [[ ${#updated[@]} -gt 0 ]]; then - local answer - read -r -p "Run 'slackrepo update ${updated[*]}'? [Y/n] " answer - answer="${answer:-Y}" - if [[ "$answer" =~ ^[Yy]$ ]]; then - slackrepo update "${updated[@]}" - fi + local -a existing=() fresh=() + local up + for up in "${updated[@]}"; do + if pkg_in_repo "$up"; then existing+=("$up"); else fresh+=("$up"); fi + done + run_slackrepo update "${existing[@]}" + run_slackrepo build "${fresh[@]}" fi } diff --git a/tests/mkhint_test.sh b/tests/mkhint_test.sh index fc84bf9..9b00547 100755 --- a/tests/mkhint_test.sh +++ b/tests/mkhint_test.sh @@ -1289,6 +1289,94 @@ rm -f "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null run_mkhint -n curl -V 8.6.0 >/dev/null 2>&1 assert_contains "hint VERSION set via -V" "$MOCK_HINT/curl.hint" 'VERSION="8.6.0"' +# ── T68: --check updated pkg already built → slackrepo UPDATE ───────────────── +echo "" +echo "T68: --check, package present in repo, offered 'update'" +rm -f "$SLACKREPO_LOG" "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null +cat > "$MOCK_BASE/new_ver.json" << 'EOF' +{ "version": 2, "data": { "curl": { "version": "8.9.0" } } } +EOF +cat > "$MOCK_HINT/curl.hint" << 'EOF' +VERSION="8.5.0" +ARCH="x86_64" +DOWNLOAD="https://curl.se/download/curl-8.5.0.tar.gz" +MD5SUM="abc123def456abc123def456abc123de" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +EOF +seed_pkg network curl 8.5.0 +run_mkhint -C curl < <(printf 'Y\nY\n') +assert_contains "slackrepo update called" "$SLACKREPO_LOG" '^update curl$' +assert_not_contains "no build called" "$SLACKREPO_LOG" 'build' + +# ── T69: --check updated pkg NOT built → slackrepo BUILD ────────────────────── +echo "" +echo "T69: --check, package absent from repo, offered 'build'" +rm -f "$SLACKREPO_LOG" "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null +rm -rf "$MOCK_PKGS" +cat > "$MOCK_BASE/new_ver.json" << 'EOF' +{ "version": 2, "data": { "curl": { "version": "8.9.0" } } } +EOF +cat > "$MOCK_HINT/curl.hint" << 'EOF' +VERSION="8.5.0" +ARCH="x86_64" +DOWNLOAD="https://curl.se/download/curl-8.5.0.tar.gz" +MD5SUM="abc123def456abc123def456abc123de" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +EOF +run_mkhint -C curl < <(printf 'Y\nY\n') +assert_contains "slackrepo build called" "$SLACKREPO_LOG" '^build curl$' +assert_not_contains "no update called" "$SLACKREPO_LOG" 'update' + +# ── T70: --check mixed → update for built, build for new ────────────────────── +echo "" +echo "T70: --check, one built + one new, both offered" +rm -f "$SLACKREPO_LOG" "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null +rm -rf "$MOCK_PKGS" +cat > "$MOCK_BASE/new_ver.json" << 'EOF' +{ "version": 2, "data": { "curl": { "version": "8.9.0" }, "wget": { "version": "1.25.0" } } } +EOF +cat > "$MOCK_HINT/curl.hint" << 'EOF' +VERSION="8.5.0" +ARCH="x86_64" +DOWNLOAD="https://curl.se/download/curl-8.5.0.tar.gz" +MD5SUM="abc123def456abc123def456abc123de" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +EOF +cat > "$MOCK_HINT/wget.hint" << 'EOF' +VERSION="1.21.0" +ARCH="x86_64" +DOWNLOAD="https://ftp.gnu.org/gnu/wget/wget-1.21.0.tar.gz" +MD5SUM="beefbeefbeefbeefbeefbeefbeefbeef" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +EOF +seed_pkg network curl 8.5.0 +run_mkhint -C curl wget < <(printf 'Y\nY\nY\nY\n') +assert_contains "update for built curl" "$SLACKREPO_LOG" '^update curl$' +assert_contains "build for new wget" "$SLACKREPO_LOG" '^build wget$' + +# ── T71: --hintfile no -V, pkg not built → build ────────────────────────────── +echo "" +echo "T71: --hintfile single, build-vs-update by presence" +rm -f "$SLACKREPO_LOG" "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null +rm -rf "$MOCK_PKGS" +cat > "$MOCK_BASE/new_ver.json" << 'EOF' +{ "version": 2, "data": { "curl": { "version": "8.9.0" } } } +EOF +cat > "$MOCK_HINT/curl.hint" << 'EOF' +VERSION="8.5.0" +ARCH="x86_64" +DOWNLOAD="https://curl.se/download/curl-8.5.0.tar.gz" +MD5SUM="abc123def456abc123def456abc123de" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +EOF +run_mkhint -f curl < <(printf '\nY\n') +assert_contains "hintfile new pkg → build" "$SLACKREPO_LOG" '^build curl$' + # ─── SUMMARY ────────────────────────────────────────────────────────────────── teardown |
