Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy a shell script with Ruby gem and install in bin directory

I wish to place a shell script in my gem's bin dir, along with other Ruby programs that belong to the package. I wish to have this shell script installed in the bin directory as-is (that is, no wrappers). Is that possible with Ruby gems at all? I would be happy with post-install hooks if not otherwise possible. Anybody has any experience with this?

like image 911
scientistician Avatar asked May 16 '14 17:05

scientistician


People also ask

Where do RubyGems install to?

When you use the --user-install option, RubyGems will install the gems to a directory inside your home directory, something like ~/. gem/ruby/1.9. 1 . The commands provided by the gems you installed will end up in ~/.

How do I release a gem to RubyGems?

Publishing to RubyGems.orgVisit the sign up page and supply an email address that you control, a handle (username) and a password. After creating the account, use your email and password when pushing the gem. (RubyGems saves the credentials in ~/. gem/credentials for you so you only need to log in once.)

How install RubyGems manually in Kali Linux?

Step 1: In order to install RubyGems, first we need to install ruby on Linux. Run the following command on the terminal to install ruby. Step 2: Go to the RubyGems download page and click on the zip button, this will download the zip through which you can install RubyGems.

How do I install gems?

To install a gem, use gem install [gem] . Browsing installed gems is done with gem list . For more information about the gem command, see below or head to RubyGems' docs. There are other sources of libraries though.


1 Answers

This issue is described here: https://github.com/rubygems/rubygems/issues/88

If the gem you're developing is intended only for your own use, you can simply install it with

gem install --no-wrapper my_gem

I think you'd best write a ruby script which runs your bash script. Here's an example on how to do that:


bin/test_gem

#!/usr/bin/env ruby

bin_dir = File.expand_path(File.dirname(__FILE__))
shell_script_path = File.join(bin_dir, 'test_gem.sh')

`#{shell_script_path}`

bin/test_gem.sh

#!/bin/sh

echo "Hello World!"

test_gem.gemspec

spec.files = [
  # ...
  'bin/test_gem', 'bin/test_gem.sh'
]

# ...

spec.executables = ['test_gem']

NOTE: Don't forget to set both files in the bin folder to executable!

Note that while test_gem.sh is registered with the files Rubygems command, it's not registered as executables: it will just be placed in the installed gem's dir but not wrapped/shimmed.

If you install your gem (and run rbenv rehash if necessary), calling test_gem will result in the ruby script executing your shell script.

like image 156
codegourmet Avatar answered Sep 18 '22 17:09

codegourmet