Stream: beginners

Topic: roc nightly install script


view this post on Zulip Rene Mailaender (Apr 13 2023 at 20:44):

Hey everyone,
with the help of rocs ci scripts, i wrote a little bash script that installs the latest roc build as /roc_nightly/. That way i don't have to wget, tar rename and so on by hand. maybe thats helpful for others too, so i thought i share it here:

set -euxo pipefail

rm -rf roc_nightly
rm roc_nightly.tar.gz

curl --request GET \
          --url https://api.github.com/repos/roc-lang/roc/releases \
          --header 'content-type: application/json' \
          --output roc_releases.json

arch=linux_x86_64
LATEST_RELEASE_URL=`cat roc_releases.json | jq --arg arch $arch '.[0] | .assets | map(.browser_download_url) | map(select(. | contains("\($arch)-"))) | last'`

if [[ "$LATEST_RELEASE_URL" == "null" ]]
then
  echo "I expected to get a url but I got null instead. The provided argument for this bash script may not have had any matches when used as arch in the jq query above."
  exit 1
fi

DL=`echo "$LATEST_RELEASE_URL" | sed 's/\"//g'`


wget -c -O roc_nightly.tar.gz $DL

mkdir roc_nightly

tar -zxf roc_nightly.tar.gz -C roc_nightly --strip-components=1

rm roc_nightly.tar.gz
rm roc_releases.json

view this post on Zulip Zeljko Nesic (Apr 18 2023 at 12:14):

@Rene Mailaender great stuff! Small question: what should be the $AUTH_HEADER value?

view this post on Zulip Rene Mailaender (Apr 18 2023 at 12:22):

oh. good question. i think that’s included by mistake. (copy paste inheritance) i never set that variable and the script worked non the less. but i double check that later. thx

view this post on Zulip Anton (Apr 18 2023 at 13:13):

Yeah, you can leave the --header '$AUTH_HEADER' \ out, it's only necessary on CI machines

view this post on Zulip Rene Mailaender (Apr 18 2023 at 17:26):

yes you are right. have removed it from the snippet. :)

view this post on Zulip Hannes (Jul 06 2023 at 04:08):

Becuase of the new naming of the nightly releases I was able to condense the install script into one line:

curl --fail --location 'https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-linux_x86_64-latest.tar.gz' | tar --directory $HOME/bin --extract --gzip --strip-components 1 --file - --wildcards 'roc_nightly-*/roc'

If you want to use it you'd need to change the linux_x86_64 to your OS and architecture and the $HOME/bin to the location you want to install the Roc binary

view this post on Zulip Richard Feldman (Jul 06 2023 at 10:31):

nice! :smiley:

An even shorter version (which at least chatGPT thinks is equivalent):

curl -fL 'https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-linux_x86_64-latest.tar.gz' | tar -xz -C $HOME/bin --strip-components 1 -f - 'roc_nightly-*/roc'

view this post on Zulip Hannes (Jul 06 2023 at 12:25):

Ah yeah, I wrote it for a docker container so I expanded out all the flags to make it more maintainable.

I'm surprised it removed the --wildcards option, but after googling it looks like the default behaviour for most tar implementations is to treat filter paths as globs :shrug:

view this post on Zulip Ajai Nelson (Jul 08 2023 at 03:49):

Hannes said:

Becuase of the new naming of the nightly releases I was able to condense the install script into one line:

curl --fail --location 'https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-linux_x86_64-latest.tar.gz' | tar --directory $HOME/bin --extract --gzip --strip-components 1 --file - --wildcards 'roc_nightly-*/roc'

If you want to use it you'd need to change the linux_x86_64 to your OS and architecture and the $HOME/bin to the location you want to install the Roc binary

For others who want to use this, I had to remove the --wildcards to get it to work on my mac. Thanks for sharing this!

view this post on Zulip Hannes (Jul 08 2023 at 04:37):

Ah, probably a GNU tar specific option :sweat_smile:

view this post on Zulip Logan Lowder (Jul 10 2023 at 15:15):

Richard Feldman said:

nice! :smiley:

An even shorter version (which at least chatGPT thinks is equivalent):

curl -fL 'https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-linux_x86_64-latest.tar.gz' | tar -xz -C $HOME/bin --strip-components 1 -f - 'roc_nightly-*/roc'

This version didn't work for me on Ubuntu. :thinking:

tar: Pattern matching characters used in file names
tar: Use --wildcards to enable pattern matching, or --no-wildcards to suppress this warning
tar: roc_nightly-*/roc: Not found in archive
tar: Exiting with failure status due to previous errors

The original one @Hannes shared works.

view this post on Zulip Richard Feldman (Jul 10 2023 at 15:46):

interesting, so I guess you need --wildcards on Linux but need to omit it on macOS?

view this post on Zulip Logan Lowder (Jul 10 2023 at 16:12):

I guess so :thinking:

$ tar --version
tar (GNU tar) 1.34

view this post on Zulip Hannes (Jul 10 2023 at 16:32):

If you have GNU tar installed on Mac OS it's normally called gtar, but I don't think that's very common :/

view this post on Zulip Richard Feldman (Jul 10 2023 at 16:40):

gtar :guitar:

view this post on Zulip Ajai Nelson (Jul 10 2023 at 17:47):

This is super hacky, but if you use TAR_OPTIONS=--wildcards tar ..., it seems to work with both tar and gtar because only GNU tar supports TAR_OPTIONS

view this post on Zulip Hannes (Mar 07 2024 at 09:23):

Updated install one-liner that installs Roc and the Roc language server on MacOS and Linux (except Alpine), you just need to export two environment variables:

export ROC_OS=... ROC_OUTPUT_LOCATION=... && mkdir -p $ROC_OUTPUT_LOCATION && curl --fail --location "https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-$ROC_OS-latest.tar.gz" | TAR_OPTIONS=--wildcards tar --directory $ROC_OUTPUT_LOCATION --extract --gzip --strip-components 1 --file - 'roc_nightly-*/roc' 'roc_nightly-*/roc_language_server'

Thanks @Ajai Nelson for the TAR_OPTIONS hack :)

view this post on Zulip Ajai Nelson (Mar 07 2024 at 09:35):

I'm not sure I should be thanked for that lol, it's a little horrifying

view this post on Zulip Hannes (Mar 07 2024 at 11:11):

If it works, it works! :sweat_smile:


Last updated: Jul 05 2025 at 12:14 UTC