Skip to content

Commit

Permalink
bup.in: move variable creation in EXEC section for better readability
Browse files Browse the repository at this point in the history
This make the CHECK CONFIG section stand out more, and also brings
variables that are constructed with configuration closer to where they
are used.

It's also more sane that way since once we start building those
variables we've completed sanity checking.
  • Loading branch information
lelutin committed May 24, 2015
1 parent de225b7 commit c708b14
Showing 1 changed file with 48 additions and 46 deletions.
94 changes: 48 additions & 46 deletions handlers/bup.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,52 @@ getconf remote_bupdir
getconf host localhost
getconf user

# We need to export this before verifying bup's version in the CHECK CONFIG
# section since we're calling bup and it will bug us about the default ~/.bup
# location if it doesn't know where its repository is placed.
if [ -n "$bupdir" ]; then
BUP_DIR="$bupdir"
export BUP_DIR
debug "BUP_DIR set to: $bupdir"
fi

### CHECK CONFIG ###
debug "backup type is set to '$desttype'"

[ -n "$test" ] || test=0

if [ -z "$path" ]; then
fatal "No source path was given."
fi

if [ -z "$branch" ]; then
fatal "The backup branch was not specified."
fi

if [ -z "$bupdir" ]; then
debug "No bupdir specified: using the default location of ~/.bup !"
fi

if [ "$desttype" != "local" ]; then
[ -n "$user" ] || fatal "Username must be specified for non-local backups."
[ -n "$host" ] || fatal "Host name must be specified for non-local backups."
fi

if [ "$ignore_version" != "yes" ]; then
# see that bup has the same version at the source and destination
sourceversion=`bup_version`
if [ "$desttype" != "local" ]; then
destversion=`bup_version $user $host`
if [ "$sourceversion" != "$destversion" ]; then
fatal "bup does not have the same version at the source and at the destination."
fi
fi
fi

### REMOVE OLD BACKUPS ###
# This is not yet implemented in bup itself.

### EXECUTE ###
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
# TODO: order the includes and excludes
Expand All @@ -82,13 +128,8 @@ EXCLUDE_RX_LIST=
for i in $exclude_rx; do
EXCLUDE_RX_LIST="${EXCLUDE_RX_LIST}--exclude-rx '${i}' " ;;
done

IFS=$SAVEIFS

debug "backup type is set to '$desttype'"

[ -n "$test" ] || test=0

REMOTE_URL=
if [ "$desttype" != "local" ]; then
if [ "$testconnect" = "yes" ] || [ "${test}" -eq 1 ]; then
Expand All @@ -100,7 +141,8 @@ if [ "$desttype" != "local" ]; then
if [ "${test}" -eq 0 ]; then
# Even though we're already doing this in bup.helper, this gives users the
# possibility to just move the bup repository out of the way in case of
# corruption and let the next backup run automatically create a new repository.
# corruption and let the next backup run automatically create a new
# repository.
#
# calling bup init on an already existing repository is safe.
debug "Initializing remote bupdir if it does not exist"
Expand All @@ -111,46 +153,6 @@ if [ "$desttype" != "local" ]; then
fi
fi

if [ -n "$bupdir" ]; then
BUP_DIR="$bupdir"
export BUP_DIR
debug "BUP_DIR set to: $bupdir"
fi

### CHECK CONFIG ###
if [ -z "$path" ]; then
fatal "No source path was given."
fi

if [ -z "$branch" ]; then
fatal "The backup branch was not specified."
fi

if [ -z "$bupdir" ]; then
debug "No bupdir specified: using the default location of ~/.bup !"
fi

if [ "$desttype" != "local" ]; then
[ -n "$user" ] || fatal "Username must be specified for non-local backups."
[ -n "$host" ] || fatal "Host name must be specified for non-local backups."
fi

if [ "$ignore_version" != "yes" ]; then
# see that bup has the same version at the source and destination
sourceversion=`bup_version`
if [ "$desttype" != "local" ]; then
destversion=`bup_version $user $host`
if [ "$sourceversion" != "$destversion" ]; then
fatal "bup does not have the same version at the source and at the destination."
fi
fi
fi

### REMOVE OLD BACKUPS ###
# This is not yet implemented in bup itself.

### EXECUTE ###

if [ "${test}" -eq 0 ]; then
if [ "$desttype" = "on" ]; then
debug "$BUP on $user@host index -u $EXCLUDE_LIST $EXCLUDE_RX_LIST $PATH_LIST"
Expand Down

0 comments on commit c708b14

Please sign in to comment.