Gem installer and scripts

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

On 9/21/06, Ted T. [email protected] wrote:

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.

Wilson B. wrote:

On 9/21/06, Ted T. [email protected] wrote:

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.

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.

Ted T. wrote:

of your gem:
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 A.'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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs