From 501df8a9484b3ab17198131aa6204164dd0b4752 Mon Sep 17 00:00:00 2001 From: mwaeckerlin Date: Wed, 27 Sep 2017 11:26:46 +0200 Subject: [PATCH] added simple yaml template file processor --- template.sh | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 template.sh diff --git a/template.sh b/template.sh new file mode 100755 index 0000000..d781f47 --- /dev/null +++ b/template.sh @@ -0,0 +1,112 @@ +#!/bin/bash -e + +while test $# -gt 0; do + case "$1" in + (-h|--help) cat < my-site.yaml + +EOF + exit;; + (-v|--var) shift; + if [[ $1 =~ ^[a-zA-Z][a-zA-Z0-9_]*= ]]; then + export $1 + else + echo "ERROR not a variable assignment: $1" 1>&2 + echo " see: $0 --help" 1>&2 + exit 1 + fi;; + (-p|--pwd) shift; + if [[ $1 =~ ^[a-zA-Z][a-zA-Z0-9_]*$ ]]; then + export $1=$(pwgen 40 1) + else + echo "ERROR not a variable name: $1" 1>&2 + echo " see: $0 --help" 1>&2 + 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 " see: $0 --help" 1>&2 + exite + fi + file="$1"; + esac + if test $# -lt 1; then + echo "ERROR too few arguments" 1>&2 + echo " see: $0 --help" 1>&2 + exit 1 + fi + shift +done + +if ! test -e "$file"; then + echo "ERROR please specify a template file" 1>&2 + echo " see: $0 --help" 1>&2 + exit 1 +fi + +eval "cat <