summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2017-10-14 18:16:49 -0600
committerAaron Ball <nullspoon@oper.io>2017-10-20 08:33:42 -0600
commit2ed21a713d92411149fd7a73640721ff9d30b000 (patch)
tree84cc1433fa90c4c9c9c2106c219c7675addbbea2
parent1908ff2864e1cc8068dfab51eefc53f96f0cdbe3 (diff)
downloadandbackup-parse-manifest-app-args.tar.gz
andbackup-parse-manifest-app-args.tar.xz
Fixed parsing of manifest application argumentsparse-manifest-app-args
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.
-rwxr-xr-xandbackup.sh46
1 files changed, 31 insertions, 15 deletions
diff --git a/andbackup.sh b/andbackup.sh
index 7f5c239..5ad31de 100755
--- a/andbackup.sh
+++ b/andbackup.sh
@@ -83,23 +83,30 @@ 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
if [ -z "${app}" ]; then
lerror "Application name required."
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 "${backups}/${app}/data/cache" ]; then
linfo "Cache doesn't exist for ${app}"
- elif ! $preserveCache; then
+ elif [ "$preserve_cache" -eq 0 ]; then
linfo "Deleting cache for ${app}"
rm -rf "${backups}/${app}/data/cache"
else
@@ -267,10 +274,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
}

Generated by cgit