Skip to content

Commit

Permalink
code cleanup fpm script
Browse files Browse the repository at this point in the history
  • Loading branch information
BIAndrews committed Apr 14, 2015
1 parent 08adb6e commit e0abaf6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
5 changes: 3 additions & 2 deletions contrib/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
fakeroot/
sshfail2kml_*_all.deb
sshfail2kml_*_amd64.changes
sshfail2kml-*.rpm
sshfail2kml_*.deb
sshfail2kml_*.changes
sshfail2kml_*.dsc
sshfail2kml_*.tar.gz

74 changes: 57 additions & 17 deletions contrib/fpm-createPackages.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#!/bin/bash

# this is a fast way to create packages with the fpm tool: https://github.com/jordansissel/fpm/wiki

DIR="$$/" # lets make a random temp dir as a fakeroot
NAME="sshfail2kml"
DESC="SSH failed login attempts logged and GeoIP info acquired for Google Map KML display in an HTML page. Complete with JSON results and SQLite indexed database for a log rotation friendly setup."
URI="https://github.com/BIAndrews/sshfail2kml"
LIC="GPLv3"
PROV="sshfail2kml"
EMAIL="[email protected]"

#################################################################################################
#
# PREFLIGHT CHECK FOR REQUIRED TOOLS
#
Expand Down Expand Up @@ -29,18 +42,17 @@ if [ $? -ne 0 ];then

fi

# juuussttt in case
if [ "$DIR" == "/" ]; then
echo "ERROR: the fakeroot temp dir can't be / or really really bad things will happen."
exit 255;
fi

########################################################################################
#
# LETS GO
#

DIR="fakeroot/"
NAME="sshfail2kml"
DESC="SSH failed login attempts logged and GeoIP info acquired for Google Map KML display in an HTML page. Complete with JSON results and SQLite indexed database for a log rotation friendly setup."
URI="https://github.com/BIAndrews/sshfail2kml"
LIC="GPLv3"
PROV="sshfail2kml"
EMAIL="[email protected]"

if [ ! -f "${PWD}/version.sh" ];then
echo "Unable to find the version.sh file."
pwd
Expand All @@ -55,6 +67,10 @@ if [ $? -ne 0 ];then
exit 1
fi

#
# Lets automatically create the package release number for jenkin/ci automation, resets on a new version/tag
#

if [ -f "${PWD}/.release-${VER}" ];then
. "${PWD}/.release-${VER}"
RELEASE=$((RELEASE+1))
Expand All @@ -63,7 +79,12 @@ RELEASE="0"
fi
echo "RELEASE=$RELEASE" > "${PWD}/.release-${VER}"

echo "Building packages for ${VER}-${RELEASE}"
###############################################################
#
# Create and populate the fakeroot directory to be packaged
#

echo "Building package fakeroot dir for ${VER}-${RELEASE}"

install -d $DIR/var/lib/sshfail2kml $DIR/etc/cron.d $DIR/usr/bin
cp -f ../sshfail2kml $DIR/usr/bin
Expand All @@ -75,35 +96,54 @@ chmod o-rwx $DIR/etc/sshfail2kml.conf
echo "DIR: $DIR"
cd $DIR

##################################
#
# CREATE THE REDHAT PACKAGE
#
# todo - when fpm can make srpms add that


fpm \
--url $URI --license $LIC --provides $PROV -p "../$NAME-$VER-$RELEASE.noarch.rpm" \
-m $EMAIL --no-rpm-sign -v $VER --iteration $RELEASE -a noarch \
-s dir -t rpm -n $NAME -d php-cli -d php-pdo --verbose --config-files /etc/sshfail2kml.conf --directories /var/lib/sshfail2kml --description "$DESC" \
*

##################################
#
# CREATE THE DEBIAN PACKAGE
#

fpm \
--url $URI --license $LIC --provides $PROV -p "../$NAME-$VER-${RELEASE}_all.deb" \
-m $EMAIL -v $VER --iteration $RELEASE -a all \
-s dir -t deb -n $NAME -d php5-cli -d php5-sqlite --verbose --config-files /etc/sshfail2kml.conf --directories /var/lib/sshfail2kml --description "$DESC" \
*

cd ..

if [ -f "$NAME-$VER-$RELEASE.noarch.rpm" ];then
rpm -qpil $NAME-$VER-$RELEASE.noarch.rpm
echo "Successfully created redhat package."

rpm -qpil $NAME-$VER-$RELEASE.noarch.rpm
echo "Successfully created redhat package."

else
echo "FAILED TO CREATE RPM PACKAGE"
exit 1

echo "FAILED TO CREATE RPM PACKAGE"
exit 1

fi

if [ -f "$NAME-$VER-${RELEASE}_all.deb" ];then
echo "Successfully created debian package."

echo "Successfully created debian package."

else
echo "FAILED TO CREATE DEBIAN PACKAGE"
exit 1

echo "FAILED TO CREATE DEBIAN PACKAGE"
exit 1

fi

#clean up
#clean up, this is a good example of why we never run someone elses code as root
rm -rf $DIR
2 changes: 1 addition & 1 deletion contrib/version.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# example, external file to work better with CI/CD
VER="1.3.5"
VER="1.3.10"

0 comments on commit e0abaf6

Please sign in to comment.