From 69bed4bb6ea6df459a9ce846e698aace5719c57a Mon Sep 17 00:00:00 2001 From: Petr Bokoc Date: Sep 20 2018 12:15:13 +0000 Subject: [PATCH 1/2] Issue 3 - Check if sudo is really required to run docker --- diff --git a/build.sh b/build.sh index c9349e3..7d2b58d 100755 --- a/build.sh +++ b/build.sh @@ -10,7 +10,17 @@ elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then # Running on Linux. # Let's assume that it's running the Docker deamon # which requires root. - echo "" - echo "This build script is using Docker to run the build in an isolated environment. You might be asked for a root password in order to start it." -sudo docker run --rm -it -v $(pwd):/antora:z antora/antora --html-url-extension-style=indexify site.yml + if groups | grep -wq "docker"; then + # Check if the current user is in the "docker" group. If true, no sudo is needed. + echo "" + echo "This build script is using Docker to run the build in an isolated environment." + docker run --rm -it -v $(pwd):/antora:z antora/antora --html-url-extension-style=indexify site.yml + else + # User isn't in the docker group; run the command with sudo. + echo "" + echo "This build script is using Docker to run the build in an isolated environment. + You might be asked for a root password in order to start it. + Add your user to the docker group to avoid this." + sudo docker run --rm -it -v $(pwd):/antora:z antora/antora --html-url-extension-style=indexify site.yml + fi fi diff --git a/preview.sh b/preview.sh index c2fcc4b..d4a7215 100755 --- a/preview.sh +++ b/preview.sh @@ -11,8 +11,18 @@ elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then # Running on Linux. # Let's assume that it's running the Docker deamon # which requires root. - echo "" - echo "This build script is using Docker to run the build in an isolated environment. You might be asked for a root password in order to start it." - echo "The preview will be available at http://localhost:8080/" - sudo docker run --rm -v $(pwd):/antora:ro,z -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro,z -p 8080:80 nginx + if groups | grep -wq "docker"; then + # Check if the current user is in the "docker" group. If true, no sudo is needed. + echo "" + echo "This build script is using Docker to run the build in an isolated environment." + echo "The preview will be available at http://localhost:8080/" + docker run --rm -v $(pwd):/antora:ro,z -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro,z -p 8080:80 nginx + else + # User isn't in the docker group; run the command with sudo. + echo "This build script is using Docker to run the build in an isolated environment. + You might be asked for a root password in order to start it. + Add your user to the docker group to avoid this." + echo "The preview will be available at http://localhost:8080/" + sudo docker run --rm -v $(pwd):/antora:ro,z -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro,z -p 8080:80 nginx + fi fi From 7b9b8a0939f23ec54388dab0b8cb168142860359 Mon Sep 17 00:00:00 2001 From: Petr Bokoc Date: Sep 20 2018 12:50:43 +0000 Subject: [PATCH 2/2] Provide better messages on the command line --- diff --git a/build.sh b/build.sh index 7d2b58d..a7383d6 100755 --- a/build.sh +++ b/build.sh @@ -14,13 +14,14 @@ elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then # Check if the current user is in the "docker" group. If true, no sudo is needed. echo "" echo "This build script is using Docker to run the build in an isolated environment." + echo "" docker run --rm -it -v $(pwd):/antora:z antora/antora --html-url-extension-style=indexify site.yml else # User isn't in the docker group; run the command with sudo. echo "" - echo "This build script is using Docker to run the build in an isolated environment. - You might be asked for a root password in order to start it. - Add your user to the docker group to avoid this." + echo "This build script is using Docker to run the build in an isolated environment. You might be asked for your password." + echo "You can avoid this by adding your user to the 'docker' group, but be aware of the security implications. See https://docs.docker.com/install/linux/linux-postinstall/." + echo "" sudo docker run --rm -it -v $(pwd):/antora:z antora/antora --html-url-extension-style=indexify site.yml fi fi diff --git a/preview.sh b/preview.sh index d4a7215..7f28177 100755 --- a/preview.sh +++ b/preview.sh @@ -16,13 +16,16 @@ elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then echo "" echo "This build script is using Docker to run the build in an isolated environment." echo "The preview will be available at http://localhost:8080/" + echo "" docker run --rm -v $(pwd):/antora:ro,z -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro,z -p 8080:80 nginx else # User isn't in the docker group; run the command with sudo. - echo "This build script is using Docker to run the build in an isolated environment. - You might be asked for a root password in order to start it. - Add your user to the docker group to avoid this." + echo "" + echo "This build script is using Docker to run the build in an isolated environment. You might be asked for your password." + echo "You can avoid this by adding your user to the 'docker' group, but be aware of the security implications. See https://docs.docker.com/install/linux/linux-postinstall/." + echo "" echo "The preview will be available at http://localhost:8080/" + echo "" sudo docker run --rm -v $(pwd):/antora:ro,z -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro,z -p 8080:80 nginx fi fi