virtual-dsm/serial.sh

52 lines
1.8 KiB
Bash
Raw Normal View History

2023-03-28 06:45:24 +02:00
#!/bin/bash
2023-04-08 01:15:41 +02:00
# Docker environment variabeles
: ${HOST_SERIAL:=''}
: ${GUEST_SERIAL:=''}
2023-03-28 18:42:02 +02:00
permanent="DSM"
serialstart="2000"
2023-03-28 06:45:24 +02:00
2023-04-02 22:38:36 +02:00
IMG="/storage"
[ ! -d "$IMG" ] && echo "Storage folder (${IMG}) not found!" && exit 69
2023-04-08 01:15:41 +02:00
#If environment variabele not set fall back to file
if [ -z "$HOST_SERIAL" ]; then
FILE="${IMG}/host.serial"
if [ ! -f "$FILE" ]; then
SERIAL="$(echo "$serialstart" | tr ' ' '\n' | sort -R | tail -1)$permanent"$(printf "%06d" $((RANDOM % 30000 + 1)))
echo $SERIAL > "$FILE"
fi
HOST_SERIAL=$(cat "${FILE}")
2023-04-02 22:38:36 +02:00
fi
2023-04-08 01:15:41 +02:00
#If environment variabele not set fall back to file
if [ -z "$GUEST_SERIAL" ]; then
FILE="${IMG}/guest.serial"
if [ ! -f "$FILE" ]; then
SERIAL="$(echo "$serialstart" | tr ' ' '\n' | sort -R | tail -1)$permanent"$(printf "%06d" $((RANDOM % 30000 + 1)))
echo $SERIAL > "$FILE"
fi
GUEST_SERIAL=$(cat "${FILE}")
2023-04-02 22:38:36 +02:00
fi
2023-04-02 21:38:34 +02:00
2023-04-08 02:00:29 +02:00
CPU=$(lscpu | sed -nr '/Model name/ s/.*:\s*(.*) @ .*/\1/p' | sed ':a;s/ / /;ta' | sed s/"(R)"//g | sed s/"-"//g | sed 's/[^[:alnum:]]\+//g')
2023-04-08 01:30:25 +02:00
[ -z "$CPU" ] && CPU="QEMU, Virtual CPU, X86_64"
2023-04-08 02:00:29 +02:00
./run/serial.bin -cpu="${CPU_CORES}" \
-cpu_arch="${CPU}" \
2023-04-02 21:38:34 +02:00
-buildnumber=42962 \
2023-04-08 02:00:29 +02:00
-vmmts=1679863686 \
-hostsn="${HOST_SERIAL}" \
-guestsn="${GUEST_SERIAL}" \
2023-04-02 21:38:34 +02:00
-vmmversion="2.6.1-12139" \
-guestuuid="ba13a19a-c0c1-4fef-9346-915ed3b98341" > /dev/null 2>&1 &
KVM_SERIAL_OPTS="\
-serial mon:stdio \
2023-04-03 13:30:19 +02:00
-device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3 \
2023-04-02 21:38:34 +02:00
-chardev pty,id=charserial0 \
-device isa-serial,chardev=charserial0,id=serial0 \
-chardev socket,id=charchannel0,host=127.0.0.1,port=12345,reconnect=10 \
-device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=vchannel"