From 7b217895f7b379d396a9bac9a87590be832dc1cf Mon Sep 17 00:00:00 2001 From: Alexandru Avadanii Date: Thu, 17 Aug 2017 16:48:12 +0200 Subject: [PATCH] lib.sh: Fix mcp key owner for OPNFV Jenkins jobs In case of non-root deploys (i.e. running `ci/deploy.sh` without sudo), the OPNFV Jenkins slave executes it under a user shell, under a root shell, e.g.: $ sudo sudo -u jenkins bash $ echo $USER jenkins $ echo $SUDO_USER root Adjust lib.sh to only use SUDO_USER when it is not "root". Change-Id: I6dd1c8a5dd3a3b02cfb760818d66e99f49709a5b Signed-off-by: Alexandru Avadanii --- mcp/scripts/lib.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mcp/scripts/lib.sh b/mcp/scripts/lib.sh index 8d4510084..d9c6454f2 100644 --- a/mcp/scripts/lib.sh +++ b/mcp/scripts/lib.sh @@ -4,7 +4,10 @@ # generate_ssh_key() { - local user=${SUDO_USER:-$USER} + local user=${USER} + if [ -n "${SUDO_USER}" ] && [ "${SUDO_USER}" != 'root' ]; then + user=${SUDO_USER} + fi [ -f "${SSH_KEY}" ] || ssh-keygen -f "${SSH_KEY}" -N '' install -o "${user}" -m 0600 "${SSH_KEY}" /tmp/ -- 2.16.6