#!/bin/sh ACTION=$1 MODULE=$2 APPLICATION=$(basename $0) PAMAVAILABLE="/usr/share/pam-configs-available/" PAMENABLE="/usr/share/pam-configs/" DIRECTORYDIVERTED="/usr/share/llxcfg-pamnss/pam-diverted/" CFG_DIR="pam-admin/enable" CFG_FILE="$CFG_DIR/lliurex" if [ "$3" ]; then DIRECTORYDIVERTED="$3" fi usage(){ echo "Usage:" echo "$APPLICATION enable|disable PAMMODULE" # Only use on postinstall and prerm echo "$APPLICATION divert|rmdivert PAMMODULE" echo "$APPLICATION rmdivert-all" echo "$APPLICATION update" exit 0 } enable_module(){ { llxcfg-config read "$CFG_FILE" ; echo "$1"; } |sort -u |llxcfg-config write "$CFG_FILE" } disable_module(){ llxcfg-config read "$CFG_FILE" |grep -vxF "$1" |sort -u |llxcfg-config write "$CFG_FILE" } test_module(){ if [ "$1" ] && [ -e "${PAMAVAILABLE}$1" ] ; then return 0 fi return 1 } update_links(){ find "${PAMAVAILABLE}" -type f -printf "%P\n" |while read MODULE; do if [ -L "$PAMENABLE$MODULE" ] ; then rm -f "$PAMENABLE$MODULE" fi done llxcfg-config dump "$CFG_DIR" |while read MODULE; do if test_module "$MODULE" ; then ln -fs "$PAMAVAILABLE$MODULE" "$PAMENABLE$MODULE" fi done } update_pam(){ pam-auth-update --package --force } if [ -z "$ACTION" ] ; then usage fi if [ -z "$MODULE" ] ; then case "$ACTION" in rmdivert-all|update) ;; *) usage ;; esac fi case "$ACTION" in enable) enable_module "$MODULE" update_links ;; disable) disable_module "$MODULE" update_links ;; divert) packagedivert=$(dpkg-divert --list ${PAMENABLE}${MODULE}) if [ -r "${PAMENABLE}$MODULE" ] && [ -z "$packagedivert" ] ; then dpkg-divert --package llxcfg-pamnss-client --rename --quiet --add --divert "${DIRECTORYDIVERTED}$MODULE" "${PAMENABLE}$MODULE" fi update_links update_pam ;; rmdivert) [ -r "${DIRECTORYDIVERTED}$MODULE" ] || exit 0 rm -f "${PAMENABLE}$MODULE" dpkg-divert --package llxcfg-pamnss-client --rename --quiet --remove "${PAMENABLE}$MODULE" || true update_pam ;; rmdivert-all) [ -d "${DIRECTORYDIVERTED}" ] || exit 0 for MODULE in $(find "${DIRECTORYDIVERTED}" -xtype f -printf "%P\n") ; do if [ -n "MODULE" ] ; then rm -f "${PAMENABLE}$MODULE" dpkg-divert --package llxcfg-pamnss-client --rename --quiet --remove "${PAMENABLE}$MODULE" || true fi done ;; update) update_links update_pam ;; *) usage ;; esac exit 0