Advertisement
Guest User

kdeencfs

a guest
Jun 23rd, 2016
1,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.04 KB | None | 0 0
  1. #!/bin/bash
  2. # Mounts an Encfs partition with dialogues, and a password stored in KDE Wallet.
  3. # The first parameter is the encrypted directory and the second parameter is the mount point.
  4. # If the password is not present in kwallet, then it is entered via a dialogue and then stored in the wallet.
  5. #
  6. # Original script by Taboom (version 1.2) found at http://www.kde-apps.org/content/show.php/Truecrypt+mount+and+unmount+scripts?content=53634
  7.  
  8. SOURCE=$1
  9. DESTINATION=$2
  10.  
  11. APPID=encfs # The application ID that KDE Wallet will recognise
  12. KWALLETD=/usr/bin/kwalletd # location of kwalletd
  13.  
  14. # Check for an X session
  15. if [ -z $DISPLAY ]; then
  16.   echo "X not running"
  17.   exit
  18. fi
  19.  
  20. $KWALLETD
  21.  
  22. #If parameters are missing
  23. if [ -z "$SOURCE" ]; then
  24.   SOURCE=$(kdialog --title "Encrypted directory" --getexistingdirectory . )
  25.   [ -z "$SOURCE" ] && exit;
  26. fi
  27.  
  28.  
  29. if [ -z "$DESTINATION" ]; then
  30.   DESTINATION=$(kdialog --title "Mount point" --getexistingdirectory . )
  31.   [ -z "$DESTINATION" ] && exit;
  32. fi
  33.  
  34. #Is this Encfs partiton mounted?
  35. if [ "$(mount | grep $DESTINATION)" != "" ]; then
  36.   $(/usr/bin/kdialog --passivepopup "Encfs: $DESTINATION is already mounted")
  37. else
  38.   # Ensure kwallet is running on KDE startup
  39.   while [ "$(qdbus org.kde.kwalletd /modules/kwalletd org.kde.KWallet.isEnabled)" != "true" ]
  40.   do
  41.     $KWALLETD
  42.   done
  43.  
  44.   #Get the key from KDE Wallet, if nonexisting ask for the key and store it later to KDE Wallet
  45.   WALLETID=$(qdbus org.kde.kwalletd /modules/kwalletd org.kde.KWallet.open kdewallet 0 $APPID)
  46.  
  47.   PASSWORD=$(qdbus org.kde.kwalletd /modules/kwalletd org.kde.KWallet.readPassword $WALLETID Passwords $DESTINATION $APPID)
  48.   #By default assume that the password was fetched from KDE Wallet
  49.   PASSWORD_FETCHED=0
  50.  
  51.   #Password does not exist - ask for it from the user
  52.   if [ -z "$PASSWORD" ]; then
  53.     PASSWORD=$(kdialog --title "Encfs: Mount $DESTINATION?" --password "Please enter passphrase for $DESTINATION.")
  54.     PASSWORD_FETCHED=$?
  55.   fi
  56.  
  57.   #If password is fetched or given
  58.   if [ $? != "" ];
  59.     then
  60.     #Try mounting the Encfs partition
  61.     A=$(echo $PASSWORD | encfs -S $SOURCE $DESTINATION )
  62.     #If successful mount
  63.     if [ $? == "0" ]
  64.       then
  65.       #If password was asked from the user, save it to KDE Wallet
  66.       if [ "$PASSWORD_FETCHED" = "0" ]; then
  67.         A=$(qdbus org.kde.kwalletd /modules/kwalletd org.kde.KWallet.writePassword $WALLETID Passwords $DESTINATION "$PASSWORD" $APPID)
  68.       fi
  69.       /usr/bin/kdialog --passivepopup "Encfs partition $DESTINATION mounted successfully"
  70.     else
  71.       #Unsuccessful mount
  72.       /usr/bin/kdialog --title "Encfs: Failed to mount $DESTINATION" --error "Failed to mount Encfs partition $DESTINATION. \n\nIncorrect password or error."
  73.     fi
  74.     #Close KDE Wallet -- can't seem to make it work with qdbus
  75.     #qdbus org.kde.kwalletd /modules/kwalletd org.kde.KWallet.close $WALLETID false $APPID
  76.     #dbus-send --session --dest=org.kde.kwalletd --type=method_call  /modules/kwalletd org.kde.KWallet.close int32:$WALLETID boolean:false string:"$APPID"
  77.   fi
  78. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement