Skip to content

[scripts] Added basic safety to the repository installation Bash script#25017

Open
serious-angel wants to merge 1 commit into
docker:mainfrom
serious-angel:patch-1
Open

[scripts] Added basic safety to the repository installation Bash script#25017
serious-angel wants to merge 1 commit into
docker:mainfrom
serious-angel:patch-1

Conversation

@serious-angel
Copy link
Copy Markdown
Contributor

Dear Developers and Artists,

Thank you for the marvel, art you do!

Description

The main issue is that it's not the first time the publicly proposed script does not complete successfully somewhere in the middle, and since no checks happen, the commands just get executed regardless. A person may not even notice some command failed above if the output from the next commands fills up the screen, too.

I am not sure the initial reason the script had no execution checks, but just in case, what do you think about the command group, due to the here-doc?

Or would it look better with the previous command core check?:

Check the exit status code of the previous command
# ...
EOF

+ (( ! $? )) &&
sudo apt update

There's a less recommended alternative:

Set the bash-opt to stop execution on any command fail
+ # Create a sub-shell to not affect the current shell.
+ (
+ # Set the bash-opt to stop execution on any command fail.
+ set -e;
+ 
# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update
+ )

May I ask, why don't you use ; to separate the commands?

Reviews

  • Technical review
  • Editorial review
  • Product review

@serious-angel serious-angel requested a review from dvdksn as a code owner May 11, 2026 13:08
@netlify
Copy link
Copy Markdown

netlify Bot commented May 11, 2026

Deploy Preview for docsdocker ready!

Name Link
🔨 Latest commit d06c179
🔍 Latest deploy log https://app.netlify.com/projects/docsdocker/deploys/6a01d4e5da38270008162aca
😎 Deploy Preview https://deploy-preview-25017--docsdocker.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant