#!/system/bin/sh
# check mtdblk of cache and if cache-partition-size
# is too small (for e.g. market downloads > 9mb); if
# then remount and link it into data partition,
# preserving 'reboot to recovery' feature in cLK
 
caching=`grep cache /proc/mtd | cut -d: -f1 | sed 's/mtd/mtdblock/'`
sizing=$(df -k /cache | tail -n1 | tr -s ' ' | cut -d ' ' -f2)
if [ $sizing -lt 10000 ]
then
  umount -l /cache
  rm -rf /cache
  mkdir /cache
  mkdir /data/cache
  mkdir /mnt/recovery
  mount /dev/block/$caching /mnt/recovery
  mkdir /mnt/recovery/recovery
  mount -o bind /data/cache /cache
  mkdir /cache/download
  mkdir /cache/recovery
  mount -o bind /mnt/recovery/recovery /cache/recovery
  mount -o bind /data/local/download /cache/download
  chown 1000.2001 /cache
fi
 
exit 0

