diff options
author | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2017-08-17 16:48:12 +0200 |
---|---|---|
committer | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2017-08-17 14:53:19 +0000 |
commit | 7b217895f7b379d396a9bac9a87590be832dc1cf (patch) | |
tree | 31405f054217c7e3ec9086e0f77e45d557465b5d | |
parent | 9720ddf955b76d678a08dc7ea53684400c659ce3 (diff) |
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 <Alexandru.Avadanii@enea.com>
-rw-r--r-- | mcp/scripts/lib.sh | 5 |
1 files changed, 4 insertions, 1 deletions
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/ |