-
Notifications
You must be signed in to change notification settings - Fork 245
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
base: main
Are you sure you want to change the base?
Conversation
swiftly-install
Outdated
@@ -0,0 +1,52 @@ | |||
#!/bin/bash |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
cd ${TMPDIR} | ||
|
||
case "$OS_NAME" in | ||
"Linux") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Co-authored-by: Jake Petroules <[email protected]>
Co-authored-by: Jake Petroules <[email protected]>
Co-authored-by: Jake Petroules <[email protected]>
Co-authored-by: Jake Petroules <[email protected]>
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:
After: