#!/bin/sh # # Configuration script for BPALogin # # Creates a new bpalogin.conf file based on the installed template, prompting # for overrides. # # Relies heavily on the formatting of the bpalogin.conf file and is sensitive # to whitespace! Be careful when changing bpalogin.conf. # # Copyright 2003 William Rose and licensed under the # GNU GPL, as per the rest of BPALogin. ### CONFIG_FILE="${1:-/etc/bpalogin.conf}" TMP_DIR="${TMPDIR:-/tmp}" NEW_CONFIG="`mktemp $TMP_DIR/bpalogin.conf-XXXXXX`" if ! [ -r "$CONFIG_FILE" ] then echo "Usage: bpalogin.conf.sh config-file-name" exit 1 fi eval `cat "$CONFIG_FILE" | \ (while read do case "$REPLY" in '# '*) # Comment line ;; '#'*) # Unspecified option REPLY="${REPLY#\#}" if [ -n "$REPLY" ] then name="${REPLY%% *}" value="${REPLY#* }" echo "$name=\"$value\"" echo "${name}_disabled=\"yes\"" disabled="$disabled $name" fi ;; *) # Empty line or specified option if [ -n "$REPLY" ] then name="${REPLY%% *}" value="${REPLY#* }" echo "$name=\"$value\"" echo "${name}_disabled=\"no\"" variables="$variables $name" fi ;; esac done echo "variables=\"${variables# }\"" echo "disabled=\"${disabled# }\"" )` ## # Prompt for new values for already configured variables. # if [ -n "$variables" ] then cat <> "$NEW_CONFIG" ;; '#'*) # Unspecified option REPLY="${REPLY#\#}" if [ -n "$REPLY" ] then name="${REPLY%% *}" if eval "[ \"\$${name}_disabled\" = \"yes\" ]" then echo "#$name `eval 'echo $'$name`" >> "$NEW_CONFIG" else echo "$name `eval 'echo $'$name`" >> "$NEW_CONFIG" fi else echo $REPLY >> "$NEW_CONFIG" fi ;; *) if [ -n "$REPLY" ] then name="${REPLY%% *}" if eval "[ \"\$${name}_disabled\" = \"yes\" ]" then echo "#$name `eval 'echo $'$name`" >> "$NEW_CONFIG" else echo "$name `eval 'echo $'$name`" >> "$NEW_CONFIG" fi else echo $REPLY >> "$NEW_CONFIG" fi ;; esac done) echo echo "New configuration successfully saved in $NEW_CONFIG" echo -n "Overwrite $CONFIG_FILE with this file? (y/n) " read case "$REPLY" in [Yy]*) if mv "$NEW_CONFIG" "$CONFIG_FILE" then echo "Your BPALogin configuration file has been updated." else echo "Action failed. Please copy $NEW_CONFIG to $CONFIG_FILE manually." fi if ! chmod 600 "$CONFIG_FILE" then echo "Unable to change permissions for your configuration file." echo "Please check your configuration file is not readable by others." fi ;; *) echo "Your original BPALogin configuration file was not changed." ;; esac echo