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

feat: Display progress via web (#584)

parent fc92b66f
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ RUN if [ "$TARGETPLATFORM" != "linux/amd64" ]; then extra="qemu-user"; fi \
        wget \
        fdisk \
        unzip \
        socat \
        nginx \
        procps \
        xz-utils \
        iptables \
@@ -39,11 +39,16 @@ RUN if [ "$TARGETPLATFORM" != "linux/amd64" ]; then extra="qemu-user"; fi \
        qemu-system-x86 \
        "$extra" \
    && apt-get clean \
    && unlink /etc/nginx/sites-enabled/default \
    && sed -i 's/^worker_processes.*/worker_processes 1;/' /etc/nginx/nginx.conf \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY ./src /run/
COPY ./web /var/www/
COPY --from=builder /qemu-host.bin /run/host.bin

RUN chmod +x /run/*.sh && chmod +x /run/*.bin
RUN mv /var/www/nginx.conf /etc/nginx/sites-enabled/web.conf 

VOLUME /storage
EXPOSE 22 139 445 5000
+17 −8
Original line number Diff line number Diff line
@@ -61,8 +61,8 @@ getSize() {
  local DISK_FILE=$1
  local DISK_EXT DISK_FMT

  DISK_EXT="$(echo "${DISK_FILE//*./}" | sed 's/^.*\.//')"
  DISK_FMT="$(ext2fmt "$DISK_EXT")"
  DISK_EXT=$(echo "${DISK_FILE//*./}" | sed 's/^.*\.//')
  DISK_FMT=$(ext2fmt "$DISK_EXT")

  case "${DISK_FMT,,}" in
    raw)
@@ -112,7 +112,9 @@ createDisk() {
    fi
  fi

  info "Creating a $DISK_TYPE $DISK_DESC image in $DISK_FMT format with a size of $DISK_SPACE..."
  MSG="Creating a $DISK_TYPE $DISK_DESC image in $DISK_FMT format with a size of $DISK_SPACE..."
  info "$MSG" && html "$MSG"

  local FAIL="Could not create a $DISK_TYPE $DISK_FMT $DISK_DESC image of $DISK_SPACE ($DISK_FILE)"

  case "${DISK_FMT,,}" in
@@ -195,7 +197,9 @@ resizeDisk() {
  fi

  local GB=$(( (CUR_SIZE + 1073741823)/1073741824 ))
  info "Resizing $DISK_DESC from ${GB}G to $DISK_SPACE..."
  MSG="Resizing $DISK_DESC from ${GB}G to $DISK_SPACE..."
  info "$MSG" && html "$MSG"

  local FAIL="Could not resize the $DISK_TYPE $DISK_FMT $DISK_DESC image from ${GB}G to $DISK_SPACE ($DISK_FILE)"

  case "${DISK_FMT,,}" in
@@ -262,7 +266,8 @@ convertDisk() {
    fi
  fi

  info "Converting $DISK_DESC to $DST_FMT, please wait until completed..."
  MSG="Converting $DISK_DESC to $DST_FMT, please wait until completed..."
  info "$MSG" && html "$MSG"

  local CONV_FLAGS="-p"
  local DISK_PARAM="$DISK_ALLOC"
@@ -301,7 +306,8 @@ convertDisk() {
    fi
  fi

  info "Conversion of $DISK_DESC to $DST_FMT completed succesfully!"
  MSG="Conversion of $DISK_DESC to $DST_FMT completed succesfully!"
  info "$MSG" && html "$MSG"

  return 0
}
@@ -372,7 +378,7 @@ addDisk () {
    else
      PREV_FMT="qcow2"
    fi
    PREV_EXT="$(fmt2ext "$PREV_FMT")"
    PREV_EXT=$(fmt2ext "$PREV_FMT")

    if [ -f "$DISK_BASE.$PREV_EXT" ] ; then
      convertDisk "$DISK_BASE.$PREV_EXT" "$PREV_FMT" "$DISK_FILE" "$DISK_FMT" "$DISK_BASE" "$DISK_DESC" "$FS" || exit $?
@@ -420,7 +426,9 @@ addDevice () {
  return 0
}

DISK_EXT="$(fmt2ext "$DISK_FMT")" || exit $?
html "Initializing disks..."

DISK_EXT=$(fmt2ext "$DISK_FMT")

if [ -z "$ALLOCATE" ]; then
  if [[ "${DISK_FMT,,}" == "raw" ]]; then
@@ -505,4 +513,5 @@ else
  addDisk "userdata4" "$DISK4_FILE" "$DISK_EXT" "disk4" "$DISK4_SIZE" "6" "0xf" "$DISK_FMT" || exit $?
fi

html "Initialized disks successfully..."
return 0
+2 −3
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -Eeuo pipefail

echo "❯ Starting Virtual DSM for Docker v$(</run/version)..."
echo "❯ For support visit https://github.com/vdsm/virtual-dsm"
echo
APP="Virtual DSM"
SUPPORT="https://github.com/vdsm/virtual-dsm"

cd /run

+16 −9
Original line number Diff line number Diff line
@@ -23,8 +23,7 @@ if [[ -f "$STORAGE/$BASE.boot.img" ]] && [[ -f "$STORAGE/$BASE.system.img" ]]; t
  return 0  # Previous installation found
fi

# Display wait message
/run/server.sh 5000 install &
html "Please wait while Virtual DSM is being installed..."

DL=""
DL_CHINA="https://cndl.synology.cn/download/DSM"
@@ -105,7 +104,8 @@ RDC="$STORAGE/dsm.rd"

if [ ! -f "$RDC" ]; then

  info "Install: Downloading installer..."
  MSG="Downloading installer..."
  info "Install: $MSG" && html "$MSG"

  RD="$TMP/rd.gz"
  POS="65627648-71021835"
@@ -174,7 +174,8 @@ fi

rm -rf "$TMP" && mkdir -p "$TMP"

info "Install: Downloading $BASE.pat..."
MSG="Downloading $BASE.pat..."
info "Install: $MSG" && html "$MSG"

PAT="/$BASE.pat"
rm -f "$PAT"
@@ -198,7 +199,8 @@ if ((SIZE<250000000)); then
  error "The specified PAT file is probably an update pack as it's too small." && exit 62
fi

info "Install: Extracting downloaded image..."
MSG="Extracting downloaded image..."
info "Install: $MSG" && html "$MSG"

if { tar tf "$PAT"; } >/dev/null 2>&1; then

@@ -221,7 +223,9 @@ else
fi

rm -rf /run/extract
info "Install: Preparing system partition..."

MSG="Preparing system partition..."
info "Install: $MSG" && html "$MSG"

BOOT=$(find "$TMP" -name "*.bin.zip")
[ ! -f "$BOOT" ] && error "The PAT file contains no boot image." && exit 67
@@ -277,7 +281,8 @@ sfdisk -q "$SYSTEM" < "$PART"
MOUNT="$TMP/system"
rm -rf "$MOUNT" && mkdir -p "$MOUNT"

info "Install: Extracting system partition..."
MSG="Extracting system partition..."
info "Install: $MSG" && html "$MSG"

HDA="$TMP/hda1"
IDB="$TMP/indexdb"
@@ -301,12 +306,13 @@ fi
LABEL="1.44.1-42218"
OFFSET="1048576" # 2048 * 512
NUMBLOCKS="622560" # (4980480 * 512) / 4096
MSG="Installing system partition..."

if [[ "$ROOT" != [Nn]* ]]; then

  tar xpfJ "$HDA.txz" --absolute-names --skip-old-files -C "$MOUNT/"

  info "Install: Installing system partition..."
  info "Install: $MSG" && html "$MSG"

  mke2fs -q -t ext4 -b 4096 -d "$MOUNT/" -L "$LABEL" -F -E "offset=$OFFSET" "$SYSTEM" "$NUMBLOCKS"

@@ -314,7 +320,7 @@ else

  fakeroot -- bash -c "set -Eeu;\
        tar xpfJ $HDA.txz --absolute-names --skip-old-files -C $MOUNT/;\
        printf '%b%s%b' '\E[1;34m❯ \E[1;36m' 'Install: Installing system partition...' '\E[0m\n';\
        printf '%b%s%b' '\E[1;34m❯ \E[1;36m' 'Install: $MSG' '\E[0m\n';\
        mke2fs -q -t ext4 -b 4096 -d $MOUNT/ -L $LABEL -F -E offset=$OFFSET $SYSTEM $NUMBLOCKS"

fi
@@ -334,4 +340,5 @@ rm -rf "$TMP"
{ set +x; } 2>/dev/null
[[ "$DEBUG" == [Yy1]* ]] && echo

html "Installation finished successfully..."
return 0
+12 −6
Original line number Diff line number Diff line
@@ -173,14 +173,17 @@ closeNetwork() {

  if [[ "$DHCP" == [Yy1]* ]]; then

    fKill "server.sh"
    # Shutdown nginx
    nginx -s stop 2> /dev/null
    fWait "nginx"

    ip link set "$VM_NET_TAP" down || true
    ip link delete "$VM_NET_TAP" || true

  else

    fKill "dnsmasq"
    local pid="/var/run/dnsmasq.pid"
    [ -f "$pid" ] && pKill "$(<"$pid")"

    ip link set "$VM_NET_TAP" down promisc off || true
    ip link delete "$VM_NET_TAP" || true
@@ -227,8 +230,6 @@ getInfo() {
#  Configure Network
# ######################################

fKill "server.sh"

if [ ! -c /dev/vhost-net ]; then
  if mknod /dev/vhost-net c 10 238; then
    chmod 660 /dev/vhost-net
@@ -236,6 +237,7 @@ if [ ! -c /dev/vhost-net ]; then
fi

getInfo
html "Initializing network..."

if [[ "$DEBUG" == [Yy1]* ]]; then
  info "Container IP is $IP with gateway $GATEWAY on interface $VM_NET_DEV" && echo
@@ -252,11 +254,15 @@ if [[ "$DHCP" == [Yy1]* ]]; then
  # Configuration for DHCP IP
  configureDHCP

  # Display IP on port 80 and 5000
  /run/server.sh 5000 /run/ip.sh &
  MSG="Please wait while discovering IP..."
  html "$MSG" "2000"

else

  # Shutdown nginx
  nginx -s stop 2> /dev/null
  fWait "nginx"

  # Configuration for static IP
  configureNAT

Loading