From c47abc4973f497c92ff4bb2bede77d6a308c2c66 Mon Sep 17 00:00:00 2001 From: Jonathan Cohen Date: Fri, 17 Jan 2020 16:17:19 -0500 Subject: [PATCH] Fix update_mmdb and the Docker image to work on Alpine (#559) * Fix the for loop in update_mmdb to be `dash` compatible for x in {a..b} is bash-only, and alpine's default shell is `dash`. * Fix other issues related to using musl/Busybox/dash * Use `[[` instead of `((` for the branch * Make sure to update to GNU coreutils in the image in order to use `date --date` * Respond to review comments --- src/shadowbox/docker/Dockerfile | 7 ++++--- src/shadowbox/scripts/update_mmdb.sh | 12 +++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/shadowbox/docker/Dockerfile b/src/shadowbox/docker/Dockerfile index f5c1ec6b5..968881cc5 100644 --- a/src/shadowbox/docker/Dockerfile +++ b/src/shadowbox/docker/Dockerfile @@ -16,7 +16,7 @@ FROM node:8.15.0-alpine # Versions can be found at https://github.com/Jigsaw-Code/outline-ss-server/releases -ARG SS_VERSION=1.0.7 +ARG SS_VERSION=1.0.8 # Save metadata on the software versions we are using. LABEL shadowbox.node_version=8.15.0 @@ -25,8 +25,9 @@ LABEL shadowbox.outline-ss-server_version="${SS_VERSION}" ARG GITHUB_RELEASE LABEL shadowbox.github.release="${GITHUB_RELEASE}" -# We use curl to detect the server's public IP. -RUN apk add --no-cache curl +# We use curl to detect the server's public IP. We need to use the --date option in `date` to +# safely grab the ip-to-country database +RUN apk add --no-cache --upgrade coreutils curl COPY src/shadowbox/scripts scripts/ COPY src/shadowbox/scripts/update_mmdb.sh /etc/periodic/weekly/update_mmdb diff --git a/src/shadowbox/scripts/update_mmdb.sh b/src/shadowbox/scripts/update_mmdb.sh index 011e05754..acbfb9e7c 100755 --- a/src/shadowbox/scripts/update_mmdb.sh +++ b/src/shadowbox/scripts/update_mmdb.sh @@ -5,15 +5,17 @@ # IP Geolocation by DB-IP (https://db-ip.com) +# Note that this runs on BusyBox sh, which lacks bash features. + TMPDIR="$(mktemp -d)" FILENAME="ip-country.mmdb" # We need to make sure that we grab an existing database at install-time -for monthdelta in {0..10}; do - newdate=$(date --date="-$monthdelta month" +%Y-%m) - ADDRESS="https://download.db-ip.com/free/ip-country-${newdate}.mmdb.gz" - curl --fail --silent "${ADDRESS}" -o "$TMPDIR/$FILENAME.gz" > /dev/null && break - if (( monthdelta == 10 )); then +for monthdelta in $(seq 10); do + newdate=$(date --date="-$monthdelta months" +%Y-%m) + ADDRESS="https://download.db-ip.com/free/dbip-country-lite-${newdate}.mmdb.gz" + curl --fail --silent "${ADDRESS}" -o "$TMPDIR/$FILENAME.gz" > /dev/null && break + if [[ $monthdelta -eq 10 ]]; then # A weird exit code on purpose -- we should catch this long before it triggers exit 2 fi