Unverified Commit f16676f7 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

Minor fixes

Network/serial reworked
parents a4a7a71d 7a8cdad8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -22,5 +22,5 @@ jobs:
      - name: Run ShellCheck
        uses: ludeeus/action-shellcheck@master
        env:
          SHELLCHECK_OPTS: -e SC2001 -e SC2002 -e SC2116 -e SC2034 -e SC1091 -e SC2143 -e SC2223 -e SC2086 -e SC2145 -e SC2015 -e SC2268 -e SC2207 -e SC2064 
          SHELLCHECK_OPTS: -e SC2001 -e SC2002 -e SC2116 -e SC2034 -e SC1091 -e SC2143 -e SC2223 -e SC2086 -e SC2145 -e SC2015 -e SC2268 -e SC2207 -e SC2064 -e SC2166
+1 −4
Original line number Diff line number Diff line
@@ -57,12 +57,9 @@ EXPOSE 445
EXPOSE 5000
EXPOSE 5001

ENV URL ""
ENV CPU_CORES 1
ENV DISK_SIZE 16G
ENV RAM_SIZE 512M

#ENV URL https://global.synologydownload.com/download/DSM/beta/7.2/64216/DSM_VirtualDSM_64216.pat
#ENV URL https://global.synologydownload.com/download/DSM/release/7.0.1/42218/DSM_VirtualDSM_42218.pat
ENV URL https://global.synologydownload.com/download/DSM/release/7.1.1/42962-1/DSM_VirtualDSM_42962.pat

ENTRYPOINT ["/run/run.sh"]
+17 −13
Original line number Diff line number Diff line
@@ -16,13 +16,17 @@ NEW_SIZE=$(numfmt --from=iec "${DISK_SIZE}")
FILE="$IMG/data$DISK_SIZE.img"

if [ ! -f "$FILE" ]; then
    # Create an empty file
    truncate -s "${NEW_SIZE}" "${FILE}"
    # Format as BTRFS filesystem
    mkfs.btrfs -q -L data -d single -m dup "${FILE}" > /dev/null
    #qemu-img convert -f raw -O qcow2 -o extended_l2=on,cluster_size=128k,compression_type=zstd,preallocation=metadata "$TMP" "$FILE"
fi

[ ! -f "$FILE" ] && echo "ERROR: Virtual DSM data-image does not exist ($FILE)" && exit 83

# Resizing requires mounting a loop device which in turn requires
# the container to be privileged, so we must disable it for now.
#
# OLD_SIZE=$(stat -c%s "${FILE}")
#
# if [ "$NEW_SIZE" -ne "$OLD_SIZE" ]; then
+7 −3
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -eu

if [ -z $URL ]; then
  #URL="https://global.synologydownload.com/download/DSM/beta/7.2/64216/DSM_VirtualDSM_64216.pat"
  #URL="https://global.synologydownload.com/download/DSM/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
  URL="https://global.synologydownload.com/download/DSM/release/7.1.1/42962-1/DSM_VirtualDSM_42962.pat"
fi

IMG="/storage"
BASE=$(basename "$URL" .pat)

@@ -8,7 +14,7 @@ BASE=$(basename "$URL" .pat)
[ ! -f "/run/server.sh" ] && echo "Script must run inside Docker container!" && exit 60

[ ! -f "$IMG/$BASE.boot.img" ] && rm -f "$IMG"/"$BASE".system.img
[ -f "$IMG/$BASE.system.img" ] && exit 0
[ -f "$IMG/$BASE.system.img" ] && return

# Display wait message on port 5000
/run/server.sh 5000 > /dev/null &
@@ -150,5 +156,3 @@ mv -f "$BOOT" "$IMG"/"$BASE".boot.img
mv -f "$SYSTEM" "$IMG"/"$BASE".system.img

rm -rf $TMP

exit 0
+28 −29
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@
set -eu

: ${VM_NET_TAP:=''}
: ${VM_NET_MAC:=''}
: ${VM_NET_IP:='20.20.20.21'}
: ${VM_NET_MAC:='02:11:32:AA:BB:CC'}

