From 8b1d11508e985cc2cd97a1d70d01574e78109569 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 9 Oct 2012 18:49:27 +0200 Subject: o Reworked app starting. --- .app/lib/app-conf | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to '.app/lib/app-conf') diff --git a/.app/lib/app-conf b/.app/lib/app-conf index 141524d..b1b06c0 100644 --- a/.app/lib/app-conf +++ b/.app/lib/app-conf @@ -3,8 +3,11 @@ key_expr="[a-zA-Z][_a-zA-Z0-9]*\.[a-zA-Z][_a-zA-Z0-9]*" get_conf() { - local key=$1 - local default=$2 + local BASEDIR=$1 + local name=$2 + local instance=$3 + local key=$4 + local default=$5 local file=$BASEDIR/$name/$instance/current/etc/app.conf if [ ! -r $file ] @@ -24,6 +27,9 @@ get_conf() { } get_conf_all() { + local BASEDIR=$1 + local name=$2 + local instance=$3 local file=$BASEDIR/$name/$instance/current/etc/app.conf if [ ! -r $file ] @@ -35,9 +41,13 @@ get_conf_all() { } get_conf_in_group() { - prefix=$1 + local BASEDIR=$1 + local name=$2 + local instance=$3 + local prefix=$1 - get_conf_all | sed -n "s,^[ ]*${prefix}\.\([._a-zA-Z]*\)=\(.*\)$,\1=\2,p" + get_conf_all "$BASEDIR" "$name" "$instance" | \ + sed -n "s,^[ ]*${prefix}\.\([._a-zA-Z]*\)=\(.*\)$,\1=\2,p" } assert_key() { @@ -52,8 +62,12 @@ assert_key() { } conf_set() { - local key=$1 - local value=$2 + local BASEDIR=$1 + local name=$2 + local instance=$3 + local key=$4 + local value=$5 + local file=$BASEDIR/$name/$instance/current/etc/app.conf assert_key "$key" @@ -68,7 +82,10 @@ conf_set() { } conf_delete() { - key=$1 + local BASEDIR=$1 + local name=$2 + local instance=$3 + local key=$4 local file=$BASEDIR/$name/$instance/current/etc/app.conf @@ -92,6 +109,8 @@ conf_usage() { } method_conf() { + local name + local instance local mode="list" while getopts "n:i:s:d:" opt @@ -124,17 +143,17 @@ method_conf() { case $mode in list) - get_conf_all | (IFS==; while read key value + get_conf_all "$BASEDIR" "$name" "$instance" | (IFS==; while read key value do printf "%-20s %-20s" "$key" "$value" echo done) ;; set) - conf_set "$key" "$value" + conf_set "$BASEDIR" "$name" "$instance" "$key" "$value" ;; delete) - conf_delete "$key" + conf_delete "$BASEDIR" "$name" "$instance" "$key" ;; esac } -- cgit v1.2.3