blob: 5c550c1f7021da99d4a9d99137092d20b6ec749c (
plain)
- #!/bin/sh
- # Load settings
- set -e
- . ./defaults.cfg || exit 1
- 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
- }
- . `findsettings host hosts $host`
- . `findsettings target targets $target`
- . ./defaults-aftermath.cfg || exit 1
|