-
Notifications
You must be signed in to change notification settings - Fork 0
/
crptest
executable file
·42 lines (37 loc) · 1.37 KB
/
crptest
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
#!/bin/bash
# general encryption-decryption test
# ecrypt encrypts all files in the given directory
# dcrypt decrypts back all the encrypted files
PROGN=${0##*/}
# make this output unique to facilitate git commit working in
# automated tests run at github actions:
printf "$PROGN run on: %s %s %s %s\n\n" $( date -u "+%d.%m.%y at %H:%M:%S %Z" )
case $# in
0)
printf "$PROGN quitting, requires a path argument\n" >&2
exit 2;;
1)
if ! [ -d "$1" ]; then
printf "$PROGN quitting, input directory name $1 not found\n" >&2
exit 2; fi;;
*)
printf "$PROGN quitting, too many arguments, needs just one input path\n" >&2
exit 2;;
esac
# directory names, preceding path is stripped off, so all output goes to ./
KEYDIR=_"$1"key # must separate _ from the variable name
OUTDIR=_"$1"crypt
ORGDIR=_"$1"org
# check that outputs directories do not already exist
if [ -d "$KEYDIR" ]; then
printf "$PROGN quitting, '$KEYDIR' already exists here!\n" >&2; exit 2; fi
if [ -d "$OUTDIR" ]; then
printf "$PROGN quitting, '$OUTDIR' already exists here!\n" >&2; exit 2; fi
if [ -d "$ORGDIR" ]; then
printf "$PROGN quitting, '$ORGDIR' already exists here!\n" >&2; exit 2; fi
# encrypt and decrypt
ncrpt -xbr $1 $KEYDIR $OUTDIR
printf "\n"
dcrpt $OUTDIR $KEYDIR $ORGDIR
diff -bqr "$1" "$ORGDIR" && printf "\n$PROGN diff: '$1' and '$ORGDIR' are identical\n"
rm -rf "$ORGDIR" "$OUTDIR" "$KEYDIR" >&2