aboutsummaryrefslogtreecommitdiff
path: root/libexec/app-cat-conf
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/app-cat-conf')
-rwxr-xr-xlibexec/app-cat-conf47
1 files changed, 47 insertions, 0 deletions
diff --git a/libexec/app-cat-conf b/libexec/app-cat-conf
new file mode 100755
index 0000000..78d3c36
--- /dev/null
+++ b/libexec/app-cat-conf
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+if [[ $APPSH_HOME == "" ]]
+then
+ APPSH_HOME=`dirname "$0"`
+ APPSH_HOME=`cd "$APPSH_HOME/.." && pwd`
+fi
+
+set -e
+
+key_expr="[a-zA-Z][_a-zA-Z0-9]*"
+
+file=.app/config
+
+while getopts "f:n:" opt
+do
+ case $opt in
+ f)
+ file=$OPTARG
+ ;;
+ n)
+ name=$OPTARG
+ ;;
+ \?)
+ echo "Invalid option: $OPTARG" >&2
+ exit 1
+ ;;
+ esac
+done
+
+if [ -z "$name" ]
+then
+ filter="s,^[ ]*\($key_expr\.$key_expr\)[ ]*=[ ]*\(.*\)$,\1=\2,p"
+else
+ filter="s,^\($name\)=\(.*\),\1=\2,p"
+fi
+
+if [[ $APPSH_DEFAULT_CONFIG == "" ]]
+then
+ APPSH_DEFAULT_CONFIG=$APPSH_HOME/lib/default-config
+fi
+
+# The awk script makes sure each key only appears once
+cat "$file" "$APPSH_DEFAULT_CONFIG" | \
+ sed -n -e "$filter" $extra | \
+ awk -F = ' (!($1 in a)){a[$1]; print }' | \
+ sort