-
Notifications
You must be signed in to change notification settings - Fork 1
/
likrura.bash
90 lines (74 loc) · 1.71 KB
/
likrura.bash
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
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
set -eo pipefail; [[ $TRACE ]] && set -x
readonly VERSION="1.0.0"
readonly OPENSSL_CIPHER_TYPE="aes-256-cbc"
likru_version() {
echo "likrura $VERSION"
}
likru_help() {
echo "Usage: cryptr command <command-specific-options>"
echo
cat<<EOF | column -c2 -t -s,
encrypt <file>, Encrypt file
decrypt <file.aes>, Decrypt encrypted file
help, Displays help
version, Displays the current version
EOF
echo
}
likru_kru() {
local _file="$1"
if [[ ! -f "$_file" ]]; then
echo "File not found" 1>&2
exit 4
fi
if [[ ! -z "${LIKRU_PASSWORD}" ]]; then
echo "[notice] using environment variable CRYPTR_PASSWORD for the password"
openssl $OPENSSL_CIPHER_TYPE -salt -pbkdf2 -in "$_file" -out "${_file}.aes" -pass env:LIKRU_PASSWORD
else
openssl $OPENSSL_CIPHER_TYPE -salt -pbkdf2 -in "$_file" -out "${_file}.aes"
fi
}
likru_dru() {
local _file="$1"
if [[ ! -f "$_file" ]]; then
echo "File not found" 1>&2
exit 5
fi
if [[ ! -z "${LIKRU_PASSWORD}" ]]; then
echo "[notice] using environment variable LIKRU_PASSWORD for the password"
openssl $OPENSSL_CIPHER_TYPE -d -salt -pbkdf2 -in "$_file" -out "${_file%\.aes}" -pass env:CRYPTR_PASSWORD
else
openssl $OPENSSL_CIPHER_TYPE -d -salt -pbkdf2 -in "$_file" -out "${_file%\.aes}"
fi
}
likru_main() {
local _command="$1"
if [[ -z $_command ]]; then
likru_version
echo
likru_help
exit 0
fi
shift 1
case "$_command" in
"kru")
likru_kru "$@"
;;
"dru")
likru_dru "$@"
;;
"version")
likru_version
;;
"help")
likru_help
;;
*)
likru_help 1>&2
exit 3
esac
}
if [[ "$0" == "$BASH_SOURCE" ]]; then
likru_main "$@"
fi