diff --git a/template.sh b/template.sh index 37ca475..a05dc72 100755 --- a/template.sh +++ b/template.sh @@ -1,5 +1,12 @@ #!/bin/bash -e +file= +if test -e "${!#}"; then + for var in $(sed -n 's,^ *# \+\(-p\|--pwd\) \+\([a-zA-Z][a-zA-Z0-9_]*\),\2,p' "${!#}"); do + export ${var}=$(pwgen 40 1) + done +fi + while test $# -gt 0; do case "$1" in (-h|--help) if test -e "${!#}"; then @@ -19,7 +26,11 @@ OPTIONS -v, --var name=value Set environment variable to be used in the template. - -p, --pwd name Generate a random password with the given name. + -p, --pwd name Generate a random password with the given name. + If a password is documented, then it does not + need to be specified. But automated + generation can be overwritten assigning a + value using option -v. FILE @@ -115,8 +126,8 @@ EOF exit 1 fi;; (*) if test $# -ne 1 -o ! -e "$1"; then - echo "ERROR please specify exactly one template file $*" 1>&2 - echo " this not a template file: $*" 1>&2 + echo "ERROR please specify exactly one template file" 1>&2 + echo " this not one template file: $*" 1>&2 echo " see: $0 --help" 1>&2 exit 1 fi