I’m writing a bash script on Linux for the user to run.
The script installs docker software on the laptop by itself:
It downloads the repository, the GPG key, containerd, awscli, etc and other stuff.
Before using AWSCLI, the script enables and starts the docker. Then adds it to the group. See the following:
# Enable docker
sudo systemctl enable docker
# Start docker
sudo systemctl start docker
# Add current user to Docker group
sudo usermod -aG docker $USER
# The rest of the script, including commands of awscli
# ...
It turns out that for the “docker” to be updated in the “group”, there’s a requirement to do a linux restart, or at least log-out (then log in again).
But the problem is, I’d like this script to run completely without intervention of the user.
I tried to use:
“newgrp docker” to reset the group settings, which would add “docker” into it without restarting, but it still doesn’t work well.
How can I solve the problem of needing to restart in the middle in order to keep on with the script’s other commands?
I assume you want to login to ECR and pull some images during the initial setup.
I see a couple of options for this:
configure the aws cli profile for root as well and do your initial setup as root?
extract the initial setup to its own script and call that script with something like sudo -u $USER bash -i -c "yourscript.sh"
Wrap the initial setup into a command like the previous one but replace yourscript.sh with the actual commands. Looks like a here-doc string is a good way to still keep it readable for the human eye.
Thank you so much for your input!
You’re right, I wanted to login to ECR and pull some images.
For now, I’ve splitted the script into two separated files, so that the second script would be run after the reboot.
I’ll look further into your suggestions. Thanks!