Install.rb/setup.rb question

I want to install a script that will be run as an executable which isn’t a
big problem on *nix, just put:
#!<path_to_ruby>
on the first line and make the file executable.

However <path_to_ruby> can vary depending on which flavor of *nix or even
which flavor of Linux you’re using and how ruby was installed.

So my question is, does install.rb take care of this? ie. for each script
in your package’s /bin directory does it prepend the #!<path_to_ruby>
prior to installing the script?

Also… I would guess that unless you’re running cygwin under Windows
that install.rb wouldn’t be too useful for installing a package on the
Windows platform, correct?

Phil

What about using

#! /usr/bin/env ruby

···

On Tuesday, 19 November 2002 at 5:09:27 +0900, Phil Tomson wrote:

I want to install a script that will be run as an executable which isn’t a
big problem on *nix, just put:
#!<path_to_ruby>
on the first line and make the file executable.

However <path_to_ruby> can vary depending on which flavor of *nix or even
which flavor of Linux you’re using and how ruby was installed.

So my question is, does install.rb take care of this? ie. for each script
in your package’s /bin directory does it prepend the #!<path_to_ruby>
prior to installing the script?

Also… I would guess that unless you’re running cygwin under Windows
that install.rb wouldn’t be too useful for installing a package on the
Windows platform, correct?


Jim Freeze

New systems generate new problems.

Also… I would guess that unless you’re running cygwin under Windows
that install.rb wouldn’t be too useful for installing a package on the
Windows platform, correct?

I copped the essentials from the RDoc install script to create the install
script for Rimport, and it seems to work fine on Windows.

James

···

Hi,

···

At Tue, 19 Nov 2002 05:09:27 +0900, Phil Tomson wrote:

So my question is, does install.rb take care of this? ie. for each script
in your package’s /bin directory does it prepend the #!<path_to_ruby>
prior to installing the script?

You mean setup package by Minero Aoki? If so, that install.rb
rewrites (not prepend) shebangs in scripts under /bin directory
automatically according to --ruby-path command line option for
config, and it’s defaulted to ${bindir}/${ruby_install_name}.


Nobu Nakada

In article 20021118153749.A13574@freeze.org,

···

Jim Freeze jim@freeze.org wrote:

On Tuesday, 19 November 2002 at 5:09:27 +0900, Phil Tomson wrote:

I want to install a script that will be run as an executable which isn’t a
big problem on *nix, just put:
#!<path_to_ruby>
on the first line and make the file executable.

However <path_to_ruby> can vary depending on which flavor of *nix or even
which flavor of Linux you’re using and how ruby was installed.

So my question is, does install.rb take care of this? ie. for each script
in your package’s /bin directory does it prepend the #!<path_to_ruby>
prior to installing the script?

Also… I would guess that unless you’re running cygwin under Windows
that install.rb wouldn’t be too useful for installing a package on the
Windows platform, correct?

What about using

#! /usr/bin/env ruby

Oh, good idea. It seems to work on Linux. Does it work on other *nix’s
as well?

Phil

In article 200211190104.gAJ14NH05620@sharui.nakada.kanuma.tochigi.jp,

Hi,

So my question is, does install.rb take care of this? ie. for each script
in your package’s /bin directory does it prepend the #!<path_to_ruby>
prior to installing the script?

You mean setup package by Minero Aoki?

Yes, that’s the one.

If so, that install.rb
rewrites (not prepend) shebangs in scripts under /bin directory
automatically according to --ruby-path command line option for
config, and it’s defaulted to ${bindir}/${ruby_install_name}.

I don’t see the ‘#!/usr/bin/ruby’ line being added to the scripts in the
/bin directory.

When I run:

ruby install.rb setup

I see the following messages:

"
install.rb: entering setup phase…
—> bin
set #! line to “#!/usr/bin/ruby” for
/home/phil/ruby_stuff/raa_exec/bin/raa_exec …
rm -f raa_exec.tmp
<— bin
install.rb: setup done.
"

So it looks like it’s going to add the shebang, but when I look at the
installed file it’s not there…

…later…

Ok, I went off and did some investigation of the sourcecode and tried some
things out. Here’s the scoop:

  1. If you have no shebang at the top of a script in the bin directory
    you’ll get now shebang+path_to_ruby_bin added.
  2. if you have: ‘#!/usr/bin/env ruby’ for the first line of the script it
    will not be changed.
  3. if you have: ‘#!ruby’ it’ll be expanded to: ‘#!/usr/bin/ruby’ (or
    whatever the actual path to your ruby executable is.) Actually, it uses
    the following regex: /\A#!\s*\Sruby\S/
    so I found that if I had: #!/usr/bin/ruby and then ran config and setup
    with another version of Ruby that I have installed elsewhere it would get
    changed to (in this particular case):
    #!/home/phil/ruby_1.7.3/bin/ruby

So it seems to do what I would expect. The reason why it didn’t work
initially was that I had: ‘#!/usr/bin/env ruby’ or no shebang at all
and install.rb doesn’t change it (special cases).

Phil

···

nobu.nokada@softhome.net wrote:

At Tue, 19 Nov 2002 05:09:27 +0900, >Phil Tomson wrote:

See [ruby-talk:27508] for a better way.

Paul

···

On Tue, Nov 19, 2002 at 05:32:14AM +0900, Jim Freeze wrote:

What about using

#! /usr/bin/env ruby

Yes.
Overall, it depends on /usr/bin/env existing. From what I can tell, it seems
ubiquitous(sp?). If your environment is somewhat controlled, it
is a great solution. If your environment is not controlled, it is a good
solution. One plus is, that you can change your path to point
to a different install of Ruby and it will automatically use
the right version. However, if the path in hardcoded in the shebang
operator, then you are stuck with using the ruby that it points
to.
(Using env also lets you control environment variables.)

···

On Tuesday, 19 November 2002 at 6:29:36 +0900, Phil Tomson wrote:

In article 20021118153749.A13574@freeze.org,
Jim Freeze jim@freeze.org wrote:

On Tuesday, 19 November 2002 at 5:09:27 +0900, Phil Tomson wrote:

I want to install a script that will be run as an executable which isn’t a
big problem on *nix, just put:
#!<path_to_ruby>
on the first line and make the file executable.

However <path_to_ruby> can vary depending on which flavor of *nix or even
which flavor of Linux you’re using and how ruby was installed.

So my question is, does install.rb take care of this? ie. for each script
in your package’s /bin directory does it prepend the #!<path_to_ruby>
prior to installing the script?

Also… I would guess that unless you’re running cygwin under Windows
that install.rb wouldn’t be too useful for installing a package on the
Windows platform, correct?

What about using

#! /usr/bin/env ruby

Oh, good idea. It seems to work on Linux. Does it work on other *nix’s
as well?


Jim Freeze

Vote for ME – I’m well-tapered, half-cocked, ill-conceived and
TAX-DEFERRED!

I’m sorry for too late replying…

In mail “Re: install.rb/setup.rb question”

Ok, I went off and did some investigation of the sourcecode and tried some
things out. Here’s the scoop:

  1. If you have no shebang at the top of a script in the bin directory
    you’ll get now shebang+path_to_ruby_bin added.
  2. if you have: ‘#!/usr/bin/env ruby’ for the first line of the script it
    will not be changed.
  3. if you have: ‘#!ruby’ it’ll be expanded to: ‘#!/usr/bin/ruby’ (or
    whatever the actual path to your ruby executable is.) Actually, it uses
    the following regex: /\A#!\s*\Sruby\S/
    so I found that if I had: #!/usr/bin/ruby and then ran config and setup
    with another version of Ruby that I have installed elsewhere it would get
    changed to (in this particular case):
    #!/home/phil/ruby_1.7.3/bin/ruby

So it seems to do what I would expect. The reason why it didn’t work
initially was that I had: ‘#!/usr/bin/env ruby’ or no shebang at all
and install.rb doesn’t change it (special cases).

That’s right.
install.rb/setup.rb does not change the shebang line when #! does not
exist, because the installer must not modify non-script (binary) file.

Since /usr/bin/env trick is also useful, install.rb/setup.rb should not
modify it (The author might select it intentionaly). But if the shebang
line is /usr/local/bin/ruby or /usr/bin/ruby, that’s dangerous. In the
case, the installer should modify it.

– Minero Aoki

···

ptkwt@shell1.aracnet.com (Phil Tomson) wrote:

Thanks for the little dissertation on this.
Very informative.
Is this in the FAQ or somewhere?

