board_detect 490 B

12345678910111213141516171819202122
  1. #!/bin/sh
  2. REAL_CFG=$1
  3. [ -n "$REAL_CFG" ] || REAL_CFG=/etc/board.json
  4. if [ -d "/etc/board.d/" ] && [ ! -s "$REAL_CFG" ]; then
  5. # Use temp file to prevent incomplete file on power-cut, CFG is used by the sourced script to read/write the file
  6. CFG="$(dirname "$REAL_CFG")/.$(basename "$REAL_CFG").tmp"
  7. rm -f "$CFG" || exit
  8. for a in $(ls /etc/board.d/*); do
  9. [ -s "$a" ] || continue
  10. (. "$a")
  11. done
  12. fi
  13. if [ -s "$CFG" ]; then
  14. mv "$CFG" "$REAL_CFG" || exit
  15. else
  16. rm -f "$CFG"
  17. exit 1
  18. fi