-
Notifications
You must be signed in to change notification settings - Fork 0
/
keystore
executable file
·78 lines (64 loc) · 2.12 KB
/
keystore
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
#!/usr/bin/env bash
# Command line utility to manage custom app keys and passwords.
# Intended to be a simple wrapper around key storage commands.
# Make sure this file is your PATH or symlink it to a file in your PATH
# e.g. ln -s app-secret-store/keystore ./keystore
# Also make sure to copy the lib sub-folder as well.
# Exit if errors encountered or trying to use an undeclared variable
# set -o nounset #-o errexit
BG_STATUS_LINE="$(tput setab 3)"
FG_STATUS_LINE="$(tput setaf 0)"
BG_BODY="$(tput setab 0)"
FG_BODY="$(tput setaf 2)"
echo -n ${BG_BODY}${FG_BODY}
script_path=$(realpath $(which keystore))
script_path=${script_path//\/keystore/}
source "$script_path/lib/_utility.sh"
source "$script_path/lib/_cursor_menus.sh"
# Check for local config, create default if it doesnt exist
KEYSTORE_CONFIG=./.keystore.config
if [ -f "$KEYSTORE_CONFIG" ]; then
echo "$KEYSTORE_CONFIG exist"
else
echo "$KEYSTORE_CONFIG does not exist"
create_default_config $KEYSTORE_CONFIG
fi
source $KEYSTORE_CONFIG
# Check for .keystore.keys file in current directory, if not there create it
KEYSTORE_FILE=./.keystore.keys
touch $KEYSTORE_FILE
if [ -z ${provider+x} ]; then provider="macos_keychain"; fi
readonly keystore_provider="$script_path/lib/provider_${provider}.sh"
# If using zsh ...
# The following code can/should be left commented out as the completions file
# only needs copied once or when/if it is changed
# ZSH_COMPLETIONS_DIR=~/.my-zsh-completions
# if [ -d "$ZSH_COMPLETIONS_DIR" ]; then
# completions_path=${script_path//\/keystore/\/_keystore}
# cp "$completions_path" "$ZSH_COMPLETIONS_DIR"
# fi
# Include the keystore provider
source $keystore_provider
# If no parameters are passed then use menu system
# The menu is expected to "exit 0"
if [ "$#" -lt 1 ]; then
source "$script_path/lib/_menus.sh"
fi
help() {
echo ""
echo "usage:"
echo ""
echo "keystore help"
echo "keystore add"
echo "keystore delete"
echo "keystore get"
echo ""
}
if [ "$#" -gt 3 ]; then
echo "Expected 1 or 2 arguments, the name of the function to perform and any argument to pass to it ..."
help
exit 0
fi
# call function
"$@"
exit 0