#!/system/bin/bash
# Darktremor A2SD 2.7 Check Setup Program
# By: Robert Travis Kirton
# Date:  June 21, 2010
# Based on code from Darktremor A2SD 2.6.1-R2"

export a2sdfs=`/system/bin/toolbox getprop cm.filesystem.ready`;
export a2sdfix=`/system/bin/busybox.a2sd grep -q -e cm.filesystem.ready /init.rc;/system/bin/busybox.a2sd echo $?;`
export a2sdcachefix=0;
export a2sdrunfix=`/system/bin/toolbox getprop cm.a2sd.runfix`;

if [ !$a2sdrunfix ];
  then
    export a2sdrunfix=0;
fi;

export a2sdfix=`/system/bin/busybox.a2sd grep -q -e cm.filesystem.ready /init.rc;/system/bin/busybox.a2sd echo $?;`;

if [ $a2sdfix == 1 ];
  then
    export a2sdfix=0;
  else
    export a2sdfix=1;
fi;

export a2sdfix2=`/system/bin/busybox.a2sd grep -q -e dc.filesystem.ready /init.rc;/system/bin/busybox.a2sd echo $?;`;

if [ $a2sdfix == 1 ];
  then
    export a2sdfix2=0;
  else
    export a2sdfix2=1;
fi;

if [ $a2sdfix == 0 ] && [ $a2sdfix2 == 0 ];
  then
    export a2sdfix=0;
  else
    export a2sdfix=1;
fi;

/system/bin/busybox.a2sd echo "[ ] Searching for Mount Point...";
if [ -d /system/sd ];
  then
    /system/bin/busybox.a2sd echo "[*] Mount point /system/sd located.";
  else
    /system/bin/busybox.a2sd echo "[X] Cannot find mount point /system/sd.";
    /system/bin/busybox.a2sd echo "    A2SD will not run without this mount point set.";
    exit;
fi;

/system/bin/busybox.a2sd echo "[ ] Checking for ext partition";
if [ -e /dev/block/mmcblk0p2 ];
  then
    /system/bin/busybox.a2sd more /proc/mounts | /system/bin/busybox.a2sd grep -e /system/sd
    if [ $? != 0 ];    
      then
        /system/bin/busybox.a2sd echo "[X] Ext partition found, but not mounted.";
        /system/bin/busybox.a2sd echo "    Your rom may not be setup to run A2SD.";
        /system/bin/busybox.a2sd echo "    Check with your rom developer if the boot image";
        /system/bin/busybox.a2sd echo "    is programmed to run A2SD.";
        exit;
      else
        /system/bin/busybox.a2sd echo "[*] Ext partition is mounted.";
    fi;
  else
    /system/bin/busybox.a2sd echo "[X] No ext partition or partition not at";
    /system/bin/busybox.a2sd echo "    /dev/block/mmcblk0p2.";
    /system/bin/busybox.a2sd echo "";
    /system/bin/busybox.a2sd echo "    An ext2, ext3, or ext4 partition must";
    /system/bin/busybox.a2sd echo "    exists on /dev/block/mmcblk0p2.";
    /system/bin/busybox.a2sd echo "";
    /system/bin/busybox.a2sd echo "    Reboot phone into recovery and create";
    /system/bin/busybox.a2sd echo "    an ext2, ext3, or ext4 partition.";
    exit;
fi;

/system/bin/busybox.a2sd echo "[ ] Checking A2SD links.";
/system/bin/busybox.a2sd echo "";
        /system/bin/busybox.a2sd echo "A2SD Status Report";
        /system/bin/busybox.a2sd echo "===============================================================";

if [ -h /data/app ];
  then
    if [ -e /system/sd/.noa2sd ];
      then
        /system/bin/busybox.a2sd echo "Apps          - [-] Linked to SD Card.";
        /system/bin/busybox.a2sd echo "                [-] File .noa2sd found.";
        /system/bin/busybox.a2sd echo "                [X] Programs run from SD card";
        /system/bin/busybox.a2sd echo "                [X] Setup issue.  Run a2sd repair to fix.";
        /system/bin/busybox.a2sd echo "";
      else
        /system/bin/busybox.a2sd echo "Apps          - [-] Linked to SD Card.";
        /system/bin/busybox.a2sd echo "                [-] File .noa2sd not found.";
        /system/bin/busybox.a2sd echo "                [*] Programs run from SD card";
        /system/bin/busybox.a2sd echo "                To run from internal storage, type a2sd remove";
        /system/bin/busybox.a2sd echo "";
    fi;
  else
    if [ -e /system/sd/.noa2sd ];
      then
        /system/bin/busybox.a2sd echo "Apps          - [-] Regular directory.";
        /system/bin/busybox.a2sd echo "                [-] File .noa2sd found.";
        /system/bin/busybox.a2sd echo "                [!] Programs run from Int. Storage.";
        /system/bin/busybox.a2sd echo "                To run from SD card, type a2sd install.";
        /system/bin/busybox.a2sd echo "";
      else
        /system/bin/busybox.a2sd echo "Apps          - [-] Regular directory.";
        /system/bin/busybox.a2sd echo "                [-] File .noa2sd not found.";
        /system/bin/busybox.a2sd echo "                [X] Programs runs from Int. Storage.";
        /system/bin/busybox.a2sd echo "                [X] Setup issue.  Run a2sd repair to fix.";
        /system/bin/busybox.a2sd echo "";
    fi;
fi;

if [ -h /data/app-private ];
  then
    if [ -e /system/sd/.noa2sd ];
      then
        /system/bin/busybox.a2sd echo "Private Apps  - [-] Linked to SD Card.";
        /system/bin/busybox.a2sd echo "                [-] File .noa2sd found.";
        /system/bin/busybox.a2sd echo "                [X] Private Programs run from SD card";
        /system/bin/busybox.a2sd echo "                [X] Setup issue.  Run a2sd repair to fix.";
        /system/bin/busybox.a2sd echo "";
      else
        /system/bin/busybox.a2sd echo "Private Apps  - [-] Linked to SD Card.";
        /system/bin/busybox.a2sd echo "                [-] File .noa2sd not found.";
        /system/bin/busybox.a2sd echo "                [*] Private Programs run from SD card";
        /system/bin/busybox.a2sd echo "                To run from internal storage, type a2sd remove";
        /system/bin/busybox.a2sd echo "";
    fi;
  else
    if [ -e /system/sd/.noa2sd ];
      then
        /system/bin/busybox.a2sd echo "Private Apps  - [-] Regular directory.";
        /system/bin/busybox.a2sd echo "                [-] File .noa2sd found.";
        /system/bin/busybox.a2sd echo "                [!] Private Programs run from Int. Storage.";
        /system/bin/busybox.a2sd echo "                To run from SD card, type a2sd install";
        /system/bin/busybox.a2sd echo "";
      else
        /system/bin/busybox.a2sd echo "Private Apps  - [-] Regular directory.";
        /system/bin/busybox.a2sd echo "                [-] File .noa2sd not found.";
        /system/bin/busybox.a2sd echo "                [X] Private Programs runs from Int. Storage.";
        /system/bin/busybox.a2sd echo "                [X] Setup issue.  Run a2sd repair to fix.";
        /system/bin/busybox.a2sd echo "";
    fi;
fi;

if [ -h /data/dalvik-cache ];
  then
    if [ ! -e /system/sd/.dalvikcache ] && [ ! -e /system/sd/.dcpartition ];
      then
        /system/bin/busybox.a2sd echo "Dalvik Cache  - [-] Symbolically Linked.";
        /system/bin/busybox.a2sd echo "                [-] File .dalvikcache not found.";
        /system/bin/busybox.a2sd echo "                [-] File .dalvikcachepart not found.";
        /system/bin/busybox.a2sd echo "                [X] Dalvik runs from either SD card or /cache.";
        /system/bin/busybox.a2sd echo "                [X] Setup issue.  Run a2sd repair to fix.";
        /system/bin/busybox.a2sd echo "";
      else
        if [ -e /system/sd/.dcpartition ];
          then
        /system/bin/busybox.a2sd echo "Dalvik Cache  - [-] Symbolically Linked.";
        /system/bin/busybox.a2sd echo "                [-] File .dalvikcachepart found.";
        /system/bin/busybox.a2sd echo "                [*] Dalvik runs from /cache partition."
        /system/bin/busybox.a2sd echo "                To run from internal storage, type a2sd nocache";
        /system/bin/busybox.a2sd echo "                To run from SD card, type a2sd cache";
        /system/bin/busybox.a2sd echo "";
          else
        /system/bin/busybox.a2sd echo "Dalvik Cache  - [-] Symbolically Linked.";
        /system/bin/busybox.a2sd echo "                [-] File .dalvikcache found.";
        /system/bin/busybox.a2sd echo "                [*] Dalvik runs from SD card";
        /system/bin/busybox.a2sd echo "                To run from internal storage, type a2sd nocache";
        /system/bin/busybox.a2sd echo "                To run from /cache partition, type a2sd cachepart";
        /system/bin/busybox.a2sd echo "";
        fi;
    fi;
  else
    if [ ! -e /system/sd/.dalvikcache ] && [ ! -e /system/sd/.dcpartition ];
      then
        /system/bin/busybox.a2sd echo "Dalvik Cache  - [-] Regular directory.";
        /system/bin/busybox.a2sd echo "                [-] File .dalvikcache not found.";
        /system/bin/busybox.a2sd echo "                [!] Dalvik runs from Int. Storage.";
        /system/bin/busybox.a2sd echo "                To run from SD card, type a2sd cache.";
        /system/bin/busybox.a2sd echo "                To run from /cache partition, type a2sd cachepart.";
        /system/bin/busybox.a2sd echo "";
      else
        if [ -e /system/sd/.dcpartition ];
          then
        /system/bin/busybox.a2sd echo "Dalvik Cache   - [-] Regular directory.";
        /system/bin/busybox.a2sd echo "                 [-] File .dalvikcachepart found.";
        /system/bin/busybox.a2sd echo "                 [X] Dalvik runs from Int. Storage.";
        /system/bin/busybox.a2sd echo "                 [X] Setup Issue.  Run a2sd repair to fix.";
        /system/bin/busybox.a2sd echo "";
           else
        /system/bin/busybox.a2sd echo "Dalvik Cache   - [-] Regular directory.";
        /system/bin/busybox.a2sd echo "                 [-] File .dalvikcache found.";
        /system/bin/busybox.a2sd echo "                 [X] Dalvik runs from Int. Storage.";
        /system/bin/busybox.a2sd echo "                 [X] Setup issue.  Run a2sd repair to fix.";
        /system/bin/busybox.a2sd echo "";
      fi;
    fi;
fi;

if [ -e /dev/block/mmcblk0p3 ];
  then
    if [ -e /system/sd/.noswap ];
      then
        /system/bin/busybox.a2sd echo "Swap           - [-] Partition present.";
        /system/bin/busybox.a2sd echo "                 [-] File .noswap found.";
        /system/bin/busybox.a2sd echo "                 [!] Swap does not start.";
        /system/bin/busybox.a2sd echo "                 To activate swap, type a2sd swap";
        /system/bin/busybox.a2sd echo "";
      else
        /system/bin/busybox.a2sd echo "Swap           - [-] Partition present.";
        /system/bin/busybox.a2sd echo "                 [-] File .noswap not found.";
        /system/bin/busybox.a2sd echo "                 [*] Swap starts.";
        /system/bin/busybox.a2sd echo "                 To deactivate swap, type a2sd noswap";
        /system/bin/busybox.a2sd echo "";
    fi;
  else
        /system/bin/busybox.a2sd echo "Swap           - [!] Partition not present.";
        /system/bin/busybox.a2sd echo "                 [!] Swap does not start.";
        /system/bin/busybox.a2sd echo "";
fi; 

if [ ! -e /system/sd/.zipalign ];
  then
        /system/bin/busybox.a2sd echo "ZipAlign       - [!] Not running at boot.";
        /system/bin/busybox.a2sd echo "";
  else
        /system/bin/busybox.a2sd echo "ZipAlign       - [*] Running at boot.";
        /system/bin/busybox.a2sd echo "";
fi;
 
if [ $a2sdfix == 0 ];
  then
        /system/bin/busybox.a2sd echo "Property Patch  - [X] File System Ready property ";
        /system/bin/busybox.a2sd echo "                      not found.";
        /system/bin/busybox.a2sd echo "                  [X] Boot image init.rc needs patch.";
        /system/bin/busybox.a2sd echo "                      Contact Kernel/ROM Developer.";
        /system/bin/busybox.a2sd echo "                  [X] Race condition may occur in";
        /system/bin/busybox.a2sd echo "                      unpatched ROM.  Phone may stall";
        /system/bin/busybox.a2sd echo "                      or loop during boot.";
        /system/bin/busybox.a2sd echo "";
  else
        /system/bin/busybox.a2sd echo "Property Patch  - [-] File System Ready property ";
        /system/bin/busybox.a2sd echo "                      found.";
        /system/bin/busybox.a2sd echo "                  [*] Boot image init.rc patched.";
        /system/bin/busybox.a2sd echo "";     
fi;

