head	1.2;
access;
symbols;
locks; strict;
comment	@# @;


1.2
date	2005.08.05.22.02.38;	author shd;	state Exp;
branches;
next	1.1;

1.1
date	2005.04.05.14.17.46;	author shd;	state Exp;
branches;
next	;


desc
@@


1.2
log
@*** empty log message ***
@
text
@#!/bin/sh

# This script was written by Heikki Orsila <heikki.orsila@@iki.fi> on
# 2005.04.05. The script is in public domain, so you may do what ever you 
# want with it.

# PREQUISITES:
# - you need dmsetup
# - you need cryptsetup
# - you need device mapper crypto target support in kernel
# - you need fdisk to verify swap partition type

# INSTRUCTIONS
#
# Edit following variables:
#
#   device: name of the hard disk that should be verified with fdisk
#           (e.g. /dev/hda)
#   swappartition: partition name of the swap (e.g. /dev/hda2)
#   mappername: device mapper name of the crypted swap (e.g. cryptoswap
#               implies that the crypted swap device is /dev/mapper/cryptoswap)

device="/dev/hdc"
swappartition="/dev/hdc3"
mappername="cryptoswap"

function error() {
	echo error: $@@
	exit 1
}

CRYPTCMD=/sbin/cryptsetup
DEVMAPCMD=/sbin/dmsetup
MAPPER=/dev/mapper

test -x $CRYPTCMD || error "$CRYPTCMD missing"
test -x $DEVMAPCMD || error "$DEVMAPCMD missing"
test -d $MAPPER || error "$MAPPER dir missing"

/sbin/fdisk $device <<EOF 2>/dev/null |grep "$swappartition.*Linux swap.*$" > /dev/null
p
q
EOF

if test "$?" != "0" ; then
	echo $0: no swap on $swappartition. aborting.
	exit 1
fi

case "$1" in
 start)
	if test -e "$MAPPER/$mappername" ; then
		echo $MAPPER/$mappername already exists. aborting.
		exit 1
	fi
	$CRYPTCMD -d /dev/urandom create $mappername $swappartition ||error "$CRYPTCMD failed"
	/sbin/mkswap $MAPPER/$mappername ||error "mkswap failed on $MAPPER/$mappername"
	/sbin/swapon $MAPPER/$mappername ||error "error turning on swap on $MAPPER/$mappername"
	echo "swap initialized and activated at $MAPPER/$mappername"
	;;
 stop)
	if test ! -b "$MAPPER/$mappername" ; then
		echo block device named $MAPPER/$mappername does not exist
		exit 1
	fi
	/sbin/swapoff -a ||errno "can not turn swaps off"
	$DEVMAPCMD remove $mappername
	exit 1
	;;
 *)
	echo "Usage: $0 {start|stop}"
	exit 1
	;;
esac
@


1.1
log
@*** empty log message ***
@
text
@d40 1
a40 1
/sbin/fdisk $device <<EOF 2>/dev/null |grep "$swappartition.*Linux swap$" > /dev/null
@

