How to build a Sonatype Nexus RPM

To compile a „latest greatest“ RPM file of Sonatype Nexus one needs three things. A Gemfile, some system dependencies and at last the bash script from this post.

The Gemfile one will need to get fpm and it’s dependencies from the rubygems

source 'https://rubygems.org'

group :build do
  gem 'fpm', :require => false
  gem 'rake',
end

One will need two dependencies to build RPMs with fpm:

yum install ruby-devel gcc

The main script…

### maybe one needs a proxy?
#export http_proxy=http://proxy.domain.de:8080
#export https_proxy=http://proxy.domain.de:8080

### locally install the gems
bundle install --path vendor/gems

### create an extra build dir, maybe one doesn't need this, but i do :D
mkdir build
cd build

### some redirects are in here... so it fails, if one has a strict cert check :-/
wget --no-check-certificate http://www.sonatype.org/downloads/nexus-latest-bundle.tar.gz

### unpack the archive and get rid of it...
tar xfz nexus-latest-bundle.tar.gz
rm nexus-latest-bundle.tar.gz

### extract version and minor version from directory name from the extracted nexus archive
export NEXUS_VERSION=$(find . -maxdepth 1 -type d -name "nexus-*"  | awk -F'-' '{print $2}')
export NEXUS_ITERATION=$(find . -maxdepth 1 -type d -name "nexus-*"  | awk -F'-' '{print $3}')

### some output, to see what version one will get
echo "Nexus Version: $NEXUS_VERSION"
echo "Nexus Iteration: $NEXUS_ITERATION"

### move the dir to plain nexus, one does not want version numbers in the installation tree, or does one?
mv nexus-* nexus

### execute fpm from the local bundle and build the RPM file.
### name the package nexus, put in the version numbers and let it depend on java 1.8
### installation directory is set with the prefix
bundle exec fpm -s dir -t rpm -n nexus -v $NEXUS_VERSION --iteration $NEXUS_ITERATION --prefix /opt/services --epoch 1 -d java-1.8.0-openjdk nexus