Skip to content

Use a curlbash script for installing swiftly #1133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

marcprux
Copy link
Contributor

Motivation:

The current recommendation for installing Swiftly on macOS and Linux involves a gnarly multi-line shell-specific blob of code that the user needs to paste into their shell.

Curlbash scripts (i.e., curl https://… | sh) are a common and portable way to install software for UNIX-like systems. They are used by popular packages like rbenv, Homebrew, Rust, NVM, Tailscale, and Deno.

Modifications:

Add a swiftly-install shell script for installing swiftly and recommend using it from the "Install" pages.

Result:

The installation instructions will be briefer and nicer and not require that the user know what shell they are running.

Before:

Screenshot 2025-08-16 at 18 03 08

After:

Screenshot 2025-08-16 at 18 03 23

@marcprux marcprux requested a review from a team as a code owner August 16, 2025 22:04
swiftly-install Outdated
@@ -0,0 +1,52 @@
#!/bin/bash

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use #!/bin/sh for maximum portability? shellcheck can help validate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soundness.sh seems to prefer bash

@shahmishal shahmishal added the workgroup-to-discuss Issue/PR to be discussed by the SWWG in the next meeting label Aug 17, 2025
@shahmishal shahmishal self-assigned this Aug 17, 2025
cd ${TMPDIR}

case "$OS_NAME" in
"Linux")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux, almost no command line tool is guaranteed to be installed. It's worth checking if all of the programs the script needs are installed.

  • ps (from a package usually called procps) is not always present.
  • tar is not always present.
  • Neither is curl (yes the swift.org instructions propose fetching the script with curl in the first place, but someone might've still manually used wget or something other way to get the script onto their machine)

mktemp and uname come from coreutils, but those are a bit too fundamental to bother checking for IMO. cd is a shell builtin.

Or, you could detect apt-get and dnf and try to install the relevant packages to ensure they'll be there (without -y, so the user is prompted if configured).

something like this:

if command -v apt-get >/dev/null 2>&1 ; then # debian, ubuntu
    apt-get update
    apt-get install curl procps tar
elif command -v dnf >/dev/null 2>&1 ; then # rhel
    dnf update
    dnf install curl procps tar
elif command -v yum >/dev/null 2>&1 ; then # amazonlinux2
    yum update
    yum install curl procps tar
elif ! command -v curl >/dev/null 2>&1 || ! command -v ps >/dev/null 2>&1 || ! command -v tar >/dev/null 2>&1 ; then
    echo "Missing one of more of the following programs: curl, ps, tar" >&2
    exit 1
fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I think that automatically running their package manager to install the missing utilities is a bit heavy-handed, so I just went with the fail-fast exit when one of the necessary commands is not present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
workgroup-to-discuss Issue/PR to be discussed by the SWWG in the next meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants