From 25349313c26c51e12dd368defd394c953224d74d Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Sat, 14 Oct 2017 18:16:49 -0600 Subject: Fixed parsing of manifest application arguments Previously, each application line was broken up into multiple arguments if IFS was found anywhere. This caused application backup arguments to be disassociated with their corresponding applications. Now we parse the file line by line and for each line, the application is read as input field 1 and all arguments are fields 2 and forwads. With this new functionality, it will be *much* easier to add additional backup flags (eg: nocompress, nocleanup, etc). Updated the preserveCache functionality to use the new functionality. --- andbackup.sh | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/andbackup.sh b/andbackup.sh index 72b8aac..e7f2c1d 100755 --- a/andbackup.sh +++ b/andbackup.sh @@ -83,7 +83,12 @@ lfatal() { backup_app() { - local app="${1}" + local app="${1:-}" + local args="${2:-}" + local preserve_cache=0 # Whether to preserve cache in the backup. Can yield + # notably larger backups for some applications + local origifs=${IFS} # Input field seperator at runtime. Useful for + # reverting local tar # Tar command for packaging the backup @@ -93,16 +98,18 @@ backup_app() { return 1 fi - #If app has the flag_delimiter that means options are passed in - local preserveCache=false - if [ 0 = $(echo ${app} | grep -q [${flag_delimiter}]; echo $?) ]; then - linfo "This app $app has passed in options" - if [ 0 = $(echo ${app} | grep -q "preserveCache"; echo $?) ]; then - preserveCache=true + # Handle passed arguments + IFS=' ' + for arg in ${args}; do + # Don't clean up the cache if preserveCache is specified + if [ "${arg}" = 'preserveCache' ]; then + preserve_cache=true + else + # Do nothing with unknown arguments + lwarn "${app}: Unknown backup argument '${arg}'" fi - #Need to get app back to std naming (without params) - app=`echo ${app} | grep -o ^.*- | sed s/-//g | cat -` - fi + done + IFS=${origifs} # Make sure app is installed if [ ! -d "${ANDROID_DATA}/${app}" ]; then @@ -156,7 +163,7 @@ backup_app() { # This will sometimes free up significant amounts of space if [[ ! -d "${data}/cache" ]]; then linfo "Cache doesn't exist for ${app}" - elif ! $preserveCache; then + elif [ "$preserve_cache" -eq 0 ]; then linfo "Excluding cache for ${app}" tar="${tar} --exclude=cache" else @@ -265,10 +272,19 @@ restore_apps() { list_backup_apps() { local list=${1:-} - [[ -z ${list} ]] && printf "A backup list is required.\n" && return 1 - - for app in $(cat ${list}); do - backup_app "${app}" + [ -z "${list}" ] && printf "A backup list is required." && return 1 + + local app # Application mame + local args # Application arguments + + export IFS=$'\n' + for line in $(cat ${list}); do + # Parse out the app name + app="$(echo ${line} | tr -s ' ' | cut -d ' ' -f 1)" + # Parse out the arguments (if any) + args="$(echo ${line} | tr -s ' ' | cut -s -d ' ' -f 2-)" + # Exceute the backup + backup_app "${app}" "${args}" done } -- cgit v1.2.3