#!/bin/bash #/************************************************************************** #* This program is free software; you can redistribute it and/or modify * #* it under the terms of the WTFPL 2.0 or later, see * #* http://www.wtfpl.net/about/ * #* * #* This program is distributed in the hope that it will be useful, * #* but WITHOUT ANY WARRANTY; without even the implied warranty of * #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * #* * #***************************************************************************/ # A dialog to override configuration options. # Whiptail is not as easily deployed here, as other dialogs. # The main difficulty arises from the fact that positive defaults # are negated, while a checklist wants to give positive results. if [ $# -eq 0 ] then echo "ERROR: file-argument missing" exit 1 fi OUTFILE="$1" # empty the file truncate $OUTFILE -s0 TITLE="Override post-processor configuration" CHECKTITLE="Deselect to disable. Esc or Cancel close the dialog and no changes will be applied." # These are the configuration variables which can be unset. VARS=(GROUP_SIGS CUSTOM_HEADERS NO_ARCHIVE_GROUPS VFY_URLS DEBUG_LOG) # Checklist options options=(GROUP_SIGS 'Signatures' ON CUSTOM_HEADERS 'Custom headers' ON NO_ARCHIVE_GROUPS 'No Archive' ON VFY_URLS 'Correct URLs' ON DEBUG_LOG 'Log' ON) # show dialog and store results result=$(whiptail --title "$TITLE" --checklist "$CHECKTITLE" 13 55 5 "${options[@]}" 3>&1 1>&2 2>&3) # which button had been pushed? okcancel=$? # make an array read -ra opts <<< $result # comment out --------> echo "cancel/ok ? $okcancel" echo $result echo "${opts[@]}" echo "${#opts[@]}" # <-------- # Find deselected options which shall be written to the outfile. # Looks complicated. if [ "$okcancel" -eq 0 ] then list='' # check each available variable ... for c in ${VARS[@]} do deactivate=TRUE # ... against the result from the dialog for o in ${opts[@]} do if [ "$o" == "\"$c\"" ] then # ignore if a variable remained checked ... deactivate=FALSE fi done # ... else write it to the list. if [ "$deactivate" == TRUE ] then list="$list $c" fi done # Heureka. echo "$list" > "$OUTFILE" else echo "exit" > "$OUTFILE" fi # Ω