From 344bcea320a63443713909b4540443f4f765093a Mon Sep 17 00:00:00 2001 From: Alex Flores Date: Sat, 24 Feb 2024 11:53:14 -0500 Subject: [PATCH 1/2] adds starnet2 --- Casks/s/starnet2.rb | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Casks/s/starnet2.rb diff --git a/Casks/s/starnet2.rb b/Casks/s/starnet2.rb new file mode 100644 index 000000000000..c18ea091e3bd --- /dev/null +++ b/Casks/s/starnet2.rb @@ -0,0 +1,66 @@ +cask "starnet2" do + version "02,2023" + sha256 "d566cd0a59d15894a3b027354812707b4408ca0917275af36602520f4ddec918" + + url "https://www.starnetastro.com/wp-content/uploads/#{version.csv.second}/#{version.csv.first}/StarNet2T_MacOS.zip" + name "starnet2" + desc "Removes stars from astrophotography images using ML models" + homepage "https://www.starnetastro.com/" + + livecheck do + url "https://www.starnetastro.com/experimental/" + regex(%r{uploads/(\d+)/(\d+)/StarNet2T_MacOS.zip}i) + strategy :page_match do |page, regex| + page.scan(regex).map { |match| "#{match[1]},#{match[0]}" } + end + end + + depends_on arch: :arm64 + + bin_path = "#{staged_path}/StarNet2T_MacOS" + installer = "#{bin_path}/installer.sh" + shim = "#{bin_path}/shim.sh" + + installer script: { + executable: installer, + sudo: true, + } + binary shim, target: "starnet2" + + preflight do + File.write installer, <<~EOS + #!/bin/sh + + chmod 0755 #{bin_path}/lib/* + mkdir -p /usr/local/lib + cp #{bin_path}/lib/* /usr/local/lib/ + EOS + + File.write shim, <<~EOS + #!/bin/sh + + # delete the symlink on process exit + cleanup() { + rm -f StarNet2_weights.pt + } + trap cleanup RETURN EXIT SIGINT SIGKILL + + # the binary hardcodes the weights path so we have to symlink it to the CWD + ln -sf #{bin_path}/StarNet2_weights.pt . + #{bin_path}/starnet2 $@ + EOS + end + + uninstall delete: [ + "/usr/local/lib/libc10.dylib", + "/usr/local/lib/libopencv_*", + "/usr/local/lib/libtorch.dylib", + "/usr/local/lib/libtorch_cpu.dylib", + ] + + # No zap stanza required + # + caveats do + files_in_usr_local + end +end From c1e165462e4d9e271638414acd21a2e31789e8ce Mon Sep 17 00:00:00 2001 From: Alex Flores Date: Sun, 25 Feb 2024 16:01:29 -0500 Subject: [PATCH 2/2] be more explicit about which libs are rm-ed --- Casks/s/starnet2.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Casks/s/starnet2.rb b/Casks/s/starnet2.rb index c18ea091e3bd..b08cc78ec888 100644 --- a/Casks/s/starnet2.rb +++ b/Casks/s/starnet2.rb @@ -51,15 +51,21 @@ EOS end - uninstall delete: [ - "/usr/local/lib/libc10.dylib", - "/usr/local/lib/libopencv_*", - "/usr/local/lib/libtorch.dylib", - "/usr/local/lib/libtorch_cpu.dylib", - ] + uninstaller = "#{bin_path}/uninstaller.sh" + uninstall_preflight do + libs = Dir.children("#{caskroom_path}/#{version}/StarNet2T_MacOS/lib").map { |lib| "/usr/local/lib/#{lib}" } + File.write uninstaller, <<~EOS + rm #{libs.join(" ")} + EOS + end + + uninstall script: { + executable: uninstaller, + sudo: true, + } # No zap stanza required - # + caveats do files_in_usr_local end