Created
August 5, 2016 14:39
-
-
Save jrha/e8bed86117efc029f08ce10727424e59 to your computer and use it in GitHub Desktop.
Debian packaging script with FPM for Maven
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo | |
echo "FPM Packaging Script for Debian" | |
echo | |
echo "Environment Variables to script:" | |
echo "--------------------------------" | |
printenv | grep '^PKG' | |
echo "--------------------------------" | |
ITERATION=0 | |
if [[ "${PKG_VERSION}" =~ .*-SNAPSHOT ]]; then | |
echo "Packaging a snapshot version" | |
ITERATION=$(git log --format="%h" -n 1).$(date +%s) | |
else | |
echo "Not packaging a snapshot version" | |
fi | |
WORK_DIR="$(mktemp -d /tmp/quattor.fpm.XXXXXXXXXX)" | |
echo "Working directory is '$WORK_DIR'" | |
# Perl modules should be in /usr/share/perl5 to comply with Debian Policy 2.3 | |
PERL_DIR=$WORK_DIR/usr/share/perl5 | |
mkdir -p $PERL_DIR | |
cp -R lib/perl/* $PERL_DIR | |
# Generate provides from Perl modules (ignore versions for now) | |
PROVIDES_PATTERN="s#$PERL_DIR\(\S\+\)\.pm#--provides lib\L\1-perl#g" | |
provides="$(find $PERL_DIR -type f -name \*.pm | sed "$PROVIDES_PATTERN" | sed 's#/#-#g')" | |
# Generate dependencies from Perl modules (ignore versions for now) | |
DEPENDS_PATTERN="s#^'\(\S\+\)'\s*=>\s*'\(\S\+\)',#--depends lib\L\1-perl#g" | |
depends="$(find $WORK_DIR/usr/share/perl5/ -type f -name \*.pm | xargs scandeps -R 2> /dev/null | sed "$DEPENDS_PATTERN" | sed 's#::#-#g')" | |
# Executables and TT Files | |
cp -R sbin share $WORK_DIR/usr | |
# Documentation and reference material | |
mkdir -p $WORK_DIR/usr/share/doc/ | |
cp -R pan $WORK_DIR/usr/share/doc/ # Reference copy of Pan templates | |
cp -R doc/man $WORK_DIR/usr/share/ # Man pages | |
# Re-compress manpages to comply with Debian Policy 12.1 | |
gunzip $WORK_DIR/usr/share/man/man8/*.gz | |
gzip -9 $WORK_DIR/usr/share/man/man8/* | |
# Generate a slightly-fake debian style changelog from git log (Debian Policy 4.4) | |
# Replace UUID based email addresses generated by git-svn | |
LOG_PATTERN="${PKG_NAME} (${PKG_VERSION}-%h.%at) stable; urgency=medium%n%n%w(76,2,4)* %B%n%w(0,0,0) -- %aN <%aE> %aD%n%n" | |
EMAIL_PATTERN='s!@[[:xdigit:]]\{8\}-[[:xdigit:]]\{4\}-[[:xdigit:]]\{4\}-[[:xdigit:]]\{4\}-[[:xdigit:]]\{12\}!@users.noreply.github.com!g' | |
git log --grep '^[^\[]' --pretty="$LOG_PATTERN" ../. | sed "$EMAIL_PATTERN" > changelog.Debian | |
# Build package | |
echo "Calling FPM..." | |
fpm \ | |
-s dir \ | |
-t deb \ | |
-C "$WORK_DIR" \ | |
$provides \ | |
$depends \ | |
--category admin \ | |
--iteration ${ITERATION} \ | |
--vendor "quattor.org" \ | |
-m "Quattor Discuss <quattor-discuss@lists.sourceforge.net>" \ | |
--url "https://www.quattor.com" \ | |
--description "${PKG_DESCRIPTION}" \ | |
--architecture all \ | |
--name ${PKG_NAME} \ | |
--version ${PKG_VERSION} \ | |
--license "Apache-2 and EUDatagrid" \ | |
--deb-changelog changelog.Debian \ | |
usr | |
# Clean up temporary working directory | |
rm -rf "$WORK_DIR" | |
echo "Packaging with FPM Completed" | |
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<groupId>org.codehaus.mojo</groupId> | |
<artifactId>exec-maven-plugin</artifactId> | |
<executions> | |
<execution> | |
<id>fpm</id> | |
<phase>package</phase> | |
<goals> | |
<goal>exec</goal> | |
</goals> | |
</execution> | |
</executions> | |
<configuration> | |
<executable>../package.sh</executable> | |
<workingDirectory>target</workingDirectory> | |
<environmentVariables> | |
<PKG_VERSION>${project.version}</PKG_VERSION> | |
<PKG_NAME>${project.artifactId}</PKG_NAME> | |
<PKG_DESCRIPTION>${project.name}</PKG_DESCRIPTION> | |
</environmentVariables> | |
</configuration> | |
</plugin> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment