用Ruby gem部署一个shell脚本并安装在bin目录下 [英] Deploy a shell script with Ruby gem and install in bin directory
问题描述
我希望在我的gem的bin目录中放置一个shell脚本,以及属于这个包的其他Ruby程序。我希望这个shell脚本按原样安装在bin目录中(也就是没有包装)。这对Ruby宝石来说可能吗?如果没有其他可能,我会很满意后安装钩子。任何人都有这方面的经验吗?
这个问题在这里描述:
https://github.com/rubygems/rubygems/issues/88
如果您正在开发的宝石仅用于您自己的用途,您可以简单地将它安装在
gem install --no-wrapper my_gem
我认为您最好编写一个运行您的bash脚本的ruby脚本。下面是一个例子:
bin / test_gem
#!/ usr / bin / env ruby
$ b 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
echoHello World!
test_gem.gemspec
spec.files = [
#...
'bin / test_gem','bin / test_gem.sh'
]
#...
spec.executables = ['test_gem']
注意:不要忘记将<$ c
请注意,尽管 test_gem.sh
是注册到文件
Rubygems命令,它没有注册为可执行文件
:它只会被放置在已安装的gem的目录中,但如果你安装了gem(并且如果需要的话运行rbenv rehash),调用 test_gem
将不会被包装/填充。 导致ruby脚本执行你的shell脚本。
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?
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.
这篇关于用Ruby gem部署一个shell脚本并安装在bin目录下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!