From fd7b8cd83942ff860766b87734284eac535fd338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 6 Jul 2019 16:45:38 +0200 Subject: [PATCH] Made username, token checking more robust against configuration errors --- 0.17/files/docker-update-mods.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/0.17/files/docker-update-mods.sh b/0.17/files/docker-update-mods.sh index 79b4097..8d953b4 100755 --- a/0.17/files/docker-update-mods.sh +++ b/0.17/files/docker-update-mods.sh @@ -9,10 +9,20 @@ if [[ -f /run/secrets/username ]]; then TOKEN=$(cat /run/secrets/token) fi -if [[ -z $TOKEN ]]; then - set -- "$(jq -j ".username, \" \", .token" "$CONFIG/server-settings.json")" - USERNAME=$1 - TOKEN=$2 +if [[ -z ${USERNAME:-} ]]; then + USERNAME="$(jq -j ".username" "$CONFIG/server-settings.json")" +fi + +if [[ -z ${TOKEN:-} ]]; then + TOKEN="$(jq -j ".token" "$CONFIG/server-settings.json")" +fi + +if [[ -z ${USERNAME:-} ]]; then + echo "You need to provide your Factorio username to update mods." +fi + +if [[ -z ${TOKEN:-} ]]; then + echo "You need to provide your Factorio token to update mods." fi ./update-mods.sh "$VERSION" "$MODS" "$USERNAME" "$TOKEN"