Slicer installation on Mac using homebrew

Since the script will run from a different machine, at first I will have it run at 8am EST. Is that too late ? Would you prefer to have the package as soon as it is available ?

That would be optimal, but I don’t think it’s critical.

I was planning to cron a script that constantly (like every half hour) whether the latest version corresponds to the current cask and repair it if needed. I guess something like that would do the trick.

We still need to have a more robust error checking, but the bulk of it is here:

# Get revision associated with the last successful caskrepair
last_revision=$(curl -# "https://raw.githubusercontent.com/caskroom/homebrew-versions/master/Casks/slicer-nightly.rb" | grep -e "^\s*version" | cut -d"," -f1 | cut -d"." -f4)

[[ -z $last_revision ]] && echo "Failed to extract revision from slicer-nightly.rb" && exit 1

# Get revision associated with the last macosx package
package_info=$(curl --progress-bar "http://download.slicer.org/find?os=macosx&stability=any")

version=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["version"])') && \
revision=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["revision"])') && \
bitstream_id=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["download_url"])' | cut -d"/" -f3)

[[ -z $revision ]] && echo "Failed to extract revision from Slicer package info" && exit 1

# If both revision match, we are all set
if [[ $last_revision ==  $revision ]]; then
  exit 0
fi

cask-repair --cask-version $version.$revision,$bitstream_id --fail-on-error --blind-submit slicer-nightly

Yes, that looks good. However, I think we also need to check whether a PR has already been sent with a call to cask-repair. Otherwise it will continue to create PRs until the first is accepted. What about keeping a local copy with info about the last repair?

# Get revision associated with the last requested update
revision_path="/tmp/slicer-version.txt"
last_requested_revision=`cat $revision_path`

[[ -z $last_requested_revision ]] && echo "Failed to extract revision from $revision_path" && exit 1

# Get revision associated with the last macosx package
package_info=$(curl --progress-bar "http://download.slicer.org/find?os=macosx&stability=any")

version=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["version"])') && \
revision=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["revision"])') && \
bitstream_id=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["download_url"])' | cut -d"/" -f3)

[[ -z $revision ]] && echo "Failed to extract revision from Slicer package info" && exit 1

# If both revision match, we are all set
if [[ $last_requested_revision ==  $revision ]]; then
  exit 0
fi

cask-repair --cask-version $version.$revision,$bitstream_id --fail-on-error --blind-submit slicer-nightly

echo $revision > $revision_path

P.S.: sometimes the bitstream ID changes and not the revision number. Why is that?

Yeahh. That was I did first … but wanted to have something with no state stored in local file. That will definitively work.

will continue to create PRs until the first is accepted.

Makes sense

sometimes the bitstream ID changes and not the revision number. Why is that?

If between Day 1 and Day 2 there is no commit done, we still build the package and upload it. Then, you will have the same revision but different id.

1 Like

I would recommend to not update the package immediately when the core installer is ready because by that time extensions are not available yet. Something like 8am Eastern time should work.

2 Likes

Actually, a PR won’t be created if there’s also one pending, the command will just fail. So I guess the script can be safely run daily without the local copy of the last submitted version.

I keep updating the cask from time to time, but still think it could be done automatically every day: Slicer installation on Mac using homebrew

@jcfr what do you think?

I might be the only person in the world updating Slicer with brew, but in case someone else is interested, I just submitted a PR so that the cask for the nightly version doesn’t need to be updated every day: https://github.com/Homebrew/homebrew-cask-versions/pull/7538

You are not the only one

1 Like

FYI Slicer nightly slicer-nightly can be installed by running:

brew cask install slicer-nightly

and upgraded:

brew cask upgrade slicer-nightly
1 Like

In the last upgrade I have obtained:

==> Installing Cask slicer-nightly
==> Purging files for version latest of Cask slicer-nightly
Error: No such file or directory @ rb_sysopen - /usr/local/Caskroom/slicer-nightly/.metadata/latest.upgrading/20190806090848.651/Casks/slicer-nightly.rb
Follow the instructions here:
  https://github.com/Homebrew/homebrew-cask#reporting-bugs
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1393:in `initialize'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1393:in `open'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1393:in `copy_file'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:487:in `copy_file'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:404:in `block in cp'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1572:in `block in fu_each_src_dest'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1586:in `fu_each_src_dest0'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1570:in `fu_each_src_dest'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:403:in `cp'
/usr/local/Homebrew/Library/Homebrew/cask/installer.rb:388:in `save_caskfile'
/usr/local/Homebrew/Library/Homebrew/cask/installer.rb:78:in `stage'
/usr/local/Homebrew/Library/Homebrew/cask/installer.rb:99:in `install'
/usr/local/Homebrew/Library/Homebrew/cask/installer.rb:126:in `reinstall'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/reinstall.rb:13:in `block in run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/reinstall.rb:7:in `each'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/reinstall.rb:7:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/abstract_command.rb:36:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:93:in `run_command'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:159:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:124:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:9:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:102:in `<main>'

Now slicer nightly is broken, it used to work really fine until last week!

Hi Alex,

It works for me. If you still have problems, you can create an issue on the homebrew-cask repo.

PR to update the cask submitted: https://github.com/Homebrew/homebrew-cask/pull/90632

1 Like

PR to update the name of the cask for the nightly preview version: https://github.com/Homebrew/homebrew-cask-versions/pull/9751

Documentation updated: https://www.slicer.org/wiki/Documentation/Labs/HomebrewCask

1 Like