#!/system/bin/sh

sdext=${SD_EXT_DIRECTORY:-/sd-ext}
sdext2=/data/sdext2
mmcblk=/dev/block/mmcblk0p2

# Oh Link2SD, you so funny
init=/system/etc/11link2sd
if [ -e $init ] ; then
    busybox mount -o remount,rw /system
    rm $init
    sync
    busybox mount -o remount,ro /system
fi

# Prep mountpoint
rm -f $sdext2 # survives iff directory
install -m 771 -o 1000 -g 1000 -d $sdext2

# Handle ext parition
if grep -q " $sdext " /proc/mounts ; then
    if [ -d $sdext/link2sd ] ; then
	install -m 771 -o 1000 -g 1000 -d $sdext/link2sd
	mount -o bind $sdext/link2sd/ $sdext2
	install -m 771 -o 1000 -g 1000 -d $sdext2
    fi
else
    # Try a fat partition
    if fsck_msdos -y $mmcblk; then
	install -m 771 -o 1000 -g 1000 -d $sdext2
	mount -o $opt -t vfat $mmcblk $sdext2
	install -m 771 -o 1000 -g 1000 -d $sdext2
    fi
fi

