#!/bin/bash # shellcheck source=kzcommon.sh # ----------------------------------------------------------------------------- # GUI-wijzigingen tonen. # # Geschreven door Karel Zimmer . # # Auteursrecht (c) 2015-2021 Karel Zimmer. # GNU Algemene Publieke Licentie . # # RelNum=09.00.26 # RelDat=2021-01-15 # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # Global constants # ----------------------------------------------------------------------------- source "$(dirname "$0")"/kzcommon.sh # Bij aanpassingen ook .completion aanpassen! readonly OPTIONS_SHORT=$OPTIONS_SHORT_COMMON readonly OPTIONS_LONG=$OPTIONS_LONG_COMMON readonly USAGE="Gebruik: $PROGNAME $OPTIONS_USAGE_COMMON" readonly HELP="Gebruik: $PROGNAME [OPTIE...] GUI-wijzigingen tonen. Opties: $OPTIONS_HELP_COMMON" # ----------------------------------------------------------------------------- # Global variables # ----------------------------------------------------------------------------- declare CONFIG_A='' declare CONFIG_B='' # ----------------------------------------------------------------------------- # Functions # ----------------------------------------------------------------------------- check_input() { local -i getopt_rc=0 local parsed='' parsed=$( getopt --alternative \ --options "$OPTIONS_SHORT" \ --longoptions "$OPTIONS_LONG" \ --name "$PROGNAME" \ -- "$@" ) || getopt_rc=$? if [[ $getopt_rc -ne 0 ]]; then printf '%s\n' "$USAGELINE" >&2 QUIET=true exit $ERROR fi eval set -- "$parsed" process_general_options "$@" while true; do case $1 in --) shift break ;; *) shift ;; esac done if [[ "$*" ]]; then printf "$PROGNAME: %s\n%s\n" 'geen argumenten opgeven' "$USAGELINE" >&2 QUIET=true exit $ERROR fi # Een non-gui script gestart met optie gui. if $OPTION_GUI; then OPTION_GUI=false TERMINAL=true fi check_user } process_input() { CONFIG_A=$(mktemp -t "$PROGNAME-A-XXXXXXXXXX.lst") save_configuration_database A "$CONFIG_A" request_input CONFIG_B=$(mktemp -t "$PROGNAME-B-XXXXXXXXXX.lst") save_configuration_database B "$CONFIG_B" report_database_changes "$CONFIG_A" "$CONFIG_B" } save_configuration_database() { local fase=${1:-fase?} local output_file=${2:-output_file?} gsettings list-recursively > "$output_file" 2> >($LOGCMD) sort --unique \ --output="$output_file" \ "$output_file" info "Inhoud configuratiedatabase vastgelegd ($fase)." } request_input() { info 'Voer nu de wijziging uit in de grafische werkomgeving.' read -rp 'Druk op de Enter-toets wanneer gereed [Enter]: ' < /dev/tty } report_database_changes() { local output_file1=${1:-output_file1?} local output_file2=${2:-output_file2?} local -i diff_rc=0 info 'Wijzigingen in de configuratiedatabase, < is de oude instelling (A), > is de nieuwe instelling (B):' diff "$output_file1" \ "$output_file2" | grep --regexp='[>|<]' || true diff_rc=${PIPESTATUS[0]} if [[ $diff_rc -eq 0 ]]; then info 'Geen wijzigingen in de configuratiedatabase.' else info "Voer uit: ${BLUE}gsettings set WIJZIGING${NORMAL}" fi } term_script() { rm "$CONFIG_A" \ "$CONFIG_B" QUIET=true exit $SUCCESS } # ----------------------------------------------------------------------------- # Main line # ----------------------------------------------------------------------------- main() { init_script check_input "$@" process_input term_script } main "$@" # EOF