Simple RPM packages with FPM
Recently I've been working on a project where we had a need to put together some shell scripts in a package to use in CentOS servers.
We could have easily tarred them up, but then updating a bunch of servers consistently whenever we had an upgrade would be a pain.
Using Yum is of course the best solution, but isn't building RPMs a real pain?
Turns out it's not anymore - enterĀ FPM.
FPM stands for "Effing Package Management" and the goal is to make building packages very easy - I think the creators were successful.
FPM comes as a Ruby gem, so you need to have Ruby installed first - look here for quick instructions on doing that on CentOS.
Once you have Ruby installed, this is how you install FPM and build a quick package:
1. Install the FPM gem:
gem install fpm --no-ri --no-rdoc
2. Go to the directory where you have your scripts - in my case I don't have one, so for this example I'm creating an empty one:
mkdir -pv /root/superscripts
cd /root/superscripts/
3. Add some test script:
#!/bin/bash
echo "superscript!"
4. Make your script executable:
chmod +x superscript
4. Build the package!
fpm --verbose -v 0.1 -n superscripts -s dir -t rpm .=/usr/local/bin
Explanation for the above:
-v 0.1 = sets the version we want
-n = sets a name for the package
-s dir = sets the source for the code - in this case it's a directory
-t rpm = sets the target type to be an RPM package
.=/usr/local/bin = this is pretty important - this tells FPM to install the files under the directory /usr/local/bin
5. Unless you get any errors you'll get a bunch of output, but in the end you should see this:
Created package {:path=>"superscripts-0.1-1.x86_64.rpm"}
6. Let's look at the contents of theĀ /root/superscripts/ directory:
[root@fpm1 superscripts]# ls -l /root/superscripts/
total 8
-rwxr-xr-x 1 root root 33 Jan 25 04:42 superscript
-rw-r--r-- 1 root root 1804 Jan 25 04:42 superscripts-0.1-1.x86_64.rpm
7. Very nice! we have an RPM - let's try installing it:
rpm -ihv superscripts-0.1-1.x86_64.rpm
8. Now let's see what's inside the target directory /usr/local/bin
[root@fpm1 superscripts]# ls -l /usr/local/bin/
total 4
-rwxr-xr-x 1 root root 33 Jan 25 04:42 superscript
9. Run our script:
[root@fpm1 superscripts]# superscript
superscript!
[root@fpm1 superscripts]# which superscript
/usr/local/bin/superscript