#!/bin/bash
PIS_SBIN="${PIS_SBIN:-/sbin}"
if [ -z "${PIS_LIBDIR:-}" ]; then
    case "$(uname -m)" in x86_64) PIS_LIBDIR=/usr/lib64/pis ;; *) PIS_LIBDIR=/usr/lib/pis ;; esac
fi
. "$PIS_LIBDIR/pis_lib" 2>/dev/null || . "$(dirname "$0")/pis_lib" || exit 1
pis_init || exit 1
release="$(pis_release)" || { pis_error "Unable to detect the Slackware release."; exit 1; }
arch="$(pis_arch)" || { pis_error "Unsupported architecture."; exit 1; }
dialog --backtitle "$PIS_BACKTITLE" --title "Slackpkg+" \
    --yesno "Install slackpkg+ 1.8.0 for Slackware $release/$arch repositories?" 7 68 || exit 0
items=(alienbob "Alien Bob packages" off restricted "Alien Bob restricted packages" off)
[ "$arch" != x86_64 ] || items=(multilib "32-bit compatibility libraries" off "${items[@]}")
selected=$(dialog --stdout --separate-output --backtitle "$PIS_BACKTITLE" --title "Slackpkg+ Repositories" \
    --checklist "Enable repositories for Slackware $release/$arch:" 0 0 0 "${items[@]}") || exit 0
repos="$(printf '%s\n' "$selected" | tr '\n' ' ' | sed 's/[[:space:]]*$//')"
pis_install_slackpkgplus "$repos" || { pis_error "slackpkg+ could not be installed or updated."; exit 1; }
pis_info "Slackpkg+" "slackpkg+ was installed and configured successfully."
