Create swap file only if absent
@@ -115,7 +115,13 @@ done
### Required? exit 1
### Else? exit 0
+if [ "$ENCRYPT" == "true" ]; then
+ SWAPDEV=/dev/mapper/swapfile
+else
+ SWAPDEV=$path
+fi
+if [ ! -f $path ] || ! [ $(stat -c "%s" $path) == $(disksize_to_count 1 $size) ]; then
## Allocate the file
dd if=/dev/zero of=$path bs=1024 count=$(disksize_to_count 1024 $size)
chmod 0600 $path
@@ -127,11 +133,9 @@ if [ "$ENCRYPT" == "true" ]; then
#losetup ${loop} ${path}
cryptsetup open --type plain --key-file /dev/urandom --key-size=256 --cipher=aes-cbc-essiv:sha256 --offset=0 ${path} swapfile
- SWAPDEV=/dev/mapper/swapfile
-else
- SWAPDEV=$path
fi
-## mkswap and swapon the device
/sbin/mkswap $SWAPDEV
+fi
+
/sbin/swapon $SWAPDEV
