From 354bd2429b1a268482528d35fb539267c04f69ed Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 4 Dec 2023 14:21:37 +0100 Subject: [PATCH] feat: Country detection * feat: Country detection --- Dockerfile | 3 ++- src/install.sh | 30 ++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 10f36bc..4f6dae6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,8 @@ ARG DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get -y upgrade && \ apt-get --no-install-recommends -y install \ - tini \ + jq \ + tini \ curl \ cpio \ wget \ diff --git a/src/install.sh b/src/install.sh index 363fae8..2da0973 100644 --- a/src/install.sh +++ b/src/install.sh @@ -21,17 +21,37 @@ fi # Display wait message /run/server.sh 5000 install & -# Download the required files from the Synology website -DL="https://global.synologydownload.com/download/DSM" +# 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