Skip to content

Instantly share code, notes, and snippets.

@monkstone
Last active October 25, 2019 06:01
Show Gist options
  • Save monkstone/159c5a9813c9cd181040b4715e74f6b2 to your computer and use it in GitHub Desktop.
Save monkstone/159c5a9813c9cd181040b4715e74f6b2 to your computer and use it in GitHub Desktop.
Install JRuby and PiCrate on debian (Rakefile)
if [ -z $GEM_HOME ]; then
mkdir -p ~/.gem/ruby/2.5.0/bin
echo "export GEM_HOME=\"\${HOME}/.gem/ruby/2.5.0\"" >> ~/.profile
echo "export GEM_PATH=\"\${HOME}/.gem/ruby/2.5.0\"" >> ~/.profile
echo "export PATH=\"\${PATH}:\${GEM_PATH}/bin\"" >> ~/.profile
echo "gem: --no-document" >> ~/.gemrc
source ~/.profile
fi
# frozen_string_literal: true
require 'rake/clean'
WARNING = <<-WARN.freeze
WARNING: Something has gone wrong with download
check that the JRUBY_VERSION and download path
are still valid
WARN
JRUBY_VERSION = '9.2.8.0'.freeze
URL = [
'https://repo1.maven.org',
'maven2',
'org',
'jruby',
'jruby-dist',
JRUBY_VERSION,
"jruby-dist-#{JRUBY_VERSION}-bin.tar.gz"
].join('/').freeze
SHA256 = [
URL,
'sha256'
].join('.').freeze
CLOBBER << "jruby-dist-#{JRUBY_VERSION}-bin.tar.gz"
CLOBBER << "jruby-dist-#{JRUBY_VERSION}-bin.tar.gz.sha256"
task default: %i[download_jruby install_jruby install_gem]
desc 'Downloading JRuby'
task :download_jruby do
begin
sh "wget #{URL}"
sh "wget #{SHA256}"
rescue
warn(WARNING)
end
value = File.read("jruby-dist-#{JRUBY_VERSION}-bin.tar.gz.sha256")
check_sha256("jruby-dist-#{JRUBY_VERSION}-bin.tar.gz", value)
end
desc 'Install JRuby'
task :install_jruby do
tar_ball = File.join(Dir.pwd, "jruby-dist-#{JRUBY_VERSION}-bin.tar.gz")
Dir.chdir('/opt') do
sh "sudo tar xzvf #{tar_ball}"
end
sh "sudo update-alternatives --install /usr/bin/jruby jruby /opt/jruby-#{JRUBY_VERSION}/bin/jruby 51"
sh "sudo update-alternatives --install /usr/bin/jirb jirb /opt/jruby-#{JRUBY_VERSION}/bin/jirb 51"
sh "sudo update-alternatives --install /usr/bin/jgem jgem /opt/jruby-#{JRUBY_VERSION}/bin/jgem 51"
end
def check_sha256(filename, expected_hash)
require 'digest'
sha256 = Digest::SHA256.new
File.open(filename, 'r') do |f|
while (buf = f.read(4096))
sha256.update(buf)
end
end
return if sha256.hexdigest == expected_hash
raise "bad sha256 checksum for #{filename} (expected #{expected_hash} got #{sha256.hexdigest})"
end
desc 'install gem'
task :install_gem do
sh 'jgem install picrate'
end
@monkstone
Copy link
Author

monkstone commented Dec 3, 2018

This rakefile is for first time install of JRuby on a debian system (real target is raspbian for raspberryPI) for PiCrate users.
Put this file in its own folder say installer then rake

@scruss
Copy link

scruss commented Oct 24, 2019

suggesting

  echo "export PATH=\"\${PATH}:\${GEM_PATH}/bin\"" >> ~/.profile

for L5 of gem_path.sh: fixes typo and is more polite with paths.

@monkstone
Copy link
Author

@scruss thanks! Also seems as though there has been mix-up on released gem which I need to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment