vendor/custom: Backuptool files

This goes along with the releasetools enhancements in build/

Based on CyanogenMod 10.1, but debranded to generic naming for
easier sharing between community projects

Change-Id: I7031af3372a0bda31397e68761f772eccd4cb138
diff --git a/prebuilt/bin/backuptool.functions b/prebuilt/bin/backuptool.functions
new file mode 100644
index 0000000..1d80a9b
--- /dev/null
+++ b/prebuilt/bin/backuptool.functions
@@ -0,0 +1,36 @@
+#!/sbin/sh
+#
+# Functions for backuptool.sh
+#
+
+export C=/tmp/backupdir
+export S=/system
+
+backup_file() {
+  if [ -e "$1" ]; then
+    local F=`basename "$1"`
+    local D=`dirname "$1"`
+    # dont backup any apps that have odex files, they are useless
+    if ( echo "$F" | grep -q "\.apk$" ) && [ -e `echo "$1" | sed -e 's/\.apk$/\.odex/'` ]; then
+      echo "Skipping odexed apk $1";
+    else
+      mkdir -p "$C/$D"
+      cp -p $1 "$C/$D/$F"
+    fi
+  fi
+}
+
+restore_file() {
+  local FILE=`basename "$1"`
+  local DIR=`dirname "$1"`
+  if [ -e "$C/$DIR/$FILE" ]; then
+    if [ ! -d "$DIR" ]; then
+      mkdir -p "$DIR";
+    fi
+    cp -p "$C/$DIR/$FILE" "$1";
+    if [ -n "$2" ]; then
+      echo "Deleting obsolete file $2"
+      rm "$2";
+    fi
+  fi
+}