From acf8ada654822e71d9996830ddef99980dd67205 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 2 Jul 2019 18:25:50 +0900 Subject: [PATCH 1/9] Change params parsing in btcpay-setup.sh --- btcpay-setup.sh | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/btcpay-setup.sh b/btcpay-setup.sh index a3cb8a0..73c373e 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -103,16 +103,38 @@ Add-on specific variables: END } -if [[ "$1" != "-i" ]] && [[ "$1" != "--install-only" ]]; then +while (( "$#" )); do + case "$1" in + -i) + START=true + shift 1 + ;; + --install-only) + START=false + shift 1 + ;; + --) # end argument parsing + shift + break + ;; + -*|--*=) # unsupported flags + echo "Error: Unsupported flag $1" >&2 + display_help + return + ;; + *) # preserve positional arguments + PARAMS="$PARAMS $1" + shift + ;; + esac +done + +# If start does not have a value, stophere +if [[ "$START" ]]; then display_help return fi -START=true -if [[ "$1" == "--install-only" ]]; then - START=false -fi - if [[ -z "$BTCPAYGEN_CRYPTO1" ]]; then if [[ "$OSTYPE" != "darwin"* ]]; then # Not Mac OS - Mac OS uses it's own env file From 1bcb7872ad0c9690134cfeb567bfbfd2d4bc9b75 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 2 Jul 2019 18:29:46 +0900 Subject: [PATCH 2/9] Fix arguments --- btcpay-setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/btcpay-setup.sh b/btcpay-setup.sh index 73c373e..ce321f3 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -102,7 +102,7 @@ Add-on specific variables: BTCTRANSMUTER_HOST: If btc transmuter is activated with opt-add-btctransmuter, the hostname of your btc transmuter website (eg. store.example.com) END } - +START="" while (( "$#" )); do case "$1" in -i) @@ -130,7 +130,7 @@ while (( "$#" )); do done # If start does not have a value, stophere -if [[ "$START" ]]; then +if ! [[ "$START" ]]; then display_help return fi From 7c76561f8c07cc25454ee71fea170fb947ced90f Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 2 Jul 2019 18:33:40 +0900 Subject: [PATCH 3/9] Fix docker-compose pull --- helpers.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/helpers.sh b/helpers.sh index d18cc65..e4e5473 100755 --- a/helpers.sh +++ b/helpers.sh @@ -99,7 +99,10 @@ btcpay_up() { } btcpay_pull() { - . $BTCPAY_BASE_DIRECTORY/Generated/pull-images.sh + pushd . > /dev/null + cd "$(dirname "$BTCPAY_ENV_FILE")" + docker-compose -f "$BTCPAY_DOCKER_COMPOSE" pull + popd > /dev/null } btcpay_down() { From e3577fd163afa9860a579de51c0f2772a336b860 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 2 Jul 2019 18:34:13 +0900 Subject: [PATCH 4/9] Remove killing docker --- btcpay-setup.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/btcpay-setup.sh b/btcpay-setup.sh index ce321f3..5565171 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -490,9 +490,4 @@ fi cd "$BTCPAY_BASE_DIRECTORY/btcpayserver-docker" install_tooling -if ! $START; then - echo "Killing dockerd in the background..." - kill %- -fi - cd $ORIGINAL_DIRECTORY From cbb82c26765f0c14ea6e4f9f28861d4cabc343be Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 3 Jul 2019 14:12:52 +0900 Subject: [PATCH 5/9] Add --docker-unavailable to run btcpay-setup.sh without docker available --- btcpay-setup.sh | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/btcpay-setup.sh b/btcpay-setup.sh index 5565171..b12bd09 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -59,6 +59,7 @@ This script must be run as root, except on Mac OS -i : Run install and start BTCPay Server --install-only : Run install only + --docker-unavailable : If specified, same as --install-only, but will also skip install steps requiring docker This script will: @@ -103,6 +104,7 @@ Add-on specific variables: END } START="" +HAS_DOCKER=true while (( "$#" )); do case "$1" in -i) @@ -113,6 +115,11 @@ while (( "$#" )); do START=false shift 1 ;; + --docker-unavailable) + START=false + HAS_DOCKER=false + shift 1 + ;; --) # end argument parsing shift break @@ -368,23 +375,27 @@ if ! [[ -x "$(command -v docker)" ]] || ! [[ -x "$(command -v docker-compose)" ] else echo "Trying to install docker-compose by using the docker-compose-builder ($(uname -m))" ! [[ -d "dist" ]] && mkdir dist - docker run --rm -ti -v "$(pwd)/dist:/dist" btcpayserver/docker-compose-builder:1.23.2 - mv dist/docker-compose /usr/local/bin/docker-compose - chmod +x /usr/local/bin/docker-compose - rm -rf "dist" + if $HAS_DOCKER; then + docker run --rm -ti -v "$(pwd)/dist:/dist" btcpayserver/docker-compose-builder:1.23.2 + mv dist/docker-compose /usr/local/bin/docker-compose + chmod +x /usr/local/bin/docker-compose + rm -rf "dist" + fi fi fi fi fi -if ! [[ -x "$(command -v docker)" ]]; then - echo "Failed to install 'docker'. Please install docker manually, then retry." - return -fi +if $HAS_DOCKER; then + if ! [[ -x "$(command -v docker)" ]]; then + echo "Failed to install 'docker'. Please install docker manually, then retry." + return + fi -if ! [[ -x "$(command -v docker-compose)" ]]; then - echo "Failed to install 'docker-compose'. Please install docker-compose manually, then retry." - return + if ! [[ -x "$(command -v docker-compose)" ]]; then + echo "Failed to install 'docker-compose'. Please install docker-compose manually, then retry." + return + fi fi # Generate the docker compose in BTCPAY_DOCKER_COMPOSE @@ -470,14 +481,14 @@ fi cd "$(dirname $BTCPAY_ENV_FILE)" -if [[ ! -z "$OLD_BTCPAY_DOCKER_COMPOSE" ]] && [[ "$OLD_BTCPAY_DOCKER_COMPOSE" != "$BTCPAY_DOCKER_COMPOSE" ]]; then +if $HAS_DOCKER && [[ ! -z "$OLD_BTCPAY_DOCKER_COMPOSE" ]] && [[ "$OLD_BTCPAY_DOCKER_COMPOSE" != "$BTCPAY_DOCKER_COMPOSE" ]]; then echo "Closing old docker-compose at $OLD_BTCPAY_DOCKER_COMPOSE..." docker-compose -f "$OLD_BTCPAY_DOCKER_COMPOSE" down -t "${COMPOSE_HTTP_TIMEOUT:-180}" fi if $START; then btcpay_up -else +elif $HAS_DOCKER; then btcpay_pull fi From e4224a42de87ef828ed6b6b937d759f767eaa95f Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 3 Jul 2019 14:18:39 +0900 Subject: [PATCH 6/9] Add --no-startup-register --- btcpay-setup.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/btcpay-setup.sh b/btcpay-setup.sh index b12bd09..aee9fca 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -58,8 +58,9 @@ Install BTCPay on this server This script must be run as root, except on Mac OS -i : Run install and start BTCPay Server - --install-only : Run install only - --docker-unavailable : If specified, same as --install-only, but will also skip install steps requiring docker + --install-only: Run install only + --docker-unavailable: Same as --install-only, but will also skip install steps requiring docker + --no-startup-register: Do not register BTCPayServer to start via systemctl or upstart This script will: @@ -105,6 +106,7 @@ END } START="" HAS_DOCKER=true +STARTUP_REGISTER=true while (( "$#" )); do case "$1" in -i) @@ -120,6 +122,10 @@ while (( "$#" )); do HAS_DOCKER=false shift 1 ;; + --no-startup-register) + STARTUP_REGISTER=false + shift 1 + ;; --) # end argument parsing shift break @@ -406,7 +412,7 @@ if [[ "$BTCPAYGEN_OLD_PREGEN" == "true" ]]; then fi # Schedule for reboot -if [[ -x "$(command -v systemctl)" ]]; then +if $STARTUP_REGISTER && [[ -x "$(command -v systemctl)" ]]; then # Use systemd if [[ -e "/etc/init/start_containers.conf" ]]; then echo -e "Uninstalling upstart script /etc/init/start_containers.conf" @@ -449,7 +455,7 @@ WantedBy=multi-user.target" > /etc/systemd/system/btcpayserver.service echo "BTCPay Server started" fi $START && echo "Impossible to start a systemctl service in chroot... skipping" -elif [[ -x "$(command -v initctl)" ]]; then +elif $STARTUP_REGISTER && [[ -x "$(command -v initctl)" ]]; then # Use upstart echo "Using upstart" echo " From 64544cbe2f77f916f27a18b9871c006ea0f2a339 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 3 Jul 2019 14:43:27 +0900 Subject: [PATCH 7/9] Small refactoring --- btcpay-setup.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/btcpay-setup.sh b/btcpay-setup.sh index aee9fca..c4dc495 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -378,15 +378,13 @@ if ! [[ -x "$(command -v docker)" ]] || ! [[ -x "$(command -v docker-compose)" ] echo "Trying to install docker-compose by downloading on $DOCKER_COMPOSE_DOWNLOAD ($(uname -m))" curl -L "$DOCKER_COMPOSE_DOWNLOAD" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose - else + elif $HAS_DOCKER; then echo "Trying to install docker-compose by using the docker-compose-builder ($(uname -m))" ! [[ -d "dist" ]] && mkdir dist - if $HAS_DOCKER; then - docker run --rm -ti -v "$(pwd)/dist:/dist" btcpayserver/docker-compose-builder:1.23.2 - mv dist/docker-compose /usr/local/bin/docker-compose - chmod +x /usr/local/bin/docker-compose - rm -rf "dist" - fi + docker run --rm -ti -v "$(pwd)/dist:/dist" btcpayserver/docker-compose-builder:1.23.2 + mv dist/docker-compose /usr/local/bin/docker-compose + chmod +x /usr/local/bin/docker-compose + rm -rf "dist" fi fi fi From 27919437cd9a1d7706a3b4a50ea6bd8728ee2342 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 3 Jul 2019 16:09:43 +0900 Subject: [PATCH 8/9] Do not build the docker-compose if no docker --- btcpay-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/btcpay-setup.sh b/btcpay-setup.sh index c4dc495..0482148 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -403,7 +403,7 @@ if $HAS_DOCKER; then fi # Generate the docker compose in BTCPAY_DOCKER_COMPOSE -. ./build.sh +$HAS_DOCKER && . ./build.sh if [[ "$BTCPAYGEN_OLD_PREGEN" == "true" ]]; then cp Generated/docker-compose.generated.yml $BTCPAY_DOCKER_COMPOSE From 34b6a8108182eda6c90b19c0a3e7b2fb9ca78fb8 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 3 Jul 2019 16:40:31 +0900 Subject: [PATCH 9/9] Do not specific tooling if the docker compose does not exists --- helpers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers.sh b/helpers.sh index e4e5473..8044ed2 100755 --- a/helpers.sh +++ b/helpers.sh @@ -34,7 +34,7 @@ install_tooling() { [ -e /usr/local/bin/$scriptname ] && rm /usr/local/bin/$scriptname if [ -e "$scriptname" ]; then - if [ "$dependency" == "*" ] || grep -q "$dependency" "$BTCPAY_DOCKER_COMPOSE"; then + if [ "$dependency" == "*" ] || ( [ -e "$BTCPAY_DOCKER_COMPOSE" ] && grep -q "$dependency" "$BTCPAY_DOCKER_COMPOSE" ); then chmod +x $scriptname ln -s "$(pwd)/$scriptname" /usr/local/bin echo "Installed $scriptname to /usr/local/bin: $comment"