summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xandbackup.sh46
1 files 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
}

Generated by cgit