Packaging Compiled Binary /w a Ruby Gem - ruby

I am creating a small daemon, written in Ruby, which relies in part on a small binary utility compiled from C code. I want to package this as a gem and include this dependency along with it.
Essentially, this daemon will need to run commands such as ip addr add ... without requiring sudo, so I created a small C program to proxy those commands which must be compiled, chowned to root, and have the setuid bit set.
I would like to have the gem compile and install this dependency along with the daemon, but I am unsure how to do so. I understand extensions can be compiled via extconf.rb, but that is specifically meant for managing Ruby extensions, right? Would it be an ugly hack to have this compile and install a binary to /usr/local/bin or similar?
Does anyone know of an existing gem which does a similar thing which I can study as an example?

Here's a gem that packages the pdftk binary.
https://github.com/charliemaffitt/pdftk-heroku

Related

How do I execute a ruby script when gem install is called?

I'm making a Ruby wrapper for a C Library that doesn't really have a system wide installation(the libxxx.a linkable library is distributed). During development, I was able to just keep this .a file in a local folder and refer to it using the C extension code. However this would be cumbersome for anyone who just wants to type gem install into their terminal. Since there is no system wide installation, I would need to execute an intermediate script that downloads the right distribution and then puts it in a generic folder within the gem directory itself.
To be clear, when someone types gem install, a tarball would get downloaded from an ftp, unpacked into the gem folder, and then gem install would proceed normally. If it helps, the C library in question is CSPICE

How can I make executables included in a Ruby gem runnable on Windows?

I have a Ruby gem with some scripts that are distributed as executables. On Linux, this means that they go on the PATH with the executable bit set when the gem is installed. But on Windows, I don't see that or anything equivalent. So, how can I make those scripts usable from the command line on Windows?
I noticed that the Gem::Installer package has a generate_windows_script command, which from the brief description appears to match what I'm trying to do. Can I use that to help here, and if so, how?

How do I easily condense a whole ruby program into one file?

I really like writing command line applications in ruby. However, when working on lots of ruby projects I end up switching between different ruby versions with something like rvm, rbenv or chruby. This means I need to install ruby command line utilities for every version of ruby I work on. I've gotten used to this, but when distributing ruby command line apps to other devs they get confused when running whateverrubyapp that worked in one directory now doesn't work in another directory because the ruby version is different, or even worse they're using gemsets.
Is there an easy way to bundle up a ruby application with all it's dependencies including gems into a single file so that I can just have people put that file in their ~/bin dir so that it behaved somewhat as though it were a compiled application?
For example, I whipped up a little rake task to take a project with no gem dependencies and put it all into one file https://github.com/mmrobins/git-rank/blob/master/Rakefile. However, I have much more complex command line apps that have gem dependencies I would want to include into a single file for easy distribution.

pdftk wrapper for Ruby

There are several Ruby wrapper gems for pdftk. Among them, is there any gem that installs the pdftk binary automatically cross major OSs at installation of itself? I want to require it in a library, and I can manually install pdftk on my own machine, but I want to avoid the mess of the users of my library being required to manually install pdftk binary.
Why not use a native solution such as CombinePDF...?
Depends on what you need, it might actually serve you better.

Self contained ruby "binary"?

[Ruby Noob]
I have a small (command line) utility written in Ruby, which requires a few gems. Is there a way to create a self contained bundle of my program such that I can run it on another machine that has Ruby installed (but not necessarily the gems)?
FWIW, the target machine runs Linux/Ubuntu.
You can use the gem bundle http://gembundler.com/
With bundle you create a Gemfile in your project root - a text that contains all your dependencies, very similar to Maven concept
In order to fetch all your dependencies simply tun
bundle install
The only issue is that you need to have the bundle gem itself installed, so you are back with the chicken-or-Egg problem :-)
I've used:
http://www.erikveen.dds.nl/rubyscript2exe/
before, but it was a while ago. Seemed to work okay for simple programs.
You can download it here:
http://rubyforge.org/projects/rubyscript2exe/

Resources