KDE dialog for crypysetup
1 oktober 2007
Reacties uit
Here is a bash script that uses kdialog to present a password prompt and tries to mount a crypt device. It interacts with the (k)ubuntu “cryptsetup” package.
-
-
#!/bin/bash
-
if [ -r /lib/cryptsetup/cryptdisks.functions ]; then
-
. /lib/cryptsetup/cryptdisks.functions
-
else
-
kdialog –title $(basename $0) –error "/lib/cryptsetup/cryptdisks.functions not found"
-
exit 1
-
fi
-
-
crypt_create (){
-
DLG_TITLE="Cryptsetup Dialog"
-
mountpoint=$(grep $MAPPER/$1 /etc/fstab | awk ‘{FS=" "}{print $2}’)
-
sudo cryptsetup status $1 > /dev/null
-
if [ $? -ne 0 ]; then
-
pwd=$(kdialog –title "$DLG_TITLE" –password "mapping $1 to device <$2>
-
-
Enter passphrase:")
-
if [ $? -ne 0 ]; then return 3; fi
-
if [ "$pwd" == "" ]; then
-
kdialog –title "$DLG_TITLE" –warningyesno "empty password, try again?" && {
-
crypt_create $1 $2
-
return 2
-
}
-
fi
-
echo "$pwd" | sudo cryptsetup create $1 $2
-
mount $mountpoint 2&>/dev/null|| {
-
sudo cryptsetup remove $1
-
kdialog –title "$DLG_TITLE" –warningyesno "cryptsetup create <$1> <$2> failed, try again?" && {
-
crypt_create $1 $2
-
return 2
-
}
-
return 0
-
}
-
else
-
if [ -z $3 ]; then
-
kdialog –yesno "$MAPPER/$CRYPT_NAME is active, do you want to deactivate?" && {
-
umount $mountpoint
-
sudo cryptsetup remove $1
-
}
-
fi
-
fi
-
return 1 #cryptdevice already setup
-
}
-
-
if [ -r $TABFILE ]; then
-
grep -Ev "^#" $TABFILE | while read line; do
-
cryptname=$(echo $line | awk ‘{print $1}’)
-
cryptdevice=$(echo $line | awk ‘{print $2}’)
-
crypt_create $cryptname $cryptdevice $1
-
done
-
exit 0
-
else
-
kdialog –title $(basename $0) –error "$TABFILE not readable"
-
exit 2
-
fi
-