As part of an environment setup script we have the following snippet which installs docker:

if [ ! "$(docker -v)" ]; then
    infoMessage "Setting up Docker..."

    echo "Updating system packages.."
    sudo apt-get update

    echo "Installing dependencies..."
    sudo apt -y install apt-transport-https ca-certificates curl software-properties-common

    echo "Adding GPG key..."
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

    echo "Adding docker repository..."
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

    apt-cache policy docker-ce
    echo "Installing docker engine..."
    sudo apt-get -y install docker.ce

    sudo usermod -aG docker ${USER}
    newgrp docker

However for two of our devs for some reason the script silently exits just after installing docker and before the fi (found this with echo's). Either the usermod or newgrp command. Exit code is zero and I'm completely stumped as to why this is happening consistently on only their machines which should be functionally identical to others, apart from any personal configs and changes they've made. When they ran the commands individually there were no issues at all and they could then re-run the script to finish setup.

I've checked breakline characters, they're LF (\n) the same as everywhere else in the script. They're running Ubuntu 18.04.

  • Possibly slightly different PATHs? Personally, I would put the absolute path to each command or utility in this tyoe of script. – fpmurphy Nov 6 '18 at 15:43
  • I'm not sure what you mean @fpmurphy1 usermod and newgrp are fairly standard and they definitely have the commands working on their machines as entering those two lines into the terminal works no problem. – Shardj Nov 6 '18 at 15:56
  • Update: I've recently upgraded my machine with a fresh install, ubuntu 16 -> ubuntu 18. Now I get the issue too, I find it likely that this is an issue relating to the distro version. – Shardj Dec 4 '18 at 12:23
  • The failure is due to newgrp, which I want to use to log the user into the newly created group – Shardj Dec 17 '18 at 11:29

The reason is that newgrp is essentially just creating a new bash instance and as a result until it exits (never happens) it cant continue execution of the script. Essentially the same as if you had su - $(id -u -n); in your script

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.