All pastes #283713 Raw Edit

Someone

public shellscript v1 · immutable
#283713 ·published 2006-12-18 15:31 UTC
rendered paste body
#!/bin/bashif [[ $UID != 0 ]]        then echo "*** Hey `whoami`.. You are not user root. please rerun this script when you are root ***"        exit 0;fi#MAIN Config FileCONFIG="/etc/crypto/crypto.conf"Nr_of_disks=`grep -v "#" $CONFIG |wc -l`dm=/sbin/dmsetupcr=/sbin/cryptsetup function start() {### try to feel the input...function USBCHECK() {sp="-\|/-\|/"x=0while (i=0)        do echo -en "\b${sp:x++%${#sp}:1}"        sleep 1 ;        if [[ "$x" = "5" ]] ## how long shall we wait?                 then echo -e "\n * you better find that usbstick.." ; exit 0                else if [[ $(lsusb |grep -c "${usb_vendor}") = "1" ]]                        then sleep 7 &  break                     fi        fidone        if [[ `df |grep -c ${usbdev}` = "0" ]] & [[ `lsusb |grep -c "${usb_vendor}"` = "1" ]]        then sleep 2.3        mount -t "${usbfs}" "${usbdev}" "${usbmountpoint}"        sleep 1.3	elif [[ `df |grep -c ${usbdev}` = "1" ]] & [[ `lsusb |grep -c "${usb_vendor}"` = "1" ]]	    then echo "usb ok"        fi}function FSCHECK() {        fsck -t $fsocd -T -C -y "$mapperdev"        if [[ "$?" == "0" ]]                then                echo -e " ### File System on $mapperdev seams to be OK ###\n"        elif [[ "$?" == "1" ]]                then echo " ### Errors on $mapperdev are corrected ###"        elif [[ "$?" == "4" ]]                then echo " *** Warning:: File system on $mapperdev has errors left uncorrected ***"                exit 1;        elif [[ "$?" == "128" ]]                then echo " *** Shared library error ***"                echo "  check --> your mount install"                echo "  check --> your lib.. /lib/"                echo "  ldd /bin/mount to see.. might help"                sleep 2                exit 1;        fi}for (( i=1 ; i<="$Nr_of_disks" ; i++ ))do## the variables from the configfilecryptohd=`awk '{print $1}' $CONFIG | sed -n ""$i"p"`fsocd=`awk '{print $2}' $CONFIG | sed -n ""$i"p"`mappername=`awk '{print $3}' $CONFIG | sed -n ""$i"p"`mapperdev=`awk '{print $4}' $CONFIG |sed -n ""$i"p"`mountpoint=`awk '{print $5}' $CONFIG | sed -n ""$i"p"`keyfile="`awk '{print $6}' $CONFIG | sed -n ""$i"p"`"usb_vendor=`awk '{print $7}' $CONFIG | sed -n ""$i"p"`usbmountpoint=`awk '{print $8}' $CONFIG | sed -n ""$i"p"`chiper=`awk '{print $9}' $CONFIG | sed -n ""$i"p"`usbfs="ext2"## dont edit this unless you got a verry static device## might changed in newer kernels.. i donno ;\usbnumber=`egrep "(sda1|sdb1|sdc1|sdd1)" /proc/partitions | awk '{print $4}'`usbdev="/dev/$usbnumber"## if no mapper or mount for the  devicesif [[ ! -e ${mapperdev} ]] && [[ `df | grep -c "${mapperdev}"` == "0" ]]        then        ## All clear to continue        USBCHECK 	sleep 1	$cr -c $chiper -d $usbmountpoint/$keyfile create $mappername $cryptohd	FSCHECK        mount -t ${fsocd} ${mapperdev} ${mountpoint}## If no mapper but mounted ; bad stuff can happenelif [[ ! -e ${mapperdev} ]] && [[ `df |grep -c "${mapperdev}"` == "1" ]]        then umount -l -r -f ${mountpoint} || echo "crap.. try lsof ${mountpoint} and kill all thouse pid's" & exit 1;        USBCHECK	sleep 1	$cr -c $chiper -d $usbmountpoint/$keyfile create $mappername $cryptohd        FSCHECK        mount -t ${fsocd} ${mapperdev} ${mountpoint}## If mapper exsits but its not mounted..  remove it and make a new..elif [[ -e "${mapperdev}" ]] && [[ `df |grep -c "${mapperdev}"` == "0" ]]	then ${dm} remove "${mappername}"        USBCHECK	sleep 1	$cr -c $chiper -d $usbmountpoint/$keyfile create $mappername $cryptohd	FSCHECK        mount -t ${fsocd} ${mapperdev} ${mountpoint}## if mounted and all well just exit,,elif [[ -e "${mapperdev}" ]] && [[ `df |grep -c "${mapperdev}"` == "1" ]]        then #exit 0;        echo " *** DEVICE $mapperdev Is already mounted"fidone}function stop() {for (( i=1 ; i<="$Nr_of_disks" ; i++ ))do mappername=`awk '{print $3}' $CONFIG | sed -n ""$i"p"`mapperdev=`awk '{print $4}' $CONFIG |sed -n ""$i"p"`umount -l -r -f "${mapperdev}" &> /dev/null${dm} remove "${mappername}" &> /dev/nulldone}case "$1" in start)	start	;;	stop)	stop		;;	*)	echo "use $0 start or $0 stop"	exit 0;	;;esac