Commit e7796f83 authored by Kroese's avatar Kroese
Browse files

Fixes

parent d9caf7e2
Loading
Loading
Loading
Loading

build.sh

0 → 100644
+3 −0
Original line number Diff line number Diff line
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
+10 −26
Original line number Diff line number Diff line
#!/usr/bin/env bash

set -eu

if [ ! -f "/run/server.sh" ]; then
    echo "Script must run inside Docker container!"
    exit 1
fi

IMG="/storage"

[ ! -f "/run/server.sh" ] && echo "Script must run inside Docker container!" && exit 1
[ ! -f "$IMG/boot.img" ] && rm -f $IMG/system.img

if [ ! -f "$IMG/system.img" ]; then

    echo "Downloading Synology DSM from $URL..."
    echo "Downloading $URL..."

    TMP="$IMG/tmp"
    FILE="$TMP/dsm.pat"

    rm -rf $TMP
    mkdir -p $TMP

    rm -rf $TMP && mkdir -p $TMP
    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
       tar xpf $FILE -C $TMP/.
@@ -41,14 +34,14 @@ if [ ! -f "$IMG/system.img" ]; then
    unzip -q $BOOT.zip -d $TMP
    rm $BOOT.zip

    echo "Extracting DSM system image..."
    echo "Extracting system image..."

    HDA="$TMP/hda1"
    mv $HDA.tgz $HDA.xz
    unxz $HDA.xz
    mv $HDA $HDA.tar

    echo "Extracting DSM disk template..."
    echo "Extracting data image..."

    SYSTEM="$TMP/temp.img"
    PLATE="/data/template.img"
@@ -67,7 +60,7 @@ if [ ! -f "$IMG/system.img" ]; then

    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 "Unmounting disk template..."
@@ -83,16 +76,10 @@ if [ ! -f "$IMG/system.img" ]; then
fi

FILE="$IMG/boot.img"
if [ ! -f "$FILE" ]; then
    echo "ERROR: Synology DSM boot-image does not exist ($FILE)"
    exit 2
fi
[ ! -f "$FILE" ] && echo "ERROR: Synology DSM boot-image does not exist ($FILE)" && exit 2

FILE="$IMG/system.img"
if [ ! -f "$FILE" ]; then
    echo "ERROR: Synology DSM system-image does not exist ($FILE)"
    exit 2
fi
[ ! -f "$FILE" ] && echo "ERROR: Synology DSM system-image does not exist ($FILE)" && exit 2

FILE="$IMG/data.img"
if [ ! -f "$FILE" ]; then
@@ -100,9 +87,6 @@ if [ ! -f "$FILE" ]; then
    mkfs.ext4 -q $FILE
fi

if [ ! -f "$FILE" ]; then
    echo "ERROR: Synology DSM data-image does not exist ($FILE)"
    exit 2
fi
[ ! -f "$FILE" ] && echo "ERROR: Synology DSM data-image does not exist ($FILE)" && exit 2

exit 0
+14 −7
Original line number Diff line number Diff line
@@ -2,15 +2,14 @@

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
    echo "Installation failed!"
    exit 2
if /run/install.sh; then
  echo "Starting DSM for Docker..."
else
  echo "Installation failed (code $?)" && exit 2
fi

echo "Booting Synology DSM for Docker..."

# A bridge of this name will be created to host the TAP interface created for
# the VM
QEMU_BRIDGE='qemubr0'
@@ -75,8 +74,16 @@ GUEST_SERIAL=$(/run/serial.sh)
# Stop the webserver
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"
echo "Booting OS..."

# Configure QEMU for graceful shutdown

+2 −2
Original line number Diff line number Diff line
#!/bin/bash

permanent="PSN"
serialstart="1960"
permanent="DSM"
serialstart="2000"
serialnum="$(echo "$serialstart" | tr ' ' '\n' | sort -R | tail -1)$permanent"$(printf "%06d" $(($RANDOM % 30000 + 1)))

echo $serialnum
+2 −1
Original line number Diff line number Diff line
@@ -2,7 +2,8 @@

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
  echo "================================================"