#!/system/bin/sh
#----------------------------------------
# Hard Swap Flasher by Yank555.lu - v2.0
#----------------------------------------

log_file="/data/hardswap.log"
feedback_file="/tmp/install/hardswap.prop"
sdcard_device="/dev/block/mmcblk1"
swap_partition=`/tmp/install/fdisk -l $sdcard_device | /tmp/install/grep swap | /tmp/install/awk '{print $1;}'`

# Remove any prior logfiles / feedback files
/tmp/install/rm $log_file
/tmp/install/rm $feedback_file

/tmp/install/echo "------------------------------------------------" > $log_file
/tmp/install/echo "     Hard Swap Flasher by Yank555.lu - v2.1     " >> $log_file
/tmp/install/echo "------------------------------------------------" >> $log_file
/tmp/install/echo "SD-card device = $sdcard_device" >> $log_file
/tmp/install/echo " " >> $log_file
/tmp/install/echo "Paratition table for SD-card :" >> $log_file
/tmp/install/echo "------------------------------" >> $log_file
/tmp/install/fdisk -l $sdcard_device >> $log_file
/tmp/install/echo " " >> $log_file
/tmp/install/echo "Swap partition = $swap_partition" >> $log_file
/tmp/install/echo " " >> $log_file

if [ "$swap_partition" = "" ];
  then

    /tmp/install/echo "swap.present = no" >> $feedback_file

    /tmp/install/echo "No swap partion present on SD-card ... aborting !" >> $log_file

  else

    /tmp/install/echo "swap.present = yes" >> $feedback_file
    /tmp/install/echo "swap.device = $swap_partition" >> $feedback_file

    /tmp/install/echo "- formating swap partition '$swap_partition'" >> $log_file
    /tmp/install/mkswap $swap_partition >> $log_file
    /tmp/install/echo " " >> $log_file

    /tmp/install/echo "swap.formated = yes" >> $feedback_file

    /tmp/install/echo "- copying swap activation script to /system/etc/init.d" >> $log_file
    /tmp/install/echo " " >> $log_file
    /tmp/install/cp /tmp/init.d/98swap /system/etc/init.d/98swap
    /tmp/install/chmod 755 /system/etc/init.d/98swap
    /tmp/install/chown 0:2000 /system/etc/init.d/98swap
    /tmp/install/echo "done." >> $log_file

    /tmp/install/echo "swap.scriptinstalled = yes" >> $feedback_file

fi;