Refactor start-qemu ports handling to allow for user-specified port mappings
This commit is contained in:
parent
e1366bdec9
commit
1eb2e0f60d
|
@ -12,4 +12,7 @@
|
||||||
-v /home/jsmith/downloads/debian.iso:/tmp/debian.iso:ro \
|
-v /home/jsmith/downloads/debian.iso:/tmp/debian.iso:ro \
|
||||||
-e QEMU_CDROM=/tmp/debian.iso \
|
-e QEMU_CDROM=/tmp/debian.iso \
|
||||||
-e QEMU_BOOT='order=d' \
|
-e QEMU_BOOT='order=d' \
|
||||||
|
-e QEMU_PORTS='2375 2376' \
|
||||||
tianon/qemu
|
tianon/qemu
|
||||||
|
|
||||||
|
Note: port 22 will always be mapped (regardless of the contents of `QEMU_PORTS`).
|
||||||
|
|
11
start-qemu
11
start-qemu
|
@ -8,11 +8,13 @@ set -e
|
||||||
# QEMU_HDA_SIZE (bytes, suffixes like "G" allowed)
|
# QEMU_HDA_SIZE (bytes, suffixes like "G" allowed)
|
||||||
# QEMU_CDROM (filename)
|
# QEMU_CDROM (filename)
|
||||||
# QEMU_BOOT (-boot)
|
# QEMU_BOOT (-boot)
|
||||||
|
# QEMU_PORTS="xxx[ xxx ...]" (space separated port numbers)
|
||||||
|
|
||||||
hostArch="$(uname -m)"
|
hostArch="$(uname -m)"
|
||||||
qemuArch="${QEMU_ARCH:-$hostArch}"
|
qemuArch="${QEMU_ARCH:-$hostArch}"
|
||||||
qemu="${QEMU_BIN:-qemu-system-$qemuArch}"
|
qemu="${QEMU_BIN:-qemu-system-$qemuArch}"
|
||||||
qemuArgs=()
|
qemuArgs=()
|
||||||
|
qemuPorts=( 22 $QEMU_PORTS )
|
||||||
|
|
||||||
if [ -e /dev/kvm ]; then
|
if [ -e /dev/kvm ]; then
|
||||||
qemuArgs+=( -enable-kvm )
|
qemuArgs+=( -enable-kvm )
|
||||||
|
@ -46,9 +48,16 @@ if [ "$QEMU_BOOT" ]; then
|
||||||
qemuArgs+=( -boot "$QEMU_BOOT" )
|
qemuArgs+=( -boot "$QEMU_BOOT" )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
netArg='user'
|
||||||
|
netArg+=",hostname=$(hostname)"
|
||||||
|
for port in "${qemuPorts[@]}"; do
|
||||||
|
netArg+=",hostfwd=tcp::$port-:$port"
|
||||||
|
netArg+=",hostfwd=udp::$port-:$port"
|
||||||
|
done
|
||||||
|
|
||||||
qemuArgs+=(
|
qemuArgs+=(
|
||||||
-net nic
|
-net nic
|
||||||
-net user,hostname="$(hostname)",hostfwd=tcp:':22'-':22'
|
-net "$netArg"
|
||||||
-vnc ':0'
|
-vnc ':0'
|
||||||
-serial stdio
|
-serial stdio
|
||||||
"$@"
|
"$@"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user