From 1f0acbd0cd47c4872fd57189181e06dc2bd7891b Mon Sep 17 00:00:00 2001 From: Swapnil Kulkarni Date: Mon, 13 Jul 2015 07:11:27 +0000 Subject: [PATCH] Update scripts to check if docker is usable for $USER Added new script for checking user permissions on docker command execution Change-Id: I3b727590d9a29f416f5b847912b7250c555c2333 Closes-Bug: #1473554 --- tools/build-docker-image | 7 ++----- tools/cleanup-containers | 2 ++ tools/cleanup-images | 6 ++++++ tools/kolla | 2 ++ tools/validate-docker-execute | 14 ++++++++++++++ 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100755 tools/validate-docker-execute diff --git a/tools/build-docker-image b/tools/build-docker-image index 7ab3823338..f7c7995e11 100755 --- a/tools/build-docker-image +++ b/tools/build-docker-image @@ -1,13 +1,10 @@ #!/bin/bash -if [[ $EUID -eq 0 ]]; then - echo "This script must not be run as root. Instead add yourself to the docker group." 1>&2 - exit 1 -fi - TOPDIR=$(git rev-parse --show-toplevel) IMGDIR="$(cd "$(dirname "$0")" && pwd)" +. $TOPDIR/tools/validate-docker-execute + RELEASE_NAMESPACE=kollaglue NAMESPACE=kollaglue PREFIX=centos-rdo- diff --git a/tools/cleanup-containers b/tools/cleanup-containers index efdd843760..4812f57449 100755 --- a/tools/cleanup-containers +++ b/tools/cleanup-containers @@ -4,6 +4,8 @@ REAL_PATH=$(python -c "import os,sys;print os.path.realpath('$0')") cd "$(dirname "$REAL_PATH")/.." +. tools/validate-docker-execute + # Remove docker containers docker ps -a -q | while read -r line ; do echo "Removing docker containers" diff --git a/tools/cleanup-images b/tools/cleanup-images index df88e033a5..c0b1db55c6 100755 --- a/tools/cleanup-images +++ b/tools/cleanup-images @@ -1,3 +1,9 @@ #!/bin/bash +# Move to top level directory +REAL_PATH=$(python -c "import os,sys;print os.path.realpath('$0')") +cd "$(dirname "$REAL_PATH")/.." + +. tools/validate-docker-execute + docker rmi $@ $(docker images -a -q) diff --git a/tools/kolla b/tools/kolla index ff05d108a4..3f99c4b43f 100755 --- a/tools/kolla +++ b/tools/kolla @@ -6,6 +6,8 @@ REAL_PATH=$(python -c "import os,sys;print os.path.realpath('$0')") cd "$(dirname "$REAL_PATH")/.." +. tools/validate-docker-execute + NETWORK_MANAGER=$(grep -sri NETWORK_MANAGER ./compose/openstack.env | cut -f2 -d'=') if [[ -z "$NETWORK_MANAGER" ]]; then echo 'No network manager defined in ./compose/openstack.env, defaulting to "neutron".' diff --git a/tools/validate-docker-execute b/tools/validate-docker-execute new file mode 100755 index 0000000000..3dda59e86c --- /dev/null +++ b/tools/validate-docker-execute @@ -0,0 +1,14 @@ +#!/bin/bash +# +# This script can be used to check user privilege to execute +# docker commands + +function check_dockerexecute { + docker ps &>/dev/null + return_val=$? + if [ $return_val -ne 0 ]; then + echo "User $USER can't seem to run Docker commands. Verify product documentation to allow user to execute docker commands" 1>&2 + exit 1 + fi +} +check_dockerexecute