-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto.sh
executable file
·55 lines (47 loc) · 956 Bytes
/
crypto.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
#! /usr/bin/env bash
function enc() {
prompt_if_file_exists .env.enc
zypher encrypt -o .env.enc -f .env
}
function dec() {
prompt_if_file_exists .env
zypher decrypt -o .env -f .env.enc
}
function hash() {
htpasswd -bnBC 10 "" "$1" | tr -d ':\n'
}
function prompt_if_file_exists() {
if [ -f $1 ]; then
read -p "File $1 already exists. Do you want to overwrite it? [y/N] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
}
function help() {
echo "Usage: crypto.sh [enc|dec|hash] [plain-password]"
echo "Example: crypto.sh enc"
echo "Example: crypto.sh dec"
echo "Example: crypto.sh hash mypassword"
}
if ! command -v zypher &> /dev/null; then
echo "zypher is not installed. Please install it first with:"
echo 'go install github.com/vtno/zypher/cmd/[email protected]'
exit 1
fi
case $1 in
enc)
enc
;;
dec)
dec
;;
hash)
hash $2
;;
*)
help
;;
esac
exit 0