Code Sample |
#!/bin/bash # encrypt_swap.sh v0.2 by wdef # Sets up encrypted swaps loopfree(){ A=$(losetup -a | cut -b 10) if [ -z "$A" ]; then NEXTLP=0 return 0 fi Y=0 for i in $A; do if [ $i -eq $Y ]; then (( Y = i + 1 )) continue else NEXTLP=$Y return 0 fi done if [ $Y -eq $MAXLOOPS ]; then return 1 else NEXTLP=$Y return 0 fi } #=================================================== WIPESWAP=yes # first overwrite swaps to wipe clean # WIPESWAP=no # in a hurry MAXLOOPS=8 if [ $EUID -ne 0 ]; then echo "You're not root."; exit 1; fi SWPS=$(awk '/^\/dev\//{print $1}' /proc/swaps) if echo $SWPS | grep -q '/dev/loop'; then echo "Looks like swap is encrypted already. Exiting .." exit 0 fi if [ -z "$SWPS" ]; then echo "No swap devices found." echo echo "You have the following partitions:" PARTITIONS="$(fdisk -l)" echo "================================================" echo "$PARTITIONS" echo "================================================" echo SWPS="" while true; do echo -n "Enter partition to use as encrypted swap device (CNTRL-C = quit): " read if [ $(echo "${REPLY}" | wc -w) -gt 1 ]; then echo "Please enter only one device at a time."; continue fi if [ ! -b "${REPLY}" ]; then echo "${REPLY} is not a valid block device."; continue fi if ! echo $PARTITIONS | grep -q ${REPLY}; then echo "${REPLY} is not a partition."; continue fi SWPS="${SWPS} ${REPLY}" echo "You have entered device(s): ${SWPS}" echo -n "Select more devices? (y/N) " read RP case $RP in y|y*|Y|Y*) continue;; n|n*|N|N*) break;; esac done echo echo "WARNING: Continuing will destroy data on ${SWPS} !" echo "~~~~~~~" while true; do echo -n "Last chance to exit. Are you sure you want to proceed? (YeS/n) " read case $REPLY in YeS) break;; n|N|n*|N*) exit 0;; y|y*|Y|Yes|YE*) echo "You must type YeS to proceed.";; *) echo "Invalid response.";; esac done else NSWP=$(echo $SWPS | wc -w) NUMSWP=${NSWP##*[ ]} echo "Encrypting $NUMSWP found swap device(s):" echo "${SWPS}" fi sed -i '/swap/ d' /etc/fstab for S in ${SWPS}; do if ! loopfree; then echo "Error: no free loops. Exiting ..."; exit 1; fi [ -n "$NUMSWP" ] && swapoff ${S} echo "Enabling encrypted swap on ${S} .." [ $WIPESWAP = yes ] && dd if=/dev/zero of=${S} bs=64k conv=notrunc &>/dev/null echo "${S} none swap sw,loop=/dev/loop$NEXTLP,encryption=AES128 0 0" >>/etc/fstab swapon -a done rm -rf /var/log/ksymoops # not needed for dsl echo "Finished." exit 0 |
Quote |
I remember nobody bothered much with dsl2unc for some time either |