#!/system/xbin/sh
# $1 = name of tar file, from "tar cf $1 $2"
# $2 = basename of data directory.
# Copy this script to /data/data (executable)

cd /data/data
    if [ ! -d $2 ] ; then
	echo "    On phone: missing directory $2 skipped"
	exit 4
    fi
uid=`ls -ld $2 | awk '{print $2}'`
if [ -z "$uid" ] ; then
    echo "    On phone: can't determine UID of $2"
    exit 4
fi
tar xpf $1
# We chown $uid $1 because xargs runs the command once even with no input.
find $2 ! -type l ! -user system -print | xargs -n 25 chown $uid $1
find $2 ! -type l ! -user system -print | xargs -n 25 chgrp $uid $1
rm $1
