Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 6 additions & 35 deletions thunar-gpg-decrypt.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Decrypt a gpg encrypted file.
#
Expand Down Expand Up @@ -35,45 +35,16 @@
# https://github.com/cytopia/thunar-custom-actions
#

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

usage() {
echo "$0 -f <filename>"
echo
echo " required:"
echo " -f input filename"
echo
}
source $DIR/thunar-gpg-functions.sh


while getopts ":f:" i; do
case "${i}" in
f)
f=${OPTARG}
;;
*)
echo "Error - unrecognized option $1" 1>&2;
usage
;;
esac
done
shift $((OPTIND-1))

# Check if file is specified
if [ -z "${f}" ]; then
echo "Error - no file specified" 1>&2;
usage
exit 1
fi

# Check if gpg exists
if ! command -v gpg >/dev/null 2>&1 ; then
echo "Error - 'gpg' not found." 1>&2
exit 1
fi
checkCommandLineArg "$@"
checkBinaryReq


# remove ".gpg" file extension if it exists
output="$( echo "${f}" | sed 's/\.gpg$//g' )"
output="$( echo "${f}" | sed 's/\(\.gpg\|\.asc\)$//g' )"

$(which gpg) -o "${output}" -d "${f}"
exit $?
Expand Down
93 changes: 93 additions & 0 deletions thunar-gpg-encrypt-and-sign.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
#
# List available public recipient keys, encrypt the file/folder
# for the specified recipient by his/her public key and sign it
# with your own key.
#
# * Put this file into your home binary dir: ~/bin/
# * Make it executable: chmod +x
#
#
# Required Software:
# -------------------------
# * gpg
# * zenity
#
#
# Thunar Integration
# ------------------------
#
# Command: ~/bin/thunar-gpg-encrypt.sh -f %f
# File Pattern: *
# Appear On: Select everything
#
#
# Usage:
# -------------------------
# thunar-gpg-encrypt.sh -f <filename>/<directory>
#
# required:
# -f input filename/directory
#
# Note:
# -------------------------
#
# Feel free to adjust/improve and commit back to:
# https://github.com/cytopia/thunar-custom-actions
#


DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

source $DIR/thunar-gpg-functions.sh

checkCommandLineArg "$@"
checkBinaryReq


################################################################################
#
# Main entry point
#
################################################################################

r="$(chooseRecipient)"
if [ -z "${r}" ]; then
zenity --error --text="No Recipient specified."
exit 1
fi
# fix zenity bug on double click
# https://bugzilla.gnome.org/show_bug.cgi?id=698683
r="$(echo "${r}" | awk '{split($0,a,"|"); print a[1]}')"



u="$(chooseSecret)"
if [ -z "${u}" ]; then
zenity --error --text="No Secret key specified."
exit 1
fi
# fix zenity bug on double click
# https://bugzilla.gnome.org/show_bug.cgi?id=698683
u="$(echo "${u}" | awk '{split($0,a,"|"); print a[1]}')"

# Encrypt folder
if [ -d "${f}" ]; then
parentdir="$(dirname "${f}")"
directory="$(basename "${f}")"

error="$(tar c -C "${parentdir}" "${directory}" | gpg -e -s --yes --batch --local-user "${u}" --recipient "${r}" -o "${parentdir}/${directory}.tar.gpg" 2>&1)"
errno=$?
else
error="$(gpg -e -s --yes --batch --local-user "${u}" --recipient "${r}" "${f}" 2>&1)"
errno=$?
fi

if [ "$errno" -gt "0" ]; then
zenity --error --text="${error}\nreturn code: ${errno}"
exit 1
else
zenity --info --text="Encrypted."
exit $?
fi

Loading