···

On Wednesday, 20 November 2002 at 6:10:52 +0900, Phil Tomson wrote:

So it seems to do what I would expect. The reason why it didn’t work
initially was that I had: ‘#!/usr/bin/env ruby’ or no shebang at all
and install.rb doesn’t change it (special cases).


Jim Freeze

There’s so much plastic in this culture that vinyl leopard skin is
becoming an endangered synthetic.
– Lily Tomlin

Better only for Unix.

-austin
– Austin Ziegler, austin@halostatue.ca on 2002.11.20 at 11.40.17

···

On Thu, 21 Nov 2002 00:24:49 +0900, Paul Brannan wrote:

On Tue, Nov 19, 2002 at 05:32:14AM +0900, Jim Freeze wrote:

What about using
#! /usr/bin/env ruby
See [ruby-talk:27508] for a better way.

Hi,

···

At Tue, 19 Nov 2002 07:01:29 +0900, Jim Freeze wrote:

Overall, it depends on /usr/bin/env existing. From what I can tell, it seems
ubiquitous(sp?). If your environment is somewhat controlled, it
is a great solution. If your environment is not controlled, it is a good
solution. One plus is, that you can change your path to point
to a different install of Ruby and it will automatically use
the right version. However, if the path in hardcoded in the shebang
operator, then you are stuck with using the ruby that it points
to.
(Using env also lets you control environment variables.)

OTOH, it may cause a security issue.


Nobu Nakada

Just as a data point, it does NOT work on my vanilla Mandrake 9.0
system.

···

On Tue, 19 Nov 2002 07:01:29 +0900, Jim Freeze wrote:

Yes.
Overall, it depends on /usr/bin/env existing. From what I can tell, it seems
ubiquitous(sp?). If your environment is somewhat controlled, it
is a great solution. If your environment is not controlled, it is a good
solution. One plus is, that you can change your path to point
to a different install of Ruby and it will automatically use
the right version. However, if the path in hardcoded in the shebang
operator, then you are stuck with using the ruby that it points
to.
(Using env also lets you control environment variables.)

So it seems to do what I would expect. The reason why it didn’t work
initially was that I had: ‘#!/usr/bin/env ruby’ or no shebang at all
and install.rb doesn’t change it (special cases).

Thanks for the little dissertation on this.
Very informative.
Is this in the FAQ or somewhere?

It’s just waiting for you to put it in, Jim! If you have a good grasp of the
question and answer, I suggest you create a new post, entitled “[FAQ]
install.rb” or similar. I’ll ensure the information ends up in the FAQ before
too long, and others can comment/correct it before it gets there.

Jim Freeze

Gavin

···

From: “Jim Freeze” jim@freeze.org

On Wednesday, 20 November 2002 at 6:10:52 +0900, Phil Tomson wrote:

In article 20021119184306.A16528@freeze.org,

So it seems to do what I would expect. The reason why it didn’t work
initially was that I had: ‘#!/usr/bin/env ruby’ or no shebang at all
and install.rb doesn’t change it (special cases).

Thanks for the little dissertation on this.
Very informative.
Is this in the FAQ or somewhere?

Dunno, but it’s a good candidate for the FAQ if it isn’t in there.
Actually the FAQ should
have a whole section on “How do I make a Ruby module installable?” or some
similar question. We’re really lacking unified info in this area, so
everybody does it a little bit differently. We need to come up with a
‘standard’ way of doing package installation in order to make it easier
for the various installer packages (raa_install, rpkg, rubynet, etc…)

Phil

···

Jim Freeze jim@freeze.org wrote:

On Wednesday, 20 November 2002 at 6:10:52 +0900, Phil Tomson wrote:

The script should still run on other platforms with “ruby -x”.

Is there another solution that works on Windows machines without
requiring -x?

Paul

···

On Thu, Nov 21, 2002 at 01:42:46AM +0900, Austin Ziegler wrote:

On Thu, 21 Nov 2002 00:24:49 +0900, Paul Brannan wrote:

On Tue, Nov 19, 2002 at 05:32:14AM +0900, Jim Freeze wrote:

What about using
#! /usr/bin/env ruby
See [ruby-talk:27508] for a better way.

Better only for Unix.

