#!/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; }
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 "Slapt-get Repositories" \
    --checklist "Third-party repositories for Slackware $release/$arch. Review package origins before installation:" 0 0 0 "${items[@]}") || exit 0
[ -n "$selected" ] || exit 0
repos="$(printf '%s\n' "$selected" | tr '\n' ' ' | sed 's/[[:space:]]*$//')"
pis_apply_slapt_repositories "$repos" || { pis_error "Repositories could not be configured or updated."; exit 1; }
pis_info "Slapt-get Repositories" "The selected Slackware $release/$arch repositories were added."
