robert_pectol]Ok folks, here's the new version! It now has theabilitytosecurelydelete the original file once this scripthassuccessfullyencryptedit. The option is disabled by default but canbeeasilyenabled bysetting the, "remove_orig_file" option near the topofthescript from,"no" to, "yes." BE WARNED - With this option active, the original file will be securely deleted!**Thatmeanstheonly way to recover the original file would betosuccessfullydecrypt it!Make sure you understand that. If youenablesecure filedeletion, itmight be a good idea to test it out onanunimportant fileso that you cansee how it works.
This new feature requires the 'wipe' command lineutility.Itcaneasily be downloaded and installed by opening a shellandtyping,"sudoapt-get install wipe" at the command prompt.
Since the script has undergone many changes inordertoincorporatethis new functionality, there might be some newbugs!Pleasereportthem so that I can get them fixed.
[COLOR=Red]UPDATED:[COLOR=Black] (02 Jan 2006 @2330 Z) This latest version contains a few minor bugfixes![/COLOR][/COLOR]
#!/bin/bash
#
# Nautilus file encryption/decryption script v2.1 - Uses GnuPG
# Written by Robert Pectol, January 2006 - http://rob.pectol.com
#
# This encrypter/decrypter script must be called from Nautilus! It
# relies on environment variables only available from within Nautilus.
# Place this script in your nautilus-scripts directory and make sure
# it's executable (chmod 775 this_script.sh) and it will show up in
# the, "Scripts" menu when files are right-clicked from within your
# Nautilus file manager. Please report any bugs to rob@pectol.com.
#
# This script requires GnuPG for file the encryption/decryption. It
# is usually installed by default on most distributions. However,
# you may need to generate a key pair for your user account. This is
# easily accomplished by opening a shell and typing the following at
# the command prompt: "gpg --gen-key" (Do *NOT* use sudo for this)
# Once you have generated your keypair, you can start encrypting and
# decrypting files with your key, using this script! It's important
# to NOT forget your passphrase or your encrypted files will be that
# way forever!!! If you enable the secure file deletion option, then
# you need to make sure the wipe utility is available on your system.
# If you don't have wipe, you can easily install it by opening a shell
# and typing, "sudo apt-get install wipe" at the command prompt.
#
# This program is free software. It is distributed in the hope
# that it will be useful, but WITHOUT ANY WARRANTY said:**
> ; then
files_path=$HOME"/Desktop"
else
files_path=`echo"$NAUTILUS_SCRIPT_CURRENT_URI" | sed -e 's/^file:\/\///; s/%20/\ /g'`
fi
gui=`which zenity`
enc_dec=`which gpg`
secure_delete=`which wipe`
# Secure file deletion disclaimer
agreed=`cat ~/.enc_dec_agreed` &> /dev/null
if [[ "$remove_orig_file" == "yes" && "$agreed" != "yes" ]]; then
dialog_title="Disclaimer!"
dialog_type="--question"
ackn1="By activating the secure file deletion feature, you acknowledge"
ackn2="that you understand the following: Once the file is successfully"
ackn3="encrypted to a new file, the original un-encrypted file will be"
ackn4="securely deleted! That is, it will be destroyed! After that,"
ackn5="the only hope of recovering the original file will be in the"
ackn6="successful decryption of the encrypted one! Don't forget your"
ackn7="passphrase or your encrypted files will be that way forever!"
ackn8="You also acknowledge that you absolve the author of this script,"
ackn9="of any responsibility for accidental data loss due to your use of it."
ackn10="You also acknowledge that you assume full responsibility for any and"
ackn11="all data loss due to your use of it! Select, 'Ok' to acknowledge."
ackn12="(NOTE: This noticewill only be shown once unless you decline to acknowledge!)"
feedback=`echo $ackn1$ackn2$ackn3$ackn4 $ackn5 $ackn6 $ackn7 $ackn8 $ackn9 $ackn10$ackn11$ackn12`
zenity --title "$dialog_title" "$dialog_type" --text "$feedback"
if [ "$?" == "0" ]; then
echo "yes" > ~/.enc_dec_agreed
$gui--title"Enabled!" "--info" --text "Secure file deletion is nowactive!You may now re-launch the script!"
else
$gui--title"Disabled!" "--info" --text "Then you should disablesecurefiledeletion before using this script again!"
fi
exit 0
fi
# Decrypt function
decrypt()
{
# Collect GnuPG passphrase and decrypt the file
getpasswd=`$gui --title "GnuPG Decrypter" --entry --hide-text \
--text="Please enter your GnuPG passphrase to decrypt $the_file:" \
| sed 's/^[ \t]*//;s/[ \t]*$//'` &> /dev/null
if [ "$getpasswd" == "" ]; then
dialog_title="Operation Aborted!"
dialog_type="--info"
feedback="No passphrase submitted. Operation cancelled!"
feedback
exit 0
fi
echo $getpasswd | $enc_dec-v--batch --passphrase-fd 0 --output /tmp/decrypted_output_file.dec \
--decrypt "$files_path/$the_file" &> /tmp/encdecresult
orig_filename=`cat/tmp/encdecresult| grep "original file name" |cut -d '=' -f2 | sed's/'\''//g'`
mv /tmp/decrypted_output_file.dec "$files_path/$orig_filename"
result=`cat /tmp/encdecresult | sed 's/<//g;s/>//g' | uniq`
rm -f /tmp/encdecresult
# Remove encrypted file after decryption
if [[ "$remove_orig_file"=="yes"&& `echo "$result" | grep "decryption failed"` == ""]];then
# Checkforexistence of the newly decrypted file before we remove theencryptedone
if [ -O "$files_path/$orig_filename" ]; then
rm -f "$files_path/$the_file"
fi
fi
# User feedback
if [[ `echo "$result" | grep "decryption failed"` != "" ]]; then
dialog_title="Decryption Error!"
dialog_type="--error"
feedback=$result
feedback
else
dialog_title="Decryption Results"
dialog_type="--info"
if [ "$verbose" == "yes" ]; then
feedback="Success! - $the_file was decryptedto$orig_filename usingkey $result"
else
feedback="Success! - Decrypted to $orig_filename!"
fi
feedback
fi
}
# Encrypt function
encrypt()
{
if [ -a "$files_path/$the_file.gpg" ]; then
dialog_title="Confirm File Replace!"
dialog_type="--question"
feedback="Encrypted file for $the_file already exists! Overwriteit?"
feedback
if [ "$yesorno" == "1" ]; then
dialog_title="Operation Aborted!"
dialog_type="--info"
feedback="Cancelled!"
feedback
exit 0
else
rm -f "$files_path/$the_file.gpg"
fi
fi
$enc_dec -v--batch--default-recipient-self -e "$files_path/$the_file"&>/tmp/encdecresult
result=`cat /tmp/encdecresult`
rm -f /tmp/encdecresult
result=`echo $result | tail -n 1 | cut -d '"' -f2 | sed 's/<//g;s/>//g'`
# Remove original file (if secure file deletion is enabled)
if [[ "$remove_orig_file"=="yes"&& `echo "$result" | grep "encryption failed"` == ""]];then
sec_file_del
else
if [[ `echo "$result" | grep "encryption failed"` == "" ]]; then
if [ "$verbose" == "yes" ]; then
warn1="*WARNING*Although$the_file was encrypted to $the_file.gpg,"
warn2="the original filewasNOT deleted. It is still on yourdrive!"
warn3="This may be asecurityissue! Consider enabling securefile"
warn4="deletion. Tostopseeing this warning, you can set theverbose"
warn5="option to, 'no' nearthetop of the script."
result=`echo "$result -$warn1$warn2 $warn3 $warn4 $warn5"`
fi
fi
fi
# User feedback
if [[ `echo "$result" | grep "encryption failed"` != "" ]]; then
dialog_title="Encryption Error!"
dialog_type="--error"
feedback=$result
feedback
else
dialog_title="Encryption Results"
dialog_type="--info"
if [ "$verbose" == "yes" ]; then
feedback="Success! - $the_file was encryptedto$the_file.gpg using key$result"
else
feedback="Success! - Encrypted to $the_file.gpg."
fi
feedback
fi
}
# Secure file deletion function
sec_file_del()
{
# Check for secure file deletion utility
if [ -x "$secure_delete" ]; then
# Checkforexistence of the newly encrypted file before we remove theoriginal
if [ -O "$files_path/$the_file.gpg" ]; then
$secure_delete -q -f "$files_path/$the_file"
if [ -a "$files_path/$the_file" ]; then
result=`echo "$result -*NOTE*$the_file (the original file) could NOTbe securely deleted!"`
else
result=`echo "$result -*NOTE*$the_file (the original file) wassecurely deleted!"`
fi
fi
else
warn1="*WARNING* $the_file could NOT be securely deleted!"
warn2="Make sure you have installed the wipe utility."
warn3="(ex: 'sudo apt-get install wipe')"
result=`echo "$result - $warn1 $warn2 $warn3"`
fi
}
# Feedback function
feedback()
{
$gui --title "$dialog_title" $dialog_type --text="$feedback"
yesorno=$?
}
# Errors function
errors()
{
if [ -x "$gui" ]; then
$gui --title"Error!" --error --text="Could NOT find GnuPG!"&>/dev/null
else
echo "Could NOT generate dialog!"
fi
exit 1
}
# Check for required tools
if [[ -x "$gui" && -x "$enc_dec" ]]; then
if [[ "$the_file" =~ "\.gpg$" || "$1" =~ "\.pgp$" ]]; then
decrypt
else
encrypt
fi
else
errors
fi
exit 0
Enjoy! :) You might want to review the code u've pasted, some spaces are wiped so the script is not working, look at for example
$gui--title"Enabled!" "--info" --text "Secure file deletion is nowactive!You may now re-launch the script!"
no spaces between $gui and --title -> script is not working btw i noticed serval times that when u post spaces are wiped :o look at your post number 31, you quoted my post number 29 but some words have spaces wiped :o