vblade-persist-convert 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. set -e
  3. NEW_DIR="$1"
  4. OLD_DIR="$2"
  5. [ "$OLD_DIR" ] || OLD_DIR='/var/lib/vblade-persist/vblades/'
  6. [ "$NEW_DIR" ] || NEW_DIR='/etc/vblade.conf.d/'
  7. [ -d "$OLD_DIR" ] || exit 0
  8. mkdir -p "$NEW_DIR"
  9. for d in $(find "$OLD_DIR" -mindepth 1 -maxdepth 1 -type d | sort) ; do
  10. [ -d "$d" ] || continue
  11. for f in NETIF SHELF SLOT SOURCE ; do
  12. [ -f "$d/env/$f" ] && continue
  13. echo "E: Incomplete vblade-persist configuration at '$d', 'env/$f' is missing"
  14. continue 2
  15. done
  16. OLDNAME="$(basename "$d")"
  17. INSTANCE="vblade.persist.$OLDNAME.conf"
  18. echo "I: Processing $OLDNAME, will store as $INSTANCE"
  19. if [ -e "$NEW_DIR/$INSTANCE" ] ; then
  20. echo "E: A vblade configuration '$NEW_DIR/$INSTANCE' already exists, skipping"
  21. continue
  22. fi
  23. TEMP="$(mktemp --tmpdir="$NEW_DIR" "$INSTANCE.XXXXX")"
  24. trap "[ -f \"$TEMP\" ] && rm \"$TEMP\"" EXIT
  25. (
  26. cat <<__EOS__
  27. #
  28. # Created by $(basename "$0") on $(date)
  29. #
  30. Shelf=$(cat "$d/env/SHELF")
  31. Slot=$(cat "$d/env/SLOT")
  32. NetIf=$(cat "$d/env/NETIF")
  33. Filename=$(cat "$d/env/SOURCE")
  34. Options=$(
  35. if [ -d "$d/macs" ] ; then
  36. macs="$(
  37. find "$d/macs" -type f -iname '[0-9a-f]*' -printf '%f,' |
  38. sort |
  39. sed -e 's/,$//'
  40. )"
  41. if [ "$macs" ] ; then
  42. printf '"-m %s"' "$macs"
  43. fi
  44. fi
  45. )
  46. # IOSchedulingClass=
  47. # IOSchedulingPriority=
  48. __EOS__
  49. ) >"$TEMP"
  50. if ! sh -n "$TEMP" ; then
  51. echo "F: Conversion of '$d' failed, checking the following script failed:"
  52. cat "$TEMP" | sed -e 's/^/| /'
  53. rm "$TEMP"
  54. exit 1
  55. fi
  56. mv "$TEMP" "$NEW_DIR/$INSTANCE"
  57. done
  58. exit 0