Revision 1090
Added by Aaron Marcuse-Kubitza almost 13 years ago
bin/env_password | ||
---|---|---|
3 | 3 |
|
4 | 4 |
self="$(readlink -f -- "$BASH_SOURCE")" |
5 | 5 |
|
6 |
force=
|
|
7 |
test _"$1" = _- && { force=1; shift;}
|
|
6 |
out=/dev/tty
|
|
7 |
function echo2() { echo "$@" >"$out";}
|
|
8 | 8 |
|
9 |
test "$#" -ge 1 || \
|
|
10 |
{ echo "Usage: . $self env_var_name [msg] (note initial \".\")" >&2; exit 2;}
|
|
9 |
store=
|
|
10 |
test _"$1" = _- && { store=1; shift;}
|
|
11 | 11 |
|
12 |
msg="$2" |
|
13 |
test -n "$msg" || msg="$1" |
|
12 |
if ! test "$#" -ge 1; then |
|
13 |
echo2 "Usage: . $self env_var [desc] (note initial \".\")"|fold -s >"$out" |
|
14 |
exit 2 |
|
15 |
fi |
|
14 | 16 |
|
17 |
desc="$2" |
|
18 |
test -n "$desc" || desc="the $1 password" |
|
19 |
|
|
15 | 20 |
function trace() |
16 | 21 |
{ |
17 |
{ for arg in "$@"; do printf "%q " "$arg"; done; echo;} >&2
|
|
22 |
{ for arg in "$@"; do printf "%q " "$arg"; done; echo;} >"$out"
|
|
18 | 23 |
} |
19 | 24 |
|
20 |
if test -n "$force" -o -z "${!1+t}"; then # env var with name $1 is unset |
|
21 |
if test -n "$force"; then action="change the saved value for" |
|
22 |
else action="avoid having to reenter" |
|
25 |
if test -n "$store" -o -z "${!1+t}"; then # env var with name $1 is unset |
|
26 |
if test -n "$store"; then |
|
27 |
echo2 "[7m To change the saved value for $desc, run: [0m" >"$out" |
|
28 |
else |
|
29 |
echo2 "[101;97m You must first store $desc. At the shell, run: [39;49m" |
|
23 | 30 |
fi |
24 |
echo "[7m To $action $msg password, run: [0m" >&2 |
|
25 | 31 |
trace . "$self" - "$@" |
26 | 32 |
|
27 |
read -s -p "Enter $msg password: "; echo |
|
33 |
test -z "$store" && exit 1 # just direct user how to store password |
|
34 |
read -s -p "Enter $desc password: " 2>"$out"; echo2 |
|
28 | 35 |
export "$1"="$REPLY" |
29 | 36 |
fi |
map | ||
---|---|---|
13 | 13 |
test -n "$in_host" || export in_host=localhost |
14 | 14 |
if test -z "$in_user"; then |
15 | 15 |
if test _"$(hostname)" = _nimoy -a _"$in_engine" = _MySQL; then |
16 |
test -n "${mysql_password+t}" || \
|
|
17 |
. "$binDir/env_password" mysql_password "your MySQL"
|
|
16 |
. "$binDir/env_password" mysql_password "your MySQL password"
|
|
17 |
# will exit this script if password not set
|
|
18 | 18 |
export in_user="$USER" in_password="$mysql_password" |
19 | 19 |
if test "$in_database" = SALVIAS; then in_database=salvias_plots |
20 | 20 |
elif test "$in_database" = NYBG; then in_database=bien2_staging |
Also available in: Unified diff
env_password: Print all messages to /dev/tty so the user sees them even if stderr is redirected to a log file. Exit if password not already set, because e.g. scripts run in the background will not be able to prompt for it.