#!/bin/sh
# Remember to edit the list of apps excluding dangerous or irrelevant ones.
# Find the directory where you saved the application data, what would be
# /data/data on the phone.  "cd" to that directory before running this script. 
# Make sure ./untar-data is there, either restored from the old version or
# copied anew from .../selen/doc/untar-data .
apps="
	com.amazon.kindle
	com.android.bluetooth
	com.android.browser
	com.android.certinstaller
	com.android.contacts
	com.android.deskclock
	com.android.keychain
	com.android.providers.calendar
	com.android.providers.contacts
	com.bugbox.android.apps.jira.lite
	com.cadreworks.bible_le
	com.eclipsim.gpsstatus2
	com.fsck.k9
	com.googlecode.andoku
	com.googlecode.android.wifi.tether
	com.happydroid.bookmarks
	com.neddashfox.nightclock
	com.whatsapp
	com.xabber.android
	de.schaeuffelhut.android.openvpn
	de.schaeuffelhut.android.openvpn.installer
	eu.kowalczuk.rsync4android
	jp.sblo.pandora.jota
	net.healeys.lexic
	org.connectbot
	org.dmfs.caldav.lib
	org.dmfs.carddav.sync
	org.hermit.tricorder
	org.linphone
	org.thetomahawk.spreadsheet
	ru.org.amip.ClockSync
	tkj.android.homecontrol.mythmote
	uk.co.nickfines.RealCalc
"

t=com.android.browser 
if [ ! -d $t ] ; then
    echo $t not found in current directory.
    echo "'cd'" to the directory containing the data dirs.
    echo This came from /data/data on the phone.
    exit 4
fi
ut=untar-data
if [ ! -e $ut ] ; then
    echo $ut not found in current directory.
    echo Copy it and make it executable. 
    exit 4
elif [ ! -x $ut ] ; then
    echo $ut is not executable, needs to be.
    exit 4
fi

adb push $ut /data/data/$ut
adb shell "chmod 755 /data/data/$ut"

tfil=/tmp/app.tar
for a in $apps ; do
    echo === Restoring $a
    if [ ! -d $a ] ; then
	echo "    Missing directory skipped"
	continue
    fi
    tar cf $tfil $a
    adb push $tfil /data/data/app.tar
    adb shell "/data/data/$ut /data/data/app.tar $a"
done
