gem installer and scripts

T

Ted Toth

Is there a way to get gem to run a script during an install similar to
rpms pre/post-install? How do others deal with needing to copy files or
create links etc. during a gem install?

Ted
 
W

Wilson Bilkovich

Is there a way to get gem to run a script during an install similar to
rpms pre/post-install? How do others deal with needing to copy files or
create links etc. during a gem install?

Include a script with one of the following names in the base directory
of your gem:
install.rb
post-install.rb
uninstall.rb

They get run pretty much when the names suggest. See gems like
activerecord, rake, and rmagick for examples.
 
T

Ted Toth

Wilson said:
Include a script with one of the following names in the base directory
of your gem:
install.rb
post-install.rb
uninstall.rb

They get run pretty much when the names suggest. See gems like
activerecord, rake, and rmagick for examples.

Thanks. I created a post-install.rb and tested it but it doesn't get run
during the install as best I can tell. I've looked at the gem code and I
don't see code that would run my post-install.rb script maybe I just
missed it but ... Would you know where this happens? I did look at gems
already on my system but they only contain install.rb files.
 
T

Timothy Hunter

Ted said:
Thanks. I created a post-install.rb and tested it but it doesn't get run
during the install as best I can tell. I've looked at the gem code and I
don't see code that would run my post-install.rb script maybe I just
missed it but ... Would you know where this happens? I did look at gems
already on my system but they only contain install.rb files.
I can only speak for RMagick, but fwiw,

install.rb was Minero Aoki's generic Ruby library/application installer
script, which predates RubyGems. I've since replaced it in the RMagick
install with Minero's setup.rb
(http://i.loveruby.net/en/projects/setup/). (This is the same setup.rb
that you run to install RubyGems the first time.) The
install.rb/setup.rb scheme defines three steps during installation:
config, setup, and install. Each specific application/library can define
"hooks" that run before or after each step. A "hook" is a Ruby program.
The hook scripts are identified by their name, which is "pre-" or
"post-" followed by the step name. Thus "post-install.rb" is a hook that
runs after the install step. Therefore setup.rb runs the RMagick
post-install.rb hook after it completes the standard installation tasks.
In the RMagick case, post-install.rb copies the RMagick documentation
files to the doc directory. The install.rb/setup.rb process doesn't
define an uninstall step, so for RMagick, I provided a uninstall.rb
script that can be executed for the "make uninstall" target, or simply
by running "ruby uninstall.rb" from the command line.

Probably RMagick isn't a good model for an installation process. RMagick
was out there before there was a RubyGems, so I created an installation
process based on the at-the-time-standard install.rb/setup.rb code.
Later, at the request of an important but traditionally-minded supporter
I hacked a GNU configure/make/make install over that, and when RubyGems
came out I hacked it to work with RubyGems. I'm sure Rake and
activerecord are much better models.

The last time I checked RubyGems, for security purposes, did not support
the execution of arbitrary user-supplied scripts. Remember RubyGems may
be running with root/admin priviledges, so it wouldn't be wise to allow
just any ol' Ruby library developer to add code to the installation
process. To the best of my knowledge, if you can't specify it in a
gemfile you can't make RubyGems do it. If I'm wrong I'm sure somebody
will correct me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top