#!/system/bin/sh

sdext=${SD_EXT_DIRECTORY:-/sd-ext}

# Ensure $sdext is actually mounted
grep -q " $sdext " /proc/mounts || exit 0

rm -rf $sdext/dalvik-cache

if [ ! -d $sdext/link2sd ] ; then
    for dir in app app-private; do
	[ -d $sdext/$dir -a -d /data/$dir ] || continue
	install -m 771 -o 1000 -g 1000 -d $sdext/$dir
	if ! grep -q " /data/$dir " /proc/mounts ; then
	    mv -f /data/$dir/* $sdext/$dir/
	    mount -o bind $sdext/$dir/ /data/$dir
	fi
    done
fi

