forked from okigan/e7z
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e7z
executable file
·54 lines (43 loc) · 1.12 KB
/
e7z
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
#!/bin/bash
command=
key=
while [ $# -gt 0 ]
do
case $1 in
a) command=a; ;;
x) command=x; ;;
-k) key=$2; shift ;;
-*)
echo >&2 "usage: $0 a|x -k keyfile ..."
exit 1;;
*) break;; # terminate while loop
esac
shift
done
echo command=$command
echo key=$key
encryptedPasswordFile=archivePassword.ssl
archiveCommand=/usr/bin/7z
case $command in
a)
input=*.txt
output=test.7z
archivePassword=`makepasswd --chars=30`
echo "Archive password: $archivePassword"
# openssl rsa -in .ssh/id_rsa -pubout -outform PEM > key.pub
echo $archivePassword | openssl rsautl -encrypt -inkey $key -pubin -out $encryptedPasswordFile
trap "rm -f $encryptedPasswordFile" EXIT
$archiveCommand a $output $encryptedPasswordFile
$archiveCommand u -p$archivePassword $output $input
;;
x)
input=*.txt
output=test.7z
$archiveCommand e $output $encryptedPasswordFile
trap "rm -f $encryptedPasswordFile" EXIT
archivePassword=`openssl rsautl -decrypt -inkey $key -in $encryptedPasswordFile`
echo "Archive password: $archivePassword"
$archiveCommand x -p$archivePassword $output
;;
esac
exit 0