forked from cytopia/thunar-custom-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thunar-gpg-encrypt.sh
executable file
·80 lines (70 loc) · 1.76 KB
/
thunar-gpg-encrypt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#
# List available public recipient keys, encrypt the file/folder
# for the specified recipient by his/her public 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]}')"
# Encrypt folder
if [ -d "${f}" ]; then
parentdir="$(dirname "${f}")"
directory="$(basename "${f}")"
error="$(tar c -C "${parentdir}" "${directory}" | gpg -e --yes --batch --recipient "${r}" -o "${parentdir}/${directory}.tar.gpg" 2>&1)"
errno=$?
else
error="$(gpg -e --yes --batch --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