amonks / run

Go run some tasks!
https://amonks.github.io/run/
Other
19 stars 4 forks source link

oneliner in readme slightly broken (set: Illegal option -o pipefail) #111

Closed ecshreve closed 8 months ago

ecshreve commented 8 months ago

Found a small problem with the one liner I added to the readme for the install script. I only tested on osx not linux šŸ¤¦ and turns out the one liner doesn't work on a fresh ubuntu install

trying to run the one liner:

$curl -L https://raw.githubusercontent.com/amonks/run/main/install.sh | sh 
>
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1183  100  1183    0     0   3921      0 --:--:-- --:--:-- --:--:--  3930
trap: ERR: bad trap
sh: 10: set: Illegal option -o pipefail

operating system

$ lsb_release -a 
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:        22.04
Codename:       jammy

sh is actually a symlink to dash which doesn't include the pipefail option option

$ ls -al /bin/sh
rwxrwxrwx root /bin/sh -> dash

on ubuntu (and some other distros) sh has the symlink by default: https://en.wikipedia.org/wiki/Almquist_shell#Adoption_in_Debian_and_Ubuntu

Dash Debian: https://manpages.debian.org/bookworm/dash/dash.1.en.html#Argument_List_Processing

GNU Bash: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html

ecshreve commented 8 months ago

Options that come to mind

amonks commented 8 months ago

TIL that's a bashism! I did not know this!

I like portability, but I think I like pipefail protection even more. My preferred solution is to (1) change the shebang line to #!/usr/bin/env bash (/bin/bash isn't a standardized locationā€”Ā some systems put it bash in /usr/bin or /usr/local/bin; env will find the correct path), and (2) change the README to call bash by name.

ecshreve commented 8 months ago

sweet, i can pop those changes into a PR.

The sh -> dash link was a fun bit of reading for sure!

some history on why ubuntu made the switch

amonks commented 8 months ago

woah thatā€™s crazy. 7 seconds of startup time just from starting bash a lot!

ecshreve commented 8 months ago

i laughed a little at the response "Your suspicion is entirely correct." might try to work that into some conversations

ecshreve commented 8 months ago

there is a very subtle difference in the download URL for the latest release, and the url for any other release, noting it here

LATEST RELEASE https://github.com/amonks/run/releases/latest/download/<archive>

ANY OTHER VERSIONED RELEASE https://github.com/amonks/run/releases/download/<version>/<archive>

ecshreve commented 8 months ago

šŸŸ¢ so this works ONLY for latest curl -L "https://github.com/amonks/run/releases/latest/download/run_Darwin_arm64.tar.gz"

āŒ this does not (404) curl -L "https://github.com/amonks/run/releases/download/latest/run_Darwin_arm64.tar.gz"

āŒ this does not (404) curl -L "https://github.com/amonks/run/releases/v1.0.0-beta.27/download/run_Darwin_arm64.tar.gz"

šŸŸ¢ this works (for all other releases as well) curl -L "https://github.com/amonks/run/releases/download/v1.0.0-beta.27/run_Darwin_arm64.tar.gz"

amonks commented 8 months ago

I wonder if they added the latest endpoint more recently, so that folks wouldn't have to hit the releases API in scripts like this. That might explain (1) why it's different and (2) why so many scripts in the wild use the releases API.