From c74c1e5487e4b95f17c9bbd90eca8fcf31526972 Mon Sep 17 00:00:00 2001 From: OrpheeGT Date: Sat, 28 Jan 2023 23:09:27 +0100 Subject: [PATCH 1/4] replace oathtool commandl with docker oathtool oathtool binary is not available in DSM6 or DSM7. It needs to sideload binary and dependencies from debian or anything else to make it works... As we have docker synology package available on most of Synology products, using a docker container is a good alternative. This commit replace oathtool binary with docker run commandline. the first time the command is launched, it will take some time to download missing docker image locally. --- deploy/synology_dsm.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy/synology_dsm.sh b/deploy/synology_dsm.sh index c31a5df0..4154b026 100644 --- a/deploy/synology_dsm.sh +++ b/deploy/synology_dsm.sh @@ -20,7 +20,7 @@ # Dependencies: # ------------- # - jq and curl -# - oathtool (When using 2 Factor Authentication and SYNO_TOTP_SECRET is set) +# - docker (When using 2 Factor Authentication and SYNO_TOTP_SECRET is set) # #returns 0 means success, otherwise error. @@ -94,10 +94,10 @@ synology_dsm_deploy() { otp_code="" if [ -n "$SYNO_TOTP_SECRET" ]; then - if _exists oathtool; then - otp_code="$(oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null)" + if _exists docker; then + otp_code="$(docker run --rm -it toolbelt/oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null | cut -b 1-6)" else - _err "oathtool could not be found, install oathtool to use SYNO_TOTP_SECRET" + _err "docker could not be found, install docker synology package to use SYNO_TOTP_SECRET" return 1 fi fi From 39e45aa6bdc6f1163cefa3695d2cb6d4eaeb475c Mon Sep 17 00:00:00 2001 From: OrpheeGT Date: Mon, 30 Jan 2023 11:38:58 +0100 Subject: [PATCH 2/4] restored oathtool binary option - Restored oathtool binary option - Added docker image download prompt request --- deploy/synology_dsm.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/deploy/synology_dsm.sh b/deploy/synology_dsm.sh index 4154b026..294f652e 100644 --- a/deploy/synology_dsm.sh +++ b/deploy/synology_dsm.sh @@ -20,7 +20,7 @@ # Dependencies: # ------------- # - jq and curl -# - docker (When using 2 Factor Authentication and SYNO_TOTP_SECRET is set) +# - oathtool or docker (When using 2 Factor Authentication and SYNO_TOTP_SECRET is set) # #returns 0 means success, otherwise error. @@ -94,10 +94,17 @@ synology_dsm_deploy() { otp_code="" if [ -n "$SYNO_TOTP_SECRET" ]; then - if _exists docker; then - otp_code="$(docker run --rm -it toolbelt/oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null | cut -b 1-6)" + if _exists oathtool; then + otp_code="$(oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null)" + elif _exists docker; then + if [[ "$(docker images -q toolbelt/oathtool:latest 2> /dev/null)" == "" ]]; then + read -e -p "docker is available but oathtool docker image must be downloaded, do you want to download it (Y) or abort (N) ? " choice + [[ "$choice" == [Yy]* ]] && docker image pull toolbelt/oathtool:latest && otp_code="$(docker run --rm -it toolbelt/oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null | cut -b 1-6)" || { echo "Abort requested or download failed"; return 1; } + else + otp_code="$(docker run --rm -it toolbelt/oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null | cut -b 1-6)" + fi else - _err "docker could not be found, install docker synology package to use SYNO_TOTP_SECRET" + _err "neither oathtool or docker could be found, install oathtool binary or docker synology package to use SYNO_TOTP_SECRET" return 1 fi fi From 985b26bb9c7b2829de2c2d398f9950506657475c Mon Sep 17 00:00:00 2001 From: OrpheeGT Date: Mon, 30 Jan 2023 19:37:20 +0100 Subject: [PATCH 3/4] replace echo with _err --- deploy/synology_dsm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/synology_dsm.sh b/deploy/synology_dsm.sh index 294f652e..cbaa92b9 100644 --- a/deploy/synology_dsm.sh +++ b/deploy/synology_dsm.sh @@ -99,7 +99,7 @@ synology_dsm_deploy() { elif _exists docker; then if [[ "$(docker images -q toolbelt/oathtool:latest 2> /dev/null)" == "" ]]; then read -e -p "docker is available but oathtool docker image must be downloaded, do you want to download it (Y) or abort (N) ? " choice - [[ "$choice" == [Yy]* ]] && docker image pull toolbelt/oathtool:latest && otp_code="$(docker run --rm -it toolbelt/oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null | cut -b 1-6)" || { echo "Abort requested or download failed"; return 1; } + [[ "$choice" == [Yy]* ]] && docker image pull toolbelt/oathtool:latest && otp_code="$(docker run --rm -it toolbelt/oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null | cut -b 1-6)" || { _err "Abort requested or download failed"; return 1; } else otp_code="$(docker run --rm -it toolbelt/oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null | cut -b 1-6)" fi From 687814203b29bd00049d6d8fa95dbe22b14f7684 Mon Sep 17 00:00:00 2001 From: OrpheeGT Date: Fri, 21 Apr 2023 17:23:19 +0200 Subject: [PATCH 4/4] Disable docker run command if image not available locally Disable docker run command if image not available locally --- deploy/synology_dsm.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deploy/synology_dsm.sh b/deploy/synology_dsm.sh index cbaa92b9..17925072 100644 --- a/deploy/synology_dsm.sh +++ b/deploy/synology_dsm.sh @@ -98,8 +98,9 @@ synology_dsm_deploy() { otp_code="$(oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null)" elif _exists docker; then if [[ "$(docker images -q toolbelt/oathtool:latest 2> /dev/null)" == "" ]]; then - read -e -p "docker is available but oathtool docker image must be downloaded, do you want to download it (Y) or abort (N) ? " choice - [[ "$choice" == [Yy]* ]] && docker image pull toolbelt/oathtool:latest && otp_code="$(docker run --rm -it toolbelt/oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null | cut -b 1-6)" || { _err "Abort requested or download failed"; return 1; } + _err "docker is available but oathtool docker image must be downloaded manually" + _err "Please execute manually 'docker image pull toolbelt/oathtool:latest' and relaunch the deployment" + return 1 else otp_code="$(docker run --rm -it toolbelt/oathtool --base32 --totp "${SYNO_TOTP_SECRET}" 2>/dev/null | cut -b 1-6)" fi