Install script for macOS; latest .dmg doesn't work for me

G’day,

I wrote this script a while ago and just updated it today to work again, given the changes since it last worked a few years or so ago, before URLs and filenames and similar bitrot occurred.

So, while the script is working, YaCy is not.

The script hasn’t been published yet and the supporting libraries mostly aren’t available until it is published, but I figured someone might find it useful anyway. I will update here once published in full.

Meantime, is there a version for macOS that doesn’t immediately quit?..

I’m installing yacy_v1.930_202405130205_59c0cb0f3.dmg on macOS 15.3.1.

Also, I’m revisiting this because Stalag 61 (Australia) is rapidly approaching needing ID to use a search engine FFS! You’ll probably see a lot more Aussies here soon!

Cheers,

thoran

#!/usr/bin/env ruby
# install_yacy

# 20250705
# 0.3.0

# Prerequisite: Ruby is installed, which it should be already!

# How to use:
# 1. Press the <cmd> and <space> keys on the keyboard simultaneously.
# 2. Type: "Terminal.app" and press the <return> key.
# 3. Type: "cd <the directory where this can be found>"
# 3. Type: "ruby ./install_yacy" and press the <return> key.
# 5. If prompted, enter the password you use to login to your computer.
# 6. YaCy will then open a tab in your default web browser pointing at the address http://localhost:8090.
# 7. When wanting to stop YaCy, find the dock icon (A white box with a cartoon character with a red nose.) and quit it.

# Todo: (one or more of the following, in no particular order)
# 1. Turn this into a brew formula.
# 2. Remove some of the comments here and put those into a README or INSTALL or other files as appropriate.
# 3. Create a(n) .app out of this by using some simple wrapper code.
# 4. Make it cross-platform: OSX, Linux, and Windows, at least.
# 5. Clean up the required libraries so that they are either gemified and/or reduced in number.

# Changes:
# -/0: http://latest.yacy.net seems to have been replaced with https://download.yacy.net.
# 1. + require 'Kernel/require_gem'
# 2. /require_nokogiri/require_gem 'nokogiri'/
# 3. Remove self-run section around main.
# 4. + openjdk_installed?()
# 5. ~ main(): Use openjdk_installed?()
# 6. ~ latest_macos_yacy_filename(): /latest.yacy.net/download.yacy.net/
# 7. + yacy_already_downloaded?()
# 8. ~ download_yacy(): Use yacy_already_downloaded?()
# 9. ~ dmg_filename(): Use latest_macos_yacy_filename().
# 10. + latest_macos_yacy_filename_without_extname()
# 11. ~ copy_yacy_to_applications_dir(): Use latest_macos_yacy_filename_without_extname().
# 12. ~ unmount_yacy_image(): Use latest_macos_yacy_filename_without_extname().

lib_dir = File.expand_path(File.join('..', '..', 'lib'), __FILE__)
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)

require 'File/self.basename_without_extname'
require 'fileutils'
require 'FileUtils/which'
require 'Kernel/require_gem'
require 'Kernel/run'
require 'MacOS/Dmg'
require 'open-uri'

require_gem 'nokogiri'

def homebrew_installed?
  FileUtils.which('brew')
end

def openjdk_installed?
  !`brew list openjdk`.match(/Error: No available formula with the name "openjdk"\./)
end

def yacy_installed?
  File.exist?("/Users/#{current_user}/Applications/YaCy.app") ||
    File.exist?("/Applications/YaCy.app")
end

def install_homebrew
  run('/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"', show: true)
end

def link_openjdk
  run('sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk', show: true)
end

def install_openjdk
  run('brew install openjdk', show: true)
  link_openjdk
end

def latest_macos_yacy_filename
  @latest_macos_yacy_filename ||=(
    doc = Nokogiri.HTML(URI.open('http://download.yacy.net'))
    doc.search('a').map{|e| e[:href]}.reverse.detect{|e| e =~ /\.dmg/}
  )
end

def url_for_latest_macos_yacy_file
  "http://download.yacy.net/#{latest_macos_yacy_filename}"
end

def current_user
  ENV['USER']
end

def yacy_already_downloaded?
  File.exist?(dmg_filename)
end

def download(url)
  filename = File.basename(url)
  File.open(filename, 'wb') do |file|
    file.write(URI.open(url).read)
  end
end

def download_dir
  "/Users/#{current_user}/Downloads"
end

def download_yacy
  Dir.chdir(download_dir)
  download(url_for_latest_macos_yacy_file) unless yacy_already_downloaded?
end

def dmg_filename
  "#{download_dir}/#{latest_macos_yacy_filename}"
end

def mount_yacy_image
  MacOS::Dmg.mount(dmg_filename)
end

def latest_macos_yacy_filename_without_extname
  File.basename_without_extname(latest_macos_yacy_filename)
end

def copy_yacy_to_applications_dir
  if Dir.exist?("/Users/#{current_user}/Applications")
    FileUtils.cp_r("/Volumes/#{latest_macos_yacy_filename_without_extname}/#{latest_macos_yacy_filename_without_extname}.app", "/Users/#{current_user}/Applications/YaCy.app")
  else
    FileUtils.cp_r("/Volumes/#{latest_macos_yacy_filename_without_extname}/#{latest_macos_yacy_filename_without_extname}.app", '/Applications/YaCy.app')
  end
end

def unmount_yacy_image
  MacOS::Dmg.unmount(latest_macos_yacy_filename_without_extname)
end

def install_yacy
  download_yacy
  mount_yacy_image
  copy_yacy_to_applications_dir
  unmount_yacy_image
end

def start_yacy
  run("open -a 'YaCy'", show: true)
  # run('open http://localhost:8090', show: true) # This command is not necessary because `open -a YaCy` also does `open http://localhost:8090`, though I'd probably prefer it didn't.
end

def main
  unless yacy_installed?
    install_homebrew unless homebrew_installed?
    install_openjdk unless openjdk_installed?
    install_yacy
  end
  start_yacy
end

main
1 Like

I’m happy to admit error, insofar as that is version working, so perhaps the response might be to assist with troubleshooting that?