Archief

Berichten met tag ‘cryptsetup’

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.

  1.  
  2. #!/bin/bash
  3. if [ -r /lib/cryptsetup/cryptdisks.functions ]; then
  4.   . /lib/cryptsetup/cryptdisks.functions
  5. else
  6.   kdialog –title $(basename $0) –error "/lib/cryptsetup/cryptdisks.functions not found"
  7.   exit 1
  8. fi
  9.  
  10. crypt_create (){
  11.   DLG_TITLE="Cryptsetup Dialog"
  12.   mountpoint=$(grep $MAPPER/$1 /etc/fstab | awk ‘{FS=" "}{print $2}’)
  13.   sudo cryptsetup status $1 > /dev/null
  14.   if [ $? -ne 0 ]; then
  15.     pwd=$(kdialog –title "$DLG_TITLE" –password "mapping $1 to device <$2>
  16.  
  17. Enter passphrase:")
  18.     if [ $? -ne 0 ]; then return 3; fi
  19.     if [ "$pwd" == "" ]; then
  20.       kdialog –title "$DLG_TITLE" –warningyesno "empty password, try again?" && {
  21.         crypt_create $1 $2
  22.         return 2
  23.       }
  24.     fi
  25.     echo "$pwd" | sudo cryptsetup create $1 $2
  26.     mount $mountpoint 2&>/dev/null|| {
  27.       sudo cryptsetup remove $1
  28.       kdialog –title "$DLG_TITLE" –warningyesno "cryptsetup create <$1> <$2> failed, try again?" && {
  29.         crypt_create $1 $2
  30.         return 2
  31.       }
  32.       return 0
  33.     }
  34.   else
  35.     if [ -z $3 ]; then
  36.       kdialog –yesno "$MAPPER/$CRYPT_NAME is active, do you want to deactivate?" && {
  37.         umount $mountpoint
  38.         sudo cryptsetup remove $1
  39.       }
  40.     fi
  41.   fi
  42.   return 1 #cryptdevice already setup
  43. }
  44.  
  45. if [ -r $TABFILE ]; then
  46.   grep -Ev "^#" $TABFILE | while read line; do
  47.     cryptname=$(echo $line | awk ‘{print $1}’)
  48.     cryptdevice=$(echo $line | awk ‘{print $2}’)
  49.     crypt_create $cryptname $cryptdevice $1
  50.   done
  51.   exit 0
  52. else
  53.   kdialog –title $(basename $0) –error "$TABFILE not readable"
  54.   exit 2
  55. fi
  56.  
Categorie├źn:Linux Tips & Trics Tags:, , ,