12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #!/bin/sh
- set -e
- NEW_DIR="$1"
- OLD_DIR="$2"
- [ "$OLD_DIR" ] || OLD_DIR='/var/lib/vblade-persist/vblades/'
- [ "$NEW_DIR" ] || NEW_DIR='/etc/vblade.conf.d/'
- [ -d "$OLD_DIR" ] || exit 0
- mkdir -p "$NEW_DIR"
- for d in $(find "$OLD_DIR" -mindepth 1 -maxdepth 1 -type d | sort) ; do
- [ -d "$d" ] || continue
- for f in NETIF SHELF SLOT SOURCE ; do
- [ -f "$d/env/$f" ] && continue
- echo "E: Incomplete vblade-persist configuration at '$d', 'env/$f' is missing"
- continue 2
- done
- OLDNAME="$(basename "$d")"
- INSTANCE="vblade.persist.$OLDNAME.conf"
- echo "I: Processing $OLDNAME, will store as $INSTANCE"
- if [ -e "$NEW_DIR/$INSTANCE" ] ; then
- echo "E: A vblade configuration '$NEW_DIR/$INSTANCE' already exists, skipping"
- continue
- fi
- TEMP="$(mktemp --tmpdir="$NEW_DIR" "$INSTANCE.XXXXX")"
- trap "[ -f \"$TEMP\" ] && rm \"$TEMP\"" EXIT
- (
- cat <<__EOS__
- #
- # Created by $(basename "$0") on $(date)
- #
- Shelf=$(cat "$d/env/SHELF")
- Slot=$(cat "$d/env/SLOT")
- NetIf=$(cat "$d/env/NETIF")
- Filename=$(cat "$d/env/SOURCE")
- Options=$(
- if [ -d "$d/macs" ] ; then
- macs="$(
- find "$d/macs" -type f -iname '[0-9a-f]*' -printf '%f,' |
- sort |
- sed -e 's/,$//'
- )"
- if [ "$macs" ] ; then
- printf '"-m %s"' "$macs"
- fi
- fi
- )
- # IOSchedulingClass=
- # IOSchedulingPriority=
- __EOS__
- ) >"$TEMP"
- if ! sh -n "$TEMP" ; then
- echo "F: Conversion of '$d' failed, checking the following script failed:"
- cat "$TEMP" | sed -e 's/^/| /'
- rm "$TEMP"
- exit 1
- fi
- mv "$TEMP" "$NEW_DIR/$INSTANCE"
- done
- exit 0
|