#!/bin/bash set -e . /usr/share/debconf/confmodule # enable back-tracking db_capb backup || true # Set values from the configuration file. CONFIGFILE=/etc/backup-manager.conf CONFIG_OK="false" if [ -f $CONFIGFILE ] && [ -r $CONFIGFILE ]; then set +e . $CONFIGFILE if [ $? -eq 0 ]; then CONFIG_OK="true" fi set -e fi # Ensure unset variables will not be considered if sourcing errors occure # (the values stored in the debconf database will be used as a fallback). # NOTE: # To guarantee correctness, declare *after* sourcing the configuration file. db_safeset() # $1=debconf key, $2=value { if [ "$CONFIG_OK" = "false" ] && [ "X$2" = "X" ]; then return fi db_set $1 "$2" } # Preceed values db_safeset backup-manager/backup-repository "$BM_REPOSITORY_ROOT" db_safeset backup-manager/repo_user "$BM_REPOSITORY_USER" db_safeset backup-manager/repo_group "$BM_REPOSITORY_GROUP" db_safeset backup-manager/filetype "$BM_TARBALL_FILETYPE" db_safeset backup-manager/dump_symlinks "$BM_TARBALL_DUMPSYMLINKS" db_safeset backup-manager/name-format "$BM_TARBALL_NAMEFORMAT" db_safeset backup-manager/time-to-live "$BM_ARCHIVE_TTL" db_safeset backup-manager/directories "$BM_TARBALL_DIRECTORIES" db_safeset backup-manager/blacklist "$BM_TARBALL_BLACKLIST" # no debconf template for this one if [ "$BM_ENCRYPTION_METHOD" == "gpg" ]; then db_set backup-manager/enable_encryption "true" else db_set backup-manager/enable_encryption "false" fi db_safeset backup-manager/encryption_recipient "$BM_ENCRYPTION_RECIPIENT" db_safeset backup-manager/transfert_mode "$BM_UPLOAD_METHOD" db_get backup-manager/transfert_mode if [ -z "$RET" ] || [ "$RET" = "none" ]; then db_set backup-manager/want_to_upload "false" else db_set backup-manager/want_to_upload "true" fi db_safeset backup-manager/upload-hosts "$BM_UPLOAD_HOSTS" db_safeset backup-manager/upload-user-ftp "$BM_UPLOAD_FTP_USER" db_safeset backup-manager/upload-passwd "$BM_UPLOAD_FTP_PASSWORD" db_safeset backup-manager/upload-user-scp "$BM_UPLOAD_SSH_USER" db_safeset backup-manager/upload-key "$BM_UPLOAD_SSH_KEY" db_safeset backup-manager/upload-dir "$BM_UPLOAD_DESTINATION" db_safeset backup-manager/burning-method "$BM_BURNING_METHOD" db_get backup-manager/burning-method if [ -z "$RET" ] || [ "$RET" = "none" ]; then db_set backup-manager/burning-enabled "false" else db_set backup-manager/burning-enabled "true" fi db_safeset backup-manager/burning-device "$BM_BURNING_DEVICE" db_safeset backup-manager/burning-maxsize "$BM_BURNING_MAXSIZE" # Ask questions. # State variables (with two we can tell the direction of a transition). SRC_STATE=0 DST_STATE=1 # Flag to signal that blacklist processing has been performed. BL_DONE="false" # Variables to store the old debconf value, before setting a new one. # We need to initialize them before the loop, since the BL_DONE flag # is not set. db_get backup-manager/backup-repository PREV_REPO="$RET" # Since debconf frontends do not yet honor {begin/end}block commands, # we are stuck with one input per state if we want going forth and back # between questions to behave intuitively. while true; do case $DST_STATE in 1) # While the flag is not set (ie the user goes back and forth # without entering blacklist block), do not update PREV_REPO. if [ BL_DONE = "true" ]; then db_get backup-manager/backup-repository PREV_REPO=$(echo "$RET" | sed 's:\(.\)\(/\+\)$:\1:') # Unset the flag after putting a new value to PREV_REPO BL_DONE="false" fi db_input high backup-manager/backup-repository || true ;; 2) db_input medium backup-manager/repo_user || true ;; 3) db_input medium backup-manager/repo_group || true ;; 4) db_input low backup-manager/filetype || true ;; 5) db_get backup-manager/filetype # Only the tar / dar commands can dereference symlinks. if [ "$RET" != "zip" ]; then db_input low backup-manager/dump_symlinks || true else db_set backup-manager/dump_symlinks "false" fi ;; 6) db_input low backup-manager/name-format || true ;; 7) db_input medium backup-manager/time-to-live || true ;; 8) db_input high backup-manager/directories || true ;; 9) # Substitute in blacklist only if we are moving forward. # In order to forgivingly consider all the possible path variants # (such as dir/ , dir// , patha//pathb , etc.) we canonicalize # before comparing and replacing. if [ $SRC_STATE -lt $DST_STATE ]; then db_get backup-manager/blacklist NEW_BLACKLIST="$RET" # Update both the base repository root and its subdirectories. db_get backup-manager/backup-repository NEW_REPO=$(echo "$RET" | sed 's:\(.\)\(/\+\)$:\1:') if [ "$NEW_REPO" != "$PREV_REPO" ]; then NEW_BLACKLIST=$(echo "$NEW_BLACKLIST" | sed \ -e "s:^\($PREV_REPO\)\(/*\|\s\+\):$NEW_REPO\2:" \ -e "s:\(\s\+\)\($PREV_REPO\)\(/*\|\s\+\):\1$NEW_REPO\3:g" \ -e "s:\(\s\+\)\($PREV_REPO\)\(/*\)$:\1$NEW_REPO:" \ -e "s:^\($PREV_REPO\)\(/*\)$:$NEW_REPO:" ) PREV_REPO="$NEW_REPO" fi # Remove any entry contained in directories, either verbatim or # with a trailing / or a /* wildcard. But do not remove either # subdirectories, or more limited wildcards, or relative paths, # or the backup repository. db_get backup-manager/directories for entry in $(echo "$RET" \ | tr ' ' '\n' | grep '^/' | sed 's:\(.\)\(/\+\)$:\1:' \ ); do if [ "$entry" = "$NEW_REPO" ]; then continue fi full_entry="$entry\(/*\(\*\)\?\)\?" NEW_BLACKLIST=$(echo "$NEW_BLACKLIST" | sed \ -e "s:^\($full_entry\)\(\s\+\)::" \ -e "s:\(\s\+\)\($full_entry\)\(\s\+\): :g" \ -e "s:\(\s\+\)\($full_entry\\)$::" \ -e "s:^\($full_entry\)$::" ) done # Now, check if repository is in the blacklist; if not # add it (recursive backups are never a good idea). if echo "$NEW_BLACKLIST" | tr ' ' '\n' \ | grep --quiet "^$NEW_REPO\(/*\)\?$" 2>/dev/null ; then : elif [ $(echo "$NEW_BLACKLIST" | sed 's:\s*::g' \ | tr -d '\n' | wc --chars) -eq 0 ]; then NEW_BLACKLIST="$NEW_REPO" else NEW_BLACKLIST="$NEW_BLACKLIST $NEW_REPO" fi # Store blacklist and set the done flag here. db_set backup-manager/blacklist "$NEW_BLACKLIST" BL_DONE="true" fi db_input medium backup-manager/blacklist || true ;; 10) # Manage deprecated /etc/cron.d/backup-manager (<= 0.7.8 versions). if [ -f /etc/cron.d/backup-manager ]; then db_input high backup-manager/cron_d_remove_deprecated || true fi ;; 11) # Look where the cronscript is. BOGUS="sentinel" for freq in daily weekly monthly $BOGUS; do if [ -f /etc/cron.$freq/backup-manager ]; then db_set backup-manager/cron_frequency "$freq" break fi done if [ "$freq" = "$BOGUS" ] && [ -n "$2" ]; then # They don't have one; if upgrading, then they don't want it. db_set backup-manager/cron_frequency "none" fi db_input medium backup-manager/cron_frequency || true ;; # Now, we have the extra-features # Encryption? 12) db_input medium backup-manager/enable_encryption || true ;; 13) db_get backup-manager/enable_encryption if [ "$RET" = "true" ]; then db_input medium backup-manager/encryption_recipient || true fi ;; # Uploading system. 14) db_input low backup-manager/want_to_upload || true ;; 15) db_get backup-manager/want_to_upload if [ "$RET" = "true" ]; then db_input low backup-manager/transfert_mode || true fi ;; # Group alternative paths to a set of states. 16|17) db_get backup-manager/want_to_upload if [ "$RET" = "true" ]; then db_get backup-manager/transfert_mode case "$RET" in ftp) case $DST_STATE in 16) db_input low backup-manager/upload-user-ftp || true ;; 17) db_input low backup-manager/upload-passwd || true ;; esac ;; scp) case $DST_STATE in 16) db_input low backup-manager/upload-user-scp || true ;; 17) db_input low backup-manager/upload-key || true ;; esac ;; *) ;; esac fi ;; 18|19) db_get backup-manager/want_to_upload if [ "$RET" = "true" ]; then case $DST_STATE in 18) db_input low backup-manager/upload-hosts || true ;; 19) db_input low backup-manager/upload-dir || true ;; esac fi ;; # Optical disks burning? 20) db_input low backup-manager/burning-enabled || true ;; 21|22|23) db_get backup-manager/burning-enabled if [ "$RET" = "true" ]; then case $DST_STATE in 21) db_input low backup-manager/burning-device || true ;; 22) db_input low backup-manager/burning-method || true ;; 23) db_input low backup-manager/burning-maxsize || true ;; esac fi ;; # Final state; leave the state machine. *) break ;; esac # Advance the state machine. SRC_STATE=$DST_STATE if db_go; then DST_STATE=$(($DST_STATE + 1)) else DST_STATE=$(($DST_STATE - 1)) fi if [ $DST_STATE -le 0 ]; then # The user requested to back up from the first question; # leave package unconfigured. exit 10 fi done