Revision 1091
Added by Aaron Marcuse-Kubitza almost 13 years ago
env_password | ||
---|---|---|
3 | 3 |
|
4 | 4 |
self="$(readlink -f -- "$BASH_SOURCE")" |
5 | 5 |
|
6 |
out=/dev/tty |
|
7 |
function echo2() { echo "$@" >"$out";} |
|
8 |
|
|
6 |
test -t 2 && ccTty= || ccTty=1 # cc the tty if stderr is a log file |
|
7 |
{ |
|
9 | 8 |
store= |
10 | 9 |
test _"$1" = _- && { store=1; shift;} |
11 | 10 |
|
12 | 11 |
if ! test "$#" -ge 1; then |
13 |
echo2 "Usage: . $self env_var [desc] (note initial \".\")"|fold -s >"$out"
|
|
12 |
echo "Usage: . $self env_var [desc] (note initial \".\")"|fold -s
|
|
14 | 13 |
exit 2 |
15 | 14 |
fi |
16 | 15 |
|
... | ... | |
19 | 18 |
|
20 | 19 |
function trace() |
21 | 20 |
{ |
22 |
{ for arg in "$@"; do printf "%q " "$arg"; done; echo;} >"$out"
|
|
21 |
{ for arg in "$@"; do printf "%q " "$arg"; done; echo;} |
|
23 | 22 |
} |
24 | 23 |
|
25 | 24 |
if test -n "$store" -o -z "${!1+t}"; then # env var with name $1 is unset |
26 | 25 |
if test -n "$store"; then |
27 |
echo2 "[7m To change the saved value for $desc, run: [0m" >"$out"
|
|
26 |
echo "[7m To change the saved value for $desc, run: [0m"
|
|
28 | 27 |
else |
29 |
echo2 "[101;97m You must first store $desc. At the shell, run: [39;49m"
|
|
28 |
echo "[101;97m You must first store $desc. At the shell, run: [39;49m" |
|
30 | 29 |
fi |
31 | 30 |
trace . "$self" - "$@" |
32 | 31 |
|
33 | 32 |
test -z "$store" && exit 1 # just direct user how to store password |
34 |
read -s -p "Enter $desc password: " 2>"$out"; echo2
|
|
33 |
read -s -p "Enter $desc: "; echo
|
|
35 | 34 |
export "$1"="$REPLY" |
36 | 35 |
fi |
36 |
} 2>&1|tee ${ccTty:+/dev/tty} >&2 |
Also available in: Unified diff
env_password: cc stderr if it's a log file