Yes. In that case you can use all the options to env and
specify both the path and all the env vars.

···

On Tuesday, 19 November 2002 at 7:18:21 +0900, nobu.nokada@softhome.net wrote:

Hi,

At Tue, 19 Nov 2002 07:01:29 +0900, > Jim Freeze wrote:

Overall, it depends on /usr/bin/env existing. From what I can tell, it seems
ubiquitous(sp?). If your environment is somewhat controlled, it
is a great solution. If your environment is not controlled, it is a good
solution. One plus is, that you can change your path to point
to a different install of Ruby and it will automatically use
the right version. However, if the path in hardcoded in the shebang
operator, then you are stuck with using the ruby that it points
to.
(Using env also lets you control environment variables.)

OTOH, it may cause a security issue.


Jim Freeze

Why is the alphabet in that order? Is it because of that song?

I’ll refrain from any comments about Mandrake.
Maybe env is at /bin/env.

···

On Tuesday, 19 November 2002 at 9:07:55 +0900, Tim Hunter wrote:

On Tue, 19 Nov 2002 07:01:29 +0900, Jim Freeze wrote:

Yes.
Overall, it depends on /usr/bin/env existing. From what I can tell, it seems
ubiquitous(sp?). If your environment is somewhat controlled, it
is a great solution. If your environment is not controlled, it is a good
solution. One plus is, that you can change your path to point
to a different install of Ruby and it will automatically use
the right version. However, if the path in hardcoded in the shebang
operator, then you are stuck with using the ruby that it points
to.
(Using env also lets you control environment variables.)

Just as a data point, it does NOT work on my vanilla Mandrake 9.0
system.


Jim Freeze

After a number of decimal places, nobody gives a damn.

In article 20021119184306.A16528@freeze.org,

So it seems to do what I would expect. The reason why it didn’t work
initially was that I had: ‘#!/usr/bin/env ruby’ or no shebang at all
and install.rb doesn’t change it (special cases).

Thanks for the little dissertation on this.
Very informative.
Is this in the FAQ or somewhere?

Dunno, but it’s a good candidate for the FAQ if it isn’t in there.
Actually the FAQ should
have a whole section on “How do I make a Ruby module installable?” or some
similar question. We’re really lacking unified info in this area, so
everybody does it a little bit differently. We need to come up with a
‘standard’ way of doing package installation in order to make it easier
for the various installer packages (raa_install, rpkg, rubynet, etc…)

Phil

I dare say this information is worthy of a cohesive document, rather than a
mere FAQ entry. If anyone knows how to package Ruby modules for installation,
a coherent document on the Wiki would be a great contribution. I’d do it
myself if I had any idea.

Gavin

···

From: “Phil Tomson” ptkwt@shell1.aracnet.com

Jim Freeze jim@freeze.org wrote:

On Wednesday, 20 November 2002 at 6:10:52 +0900, Phil Tomson wrote:

I agreed so much with both of the below that I started up a page on Wiki
covering packaging and submission to RAA. I’m still working on the
extconf.rb and RAA submission sections. Please add, edit or condense
portions of the page to increase its usefulness and accuracy:

http://www.rubygarden.org/ruby?QuickGuideToPackaging

I’ve also been working on a similiar guide to RAA-Install:

http://www.rubygarden.org/ruby?QuickGuideToRaaInstall

I’m not sure exactly where these fit in the overall scheme of the
RubyGarden Wiki. If you look at the home page, I can see them fitting
under CodingInRuby, RubyNuby, DocumentingRuby… I dunno. I ended up
putting the RAA-Install guide under RubyArchive, which is under
RubyOnTheNet…?

_why

···

Gavin Sinclair (gsinclair@soyabean.com.au) wrote:

From: “Phil Tomson” ptkwt@shell1.aracnet.com

Actually the FAQ should have a whole section on “How do I make a
Ruby module installable?” … We’re really lacking unified info in this
area, so everybody does it a little bit differently. We need to come up with a
‘standard’ way of doing package installation in order to make it easier
for the various installer packages (raa_install, rpkg, rubynet, etc…)

Phil

I dare say this information is worthy of a cohesive document, rather than a
mere FAQ entry. If anyone knows how to package Ruby modules for installation,
a coherent document on the Wiki would be a great contribution. I’d do it
myself if I had any idea.

Gavin