diff options
author | Dave Reisner <d@falconindy.com> | 2010-01-12 10:50:52 -0500 |
---|---|---|
committer | Dave Reisner <d@falconindy.com> | 2010-01-12 10:50:52 -0500 |
commit | 146d12ded31768f558b53ad14e06d6029498f2be (patch) | |
tree | 55c8e106520483c1c7c71aade4748cb35e5111dc /squashfu | |
parent | bd94b486cac69317f989095469c57146166c933b (diff) | |
download | squashfu-146d12ded31768f558b53ad14e06d6029498f2be.tar.gz |
Create rollback action handler. Don't rely on wc -l alone to count bin inventory -- use grep to filter blank lines if a malicious user decides to edit the file and leave blanks
Diffstat (limited to 'squashfu')
-rwxr-xr-x | squashfu | 31 |
1 files changed, 25 insertions, 6 deletions
@@ -156,7 +156,7 @@ unmount_all () { check_for_resquash () { # Args: none # Returns: number of bins needing to be merged - local number_of_bins=$(wc -l "$BINVENTORY" | cut -d\ -f1) + local number_of_bins=$(grep -vE "^[ ]*$" "$BINVENTORY" | wc -l) debug "Found $number_of_bins bins" if [[ $number_of_bins -gt $MAX_BINS ]]; then @@ -215,7 +215,7 @@ create_new_incremental () { create_new_bin $? # Determine the mount order via binventory - bin_order=($(sort -n -r -t: -k2 "$BINVENTORY" | cut -d: -f1)) + local bin_order=($(sort -n -r -t: -k2 "$BINVENTORY" | cut -d: -f1)) mount_squash mount_union_with_bins ${bin_order[@]} @@ -235,7 +235,7 @@ action_backup () { # Returns: none # Does the binventory exist? If not, prompt to make sure this is an initialization - FIRST_RUN=0 + # FIRST_RUN=0 if [[ ! -f "$BINVENTORY" || ! -f "$SEED" ]]; then read -p "Looks like this is your first time running SquashFu. Is this correct? (y/n) " ans while [[ true ]]; do @@ -271,10 +271,29 @@ action_backup () { action_rollback () { debug "IOU: one rollback";exit 0 - # Validate input - # call mount_squash - # call mount_union_with_bins + # Validate input with test cases + if [[ -z $1 ]]; then + die "The rollback action requires 1 additional argument." + fi + + if [[ $1 -le 0 ]]; then + die "Please provide a positive number of backups to roll back" + fi + + # Form a chronologically ordered list of bins, assuming the user didn't give bogus input + local bin_list=($(grep -vE "^[ ]*$" "$BINVENTORY" | sort -t: -n -k2 | cut -d: -f1)) + + if [[ $1 -gt $number_of_bins ]]; then + die "Cannot rollback more than ${#number_of_bins[@]} backups" + fi + + local num_to_mount=$[ ${#number_of_bins[@]} - $1 ] + + call mount_squash + + call mount_union_with_bins ${bin_list[@]:0:$num_to_mount} + info "Union is now mounted at '${BKUP_ROOT}/rw'" } |