fuckeduppdp/docker/startup.sh

46 lines
1.7 KiB
Bash
Raw Normal View History

2023-10-26 01:25:51 +00:00
#!/bin/sh
set -e
2023-10-26 01:25:51 +00:00
2023-10-30 19:50:03 +00:00
[ -e "/dev/net/tun" ] || { echo "/dev/net/tun not found. Is the container running in privileged mode?"; exit 1; }
2023-10-26 01:25:51 +00:00
[ -n "$DISK_FILENAME" ] || DISK_FILENAME="rq0.dsk"
echo -n "Checking for disk... "
if [ -f "/mnt/$DISK_FILENAME" ]; then
[ -w "/mnt/$DISK_FILENAME" ] || { echo "Disk /mnt/$DISK_FILENAME exists and is not writable"; exit 1; }
echo "Disk found and is writable."
else
[ -w "/mnt/" ] || { echo "Disk /mnt/$DISK_FILENAME not found and /mnt not writable"; exit 1; }
[ -f "/rq0.dsk.gz" ] || { echo "Disk /mnt/$DISK_FILENAME not found and image was not built with a default disk"; exit 1; }
echo "Disk not found."
echo "Extracting default disk image..."
gzip -cd /rq0.dsk.gz > "/mnt/$DISK_FILENAME" || { echo "Failed to extract default disk image to /mnt/$DISK_FILENAME"; exit 1; }
fi
# Start CoreDNS as soon as possible after validations done
echo "Starting CoreDNS..."
[ -z "$COREDNS_DEBUG" ] && COREDNS_QUIET="-quiet"
coredns "$COREDNS_QUIET" -conf /Corefile &
2023-10-26 01:25:51 +00:00
# Set exit command only if NOEXIT not set
[ -z "$NOEXIT" ] && EXIT_CMD="exit" || EXIT_CMD=""
echo "Configuring simh..."
2023-10-26 01:25:51 +00:00
sed -e "s/<DISK_FILENAME>/${DISK_FILENAME}/" \
-e "s/<EXIT>/${EXIT_CMD}/" /boot.ini.template > /boot.ini
echo "Configuring networking..."
[ -z "$CIDR" ] && CIDR=28
[ -z "$HOSTIP" ] && HOSTIP=1.3.3.1
[ -z "$PDPIP" ] && PDPIP=1.3.3.7
2023-10-26 01:25:51 +00:00
ip tuntap add pdp mode tap
ip link set pdp up
ip addr add "${HOSTIP}/${CIDR}" dev pdp
iptables -t nat -A PREROUTING ! -i pdp -p tcp --dport 4000 -j ACCEPT # dz serial device
iptables -t nat -A PREROUTING ! -i pdp -j DNAT --to-destination "$PDPIP"
2023-10-26 01:25:51 +00:00
iptables -t nat -A POSTROUTING ! -o pdp -j MASQUERADE
echo "Booting PDP-11..."
2023-10-26 01:25:51 +00:00
pdp11 /boot.ini