Commit 354bd242 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Country detection

* feat: Country detection
parent c1d3d15d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ ARG DEBIAN_FRONTEND noninteractive

RUN apt-get update && apt-get -y upgrade && \
    apt-get --no-install-recommends -y install \
        jq \
        tini \
        curl \
        cpio \
+26 −4
Original line number Diff line number Diff line
@@ -21,17 +21,37 @@ fi
# Display wait message
/run/server.sh 5000 install &

# Download the required files from the Synology website
# Detect country
COUNTRY=""
{ JSON=$(curl -sfk https://ipinfo.io); rc=$?; } || :

if (( rc == 0 )); then
  { COUNTRY=$(echo "$JSON" | jq -r '.country' 2> /dev/null); rc=$?; } || :
  (( rc != 0 )) || [[ "$COUNTRY" == "null" ]] && COUNTRY=""
fi

if [[ -z "$COUNTRY" ]]; then
  { JSON=$(curl -sfk https://api.ipapi.is); rc=$?; } || :
  if (( rc == 0 )); then
    { COUNTRY=$(echo "$JSON" | jq -r '.location.country_code' 2> /dev/null); rc=$?; } || :
    (( rc != 0 )) || [[ "$COUNTRY" == "null" ]] && COUNTRY=""
  fi
fi

# Select download mirror based on country
if [ "$COUNTRY" == "CN" ]; then
  DL="https://cndl.synology.cn/download/DSM"
else
  DL="https://global.synologydownload.com/download/DSM"
fi

# Select default version based on architecture
if [ -z "$URL" ]; then

  if [ "$ARCH" == "amd64" ]; then
    URL="$DL/release/7.2.1/69057-1/DSM_VirtualDSM_69057.pat"
  else
    URL="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
  fi

fi

# Check if output is to interactive TTY
@@ -83,6 +103,8 @@ if [[ "$TMP" != "$STORAGE/tmp" ]]; then
  (( MIN_SPACE > SPACE )) && error "Not enough free space for installation in ${STORAGE}, have ${SPACE_GB} GB available but need at least 6 GB." && exit 94
fi

# Download the required files from the Synology website

RDC="$STORAGE/dsm.rd"

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