This commit is contained in:
Kroese 2023-03-28 18:42:02 +02:00
parent 6c2d715cf9
commit 8105a0de8e
5 changed files with 31 additions and 36 deletions

3
build.sh Normal file
View File

@ -0,0 +1,3 @@
docker build --tag dsm .
docker run --rm -it --name dsm --device=/dev/kvm:/dev/kvm --device=/dev/fuse:/dev/fuse --device=/dev/net/tun:/dev/net/tun --cap-add NET_ADMIN --cap-add SYS_ADMIN -p 80:5000 -p 443:5001 -p 5000:5000 -p 5001:5001 -v ${PWD}/img:/storage docker.io/library/dsm

View File

@ -1,29 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eu set -eu
if [ ! -f "/run/server.sh" ]; then
echo "Script must run inside Docker container!"
exit 1
fi
IMG="/storage" IMG="/storage"
[ ! -f "/run/server.sh" ] && echo "Script must run inside Docker container!" && exit 1
[ ! -f "$IMG/boot.img" ] && rm -f $IMG/system.img [ ! -f "$IMG/boot.img" ] && rm -f $IMG/system.img
if [ ! -f "$IMG/system.img" ]; then if [ ! -f "$IMG/system.img" ]; then
echo "Downloading Synology DSM from $URL..." echo "Downloading $URL..."
TMP="$IMG/tmp" TMP="$IMG/tmp"
FILE="$TMP/dsm.pat" FILE="$TMP/dsm.pat"
rm -rf $TMP rm -rf $TMP && mkdir -p $TMP
mkdir -p $TMP
wget $URL -O $FILE -q --show-progress wget $URL -O $FILE -q --show-progress
echo "Extracting DSM boot image..." echo "Extracting boot image..."
if { tar tf "$FILE"; } >/dev/null 2>&1; then if { tar tf "$FILE"; } >/dev/null 2>&1; then
tar xpf $FILE -C $TMP/. tar xpf $FILE -C $TMP/.
@ -41,14 +34,14 @@ if [ ! -f "$IMG/system.img" ]; then
unzip -q $BOOT.zip -d $TMP unzip -q $BOOT.zip -d $TMP
rm $BOOT.zip rm $BOOT.zip
echo "Extracting DSM system image..." echo "Extracting system image..."
HDA="$TMP/hda1" HDA="$TMP/hda1"
mv $HDA.tgz $HDA.xz mv $HDA.tgz $HDA.xz
unxz $HDA.xz unxz $HDA.xz
mv $HDA $HDA.tar mv $HDA $HDA.tar
echo "Extracting DSM disk template..." echo "Extracting data image..."
SYSTEM="$TMP/temp.img" SYSTEM="$TMP/temp.img"
PLATE="/data/template.img" PLATE="/data/template.img"
@ -67,7 +60,7 @@ if [ ! -f "$IMG/system.img" ]; then
echo -n "Installing system partition.." echo -n "Installing system partition.."
tar xpf $HDA.tar --absolute-names --checkpoint=.5000 -C $MOUNT/ tar xpf $HDA.tar --absolute-names --checkpoint=.6000 -C $MOUNT/
echo "" echo ""
echo "Unmounting disk template..." echo "Unmounting disk template..."
@ -83,16 +76,10 @@ if [ ! -f "$IMG/system.img" ]; then
fi fi
FILE="$IMG/boot.img" FILE="$IMG/boot.img"
if [ ! -f "$FILE" ]; then [ ! -f "$FILE" ] && echo "ERROR: Synology DSM boot-image does not exist ($FILE)" && exit 2
echo "ERROR: Synology DSM boot-image does not exist ($FILE)"
exit 2
fi
FILE="$IMG/system.img" FILE="$IMG/system.img"
if [ ! -f "$FILE" ]; then [ ! -f "$FILE" ] && echo "ERROR: Synology DSM system-image does not exist ($FILE)" && exit 2
echo "ERROR: Synology DSM system-image does not exist ($FILE)"
exit 2
fi
FILE="$IMG/data.img" FILE="$IMG/data.img"
if [ ! -f "$FILE" ]; then if [ ! -f "$FILE" ]; then
@ -100,9 +87,6 @@ if [ ! -f "$FILE" ]; then
mkfs.ext4 -q $FILE mkfs.ext4 -q $FILE
fi fi
if [ ! -f "$FILE" ]; then [ ! -f "$FILE" ] && echo "ERROR: Synology DSM data-image does not exist ($FILE)" && exit 2
echo "ERROR: Synology DSM data-image does not exist ($FILE)"
exit 2
fi
exit 0 exit 0

21
run.sh
View File

@ -2,15 +2,14 @@
set -eu set -eu
/run/server.sh 5000 "<HTML><BODY><H1><CENTER>Please wait while Synology is installing...</CENTER></H1></BODY></HTML>" > /dev/null & /run/server.sh 5000 > /dev/null &
if [ ! /run/install.sh ]; then if /run/install.sh; then
echo "Installation failed!" echo "Starting DSM for Docker..."
exit 2 else
echo "Installation failed (code $?)" && exit 2
fi fi
echo "Booting Synology DSM for Docker..."
# A bridge of this name will be created to host the TAP interface created for # A bridge of this name will be created to host the TAP interface created for
# the VM # the VM
QEMU_BRIDGE='qemubr0' QEMU_BRIDGE='qemubr0'
@ -75,8 +74,16 @@ GUEST_SERIAL=$(/run/serial.sh)
# Stop the webserver # Stop the webserver
pkill -f server.sh pkill -f server.sh
[ ! -e /dev/fuse ] && echo "Error: FUSE interface not available..." && exit 2
[ ! -e /dev/net/tun ] && echo "Error: TUN interface not available..." && exit 2
if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then
echo "Booting DSM image..."
else
echo "Error: KVM not available..." && exit 2
fi
IMG="/storage" IMG="/storage"
echo "Booting OS..."
# Configure QEMU for graceful shutdown # Configure QEMU for graceful shutdown

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
permanent="PSN" permanent="DSM"
serialstart="1960" serialstart="2000"
serialnum="$(echo "$serialstart" | tr ' ' '\n' | sort -R | tail -1)$permanent"$(printf "%06d" $(($RANDOM % 30000 + 1))) serialnum="$(echo "$serialstart" | tr ' ' '\n' | sort -R | tail -1)$permanent"$(printf "%06d" $(($RANDOM % 30000 + 1)))
echo $serialnum echo $serialnum

View File

@ -2,7 +2,8 @@
set -eu set -eu
RESPONSE="HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n${2:-"OK"}\r\n" HTML="<HTML><BODY><H1><CENTER>Please wait while Synology is installing...</CENTER></H1></BODY></HTML>"
RESPONSE="HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n$HTML\r\n"
while { echo -en "$RESPONSE"; } | nc -lN "${1:-8080}"; do while { echo -en "$RESPONSE"; } | nc -lN "${1:-8080}"; do
echo "================================================" echo "================================================"