1 |
183
|
aaronmk
|
#!/bin/bash
|
2 |
131
|
aaronmk
|
# Sets a password environment variable
|
3 |
|
|
|
4 |
291
|
aaronmk
|
self="$(readlink -f -- "$BASH_SOURCE")"
|
5 |
|
|
|
6 |
292
|
aaronmk
|
noInstr=
|
7 |
|
|
test _"$1" = _- && { noInstr=1; shift;}
|
8 |
|
|
|
9 |
251
|
aaronmk
|
test "$#" -ge 1 || \
|
10 |
291
|
aaronmk
|
{ echo "Usage: . $self env_var_name [msg] (note initial \".\")" >&2; exit 2;}
|
11 |
131
|
aaronmk
|
|
12 |
251
|
aaronmk
|
msg="$2"
|
13 |
|
|
test -n "$msg" || msg="$1"
|
14 |
|
|
|
15 |
290
|
aaronmk
|
function trace()
|
16 |
|
|
{
|
17 |
|
|
{ for arg in "$@"; do printf "%q " "$arg"; done; echo;} >&2
|
18 |
|
|
}
|
19 |
|
|
|
20 |
131
|
aaronmk
|
if test -z "${!1+t}"; then # env var with name $1 is unset
|
21 |
292
|
aaronmk
|
if test -z "$noInstr"; then
|
22 |
|
|
echo "[7m To avoid having to reenter $msg password, run: [0m" >&2
|
23 |
|
|
trace . "$self" - "$@"
|
24 |
|
|
fi
|
25 |
251
|
aaronmk
|
read -s -p "Enter $msg password: "; echo
|
26 |
131
|
aaronmk
|
export "$1"="$REPLY"
|
27 |
|
|
fi
|