: ${DNS_SERVERS:=''}
: ${DNSMASQ:='/usr/sbin/dnsmasq'}
@@ -14,18 +14,6 @@ set -eu
#  Functions
# ######################################

setupLocalDhcp () {
  IP="$2"
  MAC="$1"
  CIDR="24"
  HOSTNAME="VirtualDSM"
  # dnsmasq configuration:
  DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-range=$IP,$IP --dhcp-host=$MAC,,$IP,$HOSTNAME,infinite --dhcp-option=option:netmask,255.255.255.0"
  # Create lease file for faster resolve
  echo "0 $MAC $IP $HOSTNAME 01:${MAC}" > /var/lib/misc/dnsmasq.leases
  chmod 644 /var/lib/misc/dnsmasq.leases
}

# Setup macvtap device to connect later the VM and setup a new macvlan device to connect the host machine to the network
configureNatNetworks () {

@@ -46,7 +34,15 @@ configureNatNetworks () {
  #Enable port forwarding flag
  [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]] && sysctl -w net.ipv4.ip_forward=1

  setupLocalDhcp $VM_NET_MAC $VM_NET_IP
  CIDR="24"
  HOSTNAME="VirtualDSM"

  # dnsmasq configuration:
  DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-range=$VM_NET_IP,$VM_NET_IP --dhcp-host=$VM_NET_MAC,,$VM_NET_IP,$HOSTNAME,infinite --dhcp-option=option:netmask,255.255.255.0"

  # Create lease file for faster resolve
  echo "0 $VM_NET_MAC $VM_NET_IP $HOSTNAME 01:${VM_NET_MAC}" > /var/lib/misc/dnsmasq.leases
  chmod 644 /var/lib/misc/dnsmasq.leases
}

# ######################################
@@ -61,14 +57,6 @@ if [ ! -c /dev/net/tun ]; then
fi

[ ! -c /dev/net/tun ] && echo "Error: TUN network interface not available..." && exit 85
[ ! -d "$IMG" ] && echo "Storage folder (${IMG}) not found!" && exit 86

#If environment variabele not set fall back to file
if [ -z "$VM_NET_MAC" ]; then
  FILE="${IMG}/guest.mac"
  [ ! -f "$FILE" ] && echo "00:11:32:2C:A7:85" > "$FILE"
  VM_NET_MAC=$(cat "${FILE}")
fi

update-alternatives --set iptables /usr/sbin/iptables-legacy > /dev/null
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
@@ -88,17 +76,28 @@ for nameserver in "${nameservers[@]}"; do
  fi
done

if [ -z $DNS_SERVERS ]; then
  DNS_SERVERS="1.1.1.1"
else
  COMMAS=${DNS_SERVERS//[^,]/}
  COMMAS=${#COMMAS}
  ((COMMAS < 1)) && DNS_SERVERS="$DNS_SERVERS,1.1.1.1"
fi

DNSMASQ_OPTS="$DNSMASQ_OPTS \
	--dhcp-option=option:dns-server,$DNS_SERVERS \
  --dhcp-option=option:router,${VM_NET_IP%.*}.1 \
  --dhcp-option=option:domain-search,$searchdomains \
  --dhcp-option=option:domain-name,$domainname"
	--dhcp-option=option:router,${VM_NET_IP%.*}.1"

if [ -n "$searchdomains" -a "$searchdomains" != "." ]; then
  DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-search,$searchdomains"
  DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-name,$domainname"
else
  [[ -z $(hostname -d) ]] || DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-name,$(hostname -d)"
fi

$DNSMASQ $DNSMASQ_OPTS

KVM_NET_OPTS="${KVM_NET_OPTS} -device virtio-net-pci,netdev=hostnet0,mac=${VM_NET_MAC},id=net0"
KVM_NET_OPTS="${KVM_NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0"

# Hack for guest VMs complaining about "bad udp checksums in 5 packets"
iptables -A POSTROUTING -t mangle -p udp --dport bootpc -j CHECKSUM --checksum-fill
Loading