30 lines
522 B
Bash
Executable File
30 lines
522 B
Bash
Executable File
#!/bin/sh
|
|
|
|
[ -f /etc/nbdtab ] || exit 0
|
|
|
|
# shellcheck disable=SC2046
|
|
set -- $(cat /proc/cmdline)
|
|
while [ $# -ge 1 ]; do
|
|
case "$1" in
|
|
root=nbd:*)
|
|
arg=${1#*:}
|
|
host=${arg%:*}
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
[ -n "${host}" ] || exit 0
|
|
|
|
serial=$(sed -nr '/Serial/s/.*([0-9a-f]{8})/\1/p' /proc/cpuinfo)
|
|
if [ $? -ne 0 ]; then
|
|
serial=UNKNOWN-SERIAL
|
|
fi
|
|
sed \
|
|
-e s/@NBDHOST@/"${host}"/ \
|
|
-e s/@SERIAL@/"${serial}"/ \
|
|
/etc/nbdtab \
|
|
> /run/nbdtab
|
|
|
|
mount -o bind /run/nbdtab /etc/nbdtab
|