summaryrefslogtreecommitdiff
path: root/common-settings
blob: 5c550c1f7021da99d4a9d99137092d20b6ec749c (plain)
  1. #!/bin/sh
  2. # Load settings
  3. set -e
  4. . ./defaults.cfg || exit 1
  5. readref() {
  6. ref="$1"
  7. cat "$ref" |head -1
  8. }
  9. findsettingsdir() {
  10. ref="$1"; shift
  11. for dir in $@; do
  12. result="`find "$dir" -mindepth 1 -maxdepth 1 -type f -name "$ref" -printf '%h\n'`"
  13. [ -z "$result" ] && continue
  14. echo $result
  15. exit 0
  16. done
  17. exit 1
  18. }
  19. findsettings() {
  20. context="$1"
  21. settingsfile="$context.cfg"
  22. reffile="$context"
  23. shareddir="$2"
  24. ref="$3"
  25. # Local settings
  26. if [ -f "$settingsfile" ]; then
  27. echo "$settingsfile"
  28. # Local reference
  29. elif [ -f "$reffile" ]; then
  30. if settingsfile="`readref "$reffile"`" && settingsdir="`findsettingsdir "$settingsfile" "$shareddir"`" && [ -f "$settingsdir/$settingsfile" ]; then
  31. echo "$settingsdir/$settingsfile"
  32. else
  33. echo >&2 "E: Failed setting $context: Unable to resolve the settings file from the file \"$reffile\"."
  34. exit 1
  35. fi
  36. # Reference chained from earlier settings
  37. elif [ -n "$ref" ]; then
  38. settingsfile="$ref"
  39. if settingsdir="`findsettingsdir "$settingsfile" "$shareddir"`" && [ -f "$settingsdir/$settingsfile" ]; then
  40. echo "$settingsdir/$settingsfile"
  41. else
  42. echo >&2 "E: Failed setting $context: Unable to locate settings file \"$ref\"."
  43. exit 1
  44. fi
  45. else
  46. echo >&2 "E: No $context config found - refer to a shared settings file in the file \"$reffile\" or write a custom settings file \"$settingsfile\"."
  47. exit 1
  48. fi
  49. }
  50. . `findsettings host hosts $host`
  51. . `findsettings target targets $target`
  52. . ./defaults-aftermath.cfg || exit 1