summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjonas <jonas@8f53b18a-e215-0410-8885-9f593d34873e>2006-10-15 19:28:25 +0000
committerjonas <jonas@8f53b18a-e215-0410-8885-9f593d34873e>2006-10-15 19:28:25 +0000
commit288fa1d1d653176461d0767beb5cdd8219920b2b (patch)
tree45dddabc471cbdf24d0617805a915244fd92c548
parentacdcf22d588a5e28633d8519e6196f035d083864 (diff)
Major rewrite to more generically load chunks of settings either from local or shared files.
git-svn-id: svn+ssh://xayide/home/jonas/private_svn/fleshybrid/homebase@41 8f53b18a-e215-0410-8885-9f593d34873e
-rw-r--r--common-settings78
1 files changed, 52 insertions, 26 deletions
diff --git a/common-settings b/common-settings
index b39952a..5c550c1 100644
--- a/common-settings
+++ b/common-settings
@@ -6,32 +6,58 @@ set -e
. ./defaults.cfg || exit 1
-shareddir="hosts"
-sharedfile="host"
-customfile="host.cfg"
-if [ -f "$customfile" ]; then
- if [ -f "$sharedfile" ]; then
- echo "W: Ignoring shared host config \"$sharedfile\" - using custom \"$customfile\" instead."
- fi
- . "$customfile"
-elif [ -f "$sharedfile" ]; then
- . "$shareddir"/`cat "$sharedfile" |head -1`
-else
- echo "E: No host config found - either mention shared host config in \"$sharedfile\" or write custom file \"$customfile\"."
-fi
-
-shareddir="targets"
-sharedfile="target"
-customfile="target.cfg"
-if [ -f "$customfile" ]; then
- if [ -f "$sharedfile" ]; then
- echo "W: Ignoring shared target config \"$sharedfile\" - using custom \"$customfile\" instead."
+readref() {
+ ref="$1"
+
+ cat "$ref" |head -1
+}
+
+findsettingsdir() {
+ ref="$1"; shift
+
+ for dir in $@; do
+ result="`find "$dir" -mindepth 1 -maxdepth 1 -type f -name "$ref" -printf '%h\n'`"
+ [ -z "$result" ] && continue
+ echo $result
+ exit 0
+ done
+ exit 1
+}
+
+findsettings() {
+ context="$1"
+ settingsfile="$context.cfg"
+ reffile="$context"
+ shareddir="$2"
+ ref="$3"
+
+ # Local settings
+ if [ -f "$settingsfile" ]; then
+ echo "$settingsfile"
+ # Local reference
+ elif [ -f "$reffile" ]; then
+ if settingsfile="`readref "$reffile"`" && settingsdir="`findsettingsdir "$settingsfile" "$shareddir"`" && [ -f "$settingsdir/$settingsfile" ]; then
+ echo "$settingsdir/$settingsfile"
+ else
+ echo >&2 "E: Failed setting $context: Unable to resolve the settings file from the file \"$reffile\"."
+ exit 1
+ fi
+ # Reference chained from earlier settings
+ elif [ -n "$ref" ]; then
+ settingsfile="$ref"
+ if settingsdir="`findsettingsdir "$settingsfile" "$shareddir"`" && [ -f "$settingsdir/$settingsfile" ]; then
+ echo "$settingsdir/$settingsfile"
+ else
+ echo >&2 "E: Failed setting $context: Unable to locate settings file \"$ref\"."
+ exit 1
+ fi
+ else
+ echo >&2 "E: No $context config found - refer to a shared settings file in the file \"$reffile\" or write a custom settings file \"$settingsfile\"."
+ exit 1
fi
- . "$customfile"
-elif [ -f "$sharedfile" ]; then
- . "$shareddir"/`cat "$sharedfile" |head -1`
-else
- echo "E: No target config found - either mention shared host config in \"$sharedfile\" or write custom file \"$customfile\"."
-fi
+}
+
+. `findsettings host hosts $host`
+. `findsettings target targets $target`
. ./defaults-aftermath.cfg || exit 1