description "Micro SD Swap Location on Startup"
author "flopswap"

start on MOUNTS_OK

script

 ##These scripts are to stop swap being stripped on boot
 ##All status must return 0 or script will fail
 ##Depending on CSSU Upstart version this script needs to select correct method

  #Query Upstart if -lt use original flopswap method

  #UDV's
   qup="$(dpkg-query -W -f='${Version}\n' upstart)"
   upv="0.3.8-68+0cssu5"
   s="sleep"
   son="swapon"
   soff="swapoff"
   swap0=$(blkid | grep swap | grep -v UUID | awk '/dev/ {print $1}' | cut -d ":" -f 1)
   swap1=$(blkid | grep swap | grep UUID | awk '/dev/ {print $1}' | cut -d ":" -f 1 | sed -n '1p')
   swap2=$(blkid | grep swap | grep UUID | awk '/dev/ {print $1}' | cut -d ":" -f 1 | sed -n '2p')
 # Script
 # If two swaps on uSD are available continue else fallback.
if [ -n "$swap1" -o -n "$swap2" ]
 then
  dpkg --compare-versions $qup lt $upv || ver=1
    if [ "$ver" -eq 0 ]; then
     $son $swap1;$s 5;$soff $swap0
    elif [ "$ver" -ne 0 ]; then
     $soff $swap2;$s 5;$soff $swap0
    else
     $son -a
    fi
 else
  $son $swap0
fi
end script		
