#!/bin/csh -f

switch (`uname -s``uname -r`)
case Linux2*:
	breaksw
default:
	exec echo ${0}: does not run on `uname -s` `uname -r`
endsw

set DEBUG

while($#argv)
	switch ("$1")
	case -d:
		set DEBUG = "/bin/echo"
#		shift
#		breaksw
# fall through to verbose
	case -v:
		set VERBOSE
		shift
		breaksw
	default:
		set DQ = '"'
		exec echo ${0}: "What do I do with $DQ$1$DQ?"
	endsw
end

set BADLABELS = `/sbin/swapon -a | & grep "cannot find the device for LABEL=" | sed 's;.*LABEL=;;'`

if ("$BADLABELS" == "") then
    if ($?VERBOSE) echo `date +%T` no unlabelled swap entries found
    exit
endif


foreach LABEL ( $BADLABELS )
    echo `date +%T` Fixing $LABEL

# find just device name
    set DEV = `echo $LABEL | sed 's;SWAP-;;'`
    if ("$DEV" == "$LABEL") exec echo ${0}: cannot derive device from $LABEL

# make sure this is swap device

    set LINE = `/sbin/sfdisk -l |& grep "/dev/$DEV .* swap"`
    if ("$DEBUG" != "") echo LINE = $LINE
    if ($#LINE == 0) exec echo ${0}: /dev/$DEV does not appear to be a swap device

# label it
    $DEBUG  /sbin/mkswap -L $LABEL /dev/$DEV

end

echo `date +%T` Enabling swapping

/sbin/swapon -a

if ($?VERBOSE) echo `date +%T` Done
