2017-01-16 22:36:46 +08:00
|
|
|
#!/bin/bash
|
2017-01-16 05:48:57 +08:00
|
|
|
# packpack setup file for the ZoneMinder project
|
2017-01-15 04:14:41 +08:00
|
|
|
# Written by Andrew Bauer
|
|
|
|
|
2017-03-05 00:16:05 +08:00
|
|
|
###############
|
|
|
|
# SUBROUTINES #
|
|
|
|
###############
|
|
|
|
|
|
|
|
# General sanity checks
|
|
|
|
checksanity () {
|
|
|
|
# Check to see if this script has access to all the commands it needs
|
2017-05-11 01:08:33 +08:00
|
|
|
for CMD in set echo curl repoquery git ln mkdir rmdir cat patch; do
|
2017-03-05 00:16:05 +08:00
|
|
|
type $CMD 2>&1 > /dev/null
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo
|
|
|
|
echo "ERROR: The script cannot find the required command \"${CMD}\"."
|
|
|
|
echo
|
2017-03-04 23:44:42 +08:00
|
|
|
exit 1
|
2017-03-05 00:16:05 +08:00
|
|
|
fi
|
|
|
|
done
|
2017-01-16 05:48:57 +08:00
|
|
|
|
2017-03-05 00:16:05 +08:00
|
|
|
# Verify OS & DIST environment variables have been set before calling this script
|
2017-03-07 08:56:44 +08:00
|
|
|
if [ -z "${OS}" ] || [ -z "${DIST}" ]; then
|
2017-03-05 00:16:05 +08:00
|
|
|
echo "ERROR: both OS and DIST environment variables must be set"
|
|
|
|
exit 1
|
2017-02-17 21:07:17 +08:00
|
|
|
fi
|
2017-03-08 04:24:06 +08:00
|
|
|
|
|
|
|
if [ -z "${ARCH}" ]; then
|
|
|
|
ARCH="x86_64"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${ARCH}" != "x86_64" && "${ARCH}" != "i386" && "${ARCH}" != "armhf" ]]; then
|
|
|
|
echo
|
|
|
|
echo "ERROR: Unsupported architecture specified \"${ARCH}\"."
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-06-06 01:04:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create key variables used to assemble the package name
|
|
|
|
createvars () {
|
|
|
|
# We need today's date in year/month/day format
|
|
|
|
thedate=$(date +%Y%m%d)
|
|
|
|
|
|
|
|
# We need the (short) commit hash of the latest commit (rpm packaging only)
|
|
|
|
shorthash=$(git describe --long --always | awk -F - '{print $3}')
|
|
|
|
|
|
|
|
# Grab the ZoneMinder version from the contents of the version file
|
|
|
|
versionfile=$(cat version)
|
|
|
|
|
|
|
|
# git the latest (short) commit hash of the version file
|
|
|
|
versionhash=$(git log -n1 --pretty=format:%h version)
|
2017-03-08 04:24:06 +08:00
|
|
|
|
2017-06-06 01:04:29 +08:00
|
|
|
# Number of commits since the version file was last changed
|
|
|
|
numcommits=$(git rev-list ${versionhash}..HEAD --count)
|
2017-03-05 00:16:05 +08:00
|
|
|
}
|
2017-02-17 21:07:17 +08:00
|
|
|
|
2017-06-02 01:30:32 +08:00
|
|
|
# Check key variables before calling packpack
|
|
|
|
checkvars () {
|
|
|
|
|
2017-06-06 01:04:29 +08:00
|
|
|
for var in $thedate $shorthash $versionfile $versionhash $numcommits; do
|
|
|
|
if [ -z ${var} ]; then
|
|
|
|
echo
|
|
|
|
echo "FATAL: This script was unable to determine one or more key variables. Cannot continue."
|
|
|
|
echo
|
|
|
|
echo "VARIABLE DUMP"
|
|
|
|
echo "-------------"
|
|
|
|
echo
|
|
|
|
echo "thedate: ${thedate}"
|
|
|
|
echo "shorthash: ${shorthash}"
|
|
|
|
echo "versionfile: ${versionfile}"
|
|
|
|
echo "versionhash: ${versionhash}"
|
|
|
|
echo "numcommits: ${numcommits}"
|
|
|
|
echo
|
|
|
|
exit 98
|
|
|
|
fi
|
|
|
|
done
|
2017-06-02 01:30:32 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 00:16:05 +08:00
|
|
|
# Steps common to all builds
|
|
|
|
commonprep () {
|
|
|
|
mkdir -p build
|
|
|
|
if [ -e "packpack/Makefile" ]; then
|
|
|
|
echo "Checking packpack github repo for changes..."
|
|
|
|
git -C packpack pull origin master
|
2017-01-16 05:48:57 +08:00
|
|
|
else
|
2017-06-01 04:28:05 +08:00
|
|
|
echo "Cloning packpack github repo..."
|
2017-03-05 00:16:05 +08:00
|
|
|
git clone https://github.com/packpack/packpack.git packpack
|
2017-01-16 05:48:57 +08:00
|
|
|
fi
|
|
|
|
|
2017-05-11 01:08:33 +08:00
|
|
|
# Patch packpack
|
|
|
|
patch --dry-run --silent -f -p1 < utils/packpack/packpack-rpm.patch
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
patch -p1 < utils/packpack/packpack-rpm.patch
|
|
|
|
fi
|
|
|
|
|
2017-03-05 00:16:05 +08:00
|
|
|
# The rpm specfile requires we download the tarball and manually move it into place
|
|
|
|
# Might as well do this for Debian as well, rather than git submodule init
|
|
|
|
CRUDVER="3.0.10"
|
|
|
|
if [ -e "build/crud-${CRUDVER}.tar.gz" ]; then
|
|
|
|
echo "Found existing Crud ${CRUDVER} tarball..."
|
2017-01-16 05:48:57 +08:00
|
|
|
else
|
2017-03-05 00:16:05 +08:00
|
|
|
echo "Retrieving Crud ${CRUDVER} submodule..."
|
|
|
|
curl -L https://github.com/FriendsOfCake/crud/archive/v${CRUDVER}.tar.gz > build/crud-${CRUDVER}.tar.gz
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: Crud tarball retreival failed..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-03-05 00:30:36 +08:00
|
|
|
# Uncompress the Crud tarball and move it into place
|
|
|
|
movecrud () {
|
|
|
|
if [ -e "web/api/app/Plugin/Crud/LICENSE.txt" ]; then
|
|
|
|
echo "Crud plugin already installed..."
|
|
|
|
else
|
|
|
|
echo "Unpacking Crud plugin..."
|
|
|
|
tar -xzf build/crud-${CRUDVER}.tar.gz
|
|
|
|
rmdir web/api/app/Plugin/Crud
|
|
|
|
mv -f crud-${CRUDVER} web/api/app/Plugin/Crud
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# previsouly part of installzm.sh
|
|
|
|
# install the trusty deb and test zoneminder
|
|
|
|
installtrusty () {
|
2017-03-05 23:06:57 +08:00
|
|
|
|
|
|
|
# Check we've got gdebi installed
|
|
|
|
type gdebi 2>&1 > /dev/null
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo
|
|
|
|
echo "ERROR: The script cannot find the required command \"gdebi\"."
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-03-05 00:30:36 +08:00
|
|
|
# Install and test the zoneminder package (only) for Ubuntu Trusty
|
2017-03-06 20:50:59 +08:00
|
|
|
pkgname="build/zoneminder_${VERSION}-${RELEASE}_amd64.deb"
|
|
|
|
|
|
|
|
if [ -e $pkgname ]; then
|
2017-06-15 01:28:56 +08:00
|
|
|
sudo gdebi --quiet --non-interactive $pkgname
|
2017-03-06 20:50:59 +08:00
|
|
|
mysql -uzmuser -pzmpass zm < db/test.monitor.sql
|
|
|
|
sudo /usr/bin/zmpkg.pl start
|
|
|
|
sudo /usr/bin/zmfilter.pl -f purgewhenfull
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "ERROR: The script cannot find the package $pkgname"
|
|
|
|
echo "Check the Travis log for a build failure."
|
|
|
|
echo
|
|
|
|
exit 99
|
|
|
|
fi
|
2017-03-05 00:30:36 +08:00
|
|
|
}
|
|
|
|
|
2017-06-06 01:04:29 +08:00
|
|
|
# This sets the naming convention for the rpm packages
|
|
|
|
setrpmpkgname () {
|
|
|
|
|
|
|
|
createvars
|
|
|
|
|
|
|
|
# Set VERSION to the contents of the version file e.g. 1.31.0
|
|
|
|
# Set RELEASE to 1.{number of commits}.{today's date}git{short hash of HEAD} e.g. 1.82.20170605gitg7ae0b4a
|
|
|
|
export VERSION="$versionfile"
|
|
|
|
export RELEASE="1.${numcommits}.${thedate}git${shorthash}"
|
|
|
|
|
|
|
|
checkvars
|
2017-06-01 08:00:17 +08:00
|
|
|
|
2017-06-06 01:04:29 +08:00
|
|
|
echo
|
|
|
|
echo "Packpack VERSION has been set to: ${VERSION}"
|
|
|
|
echo "Packpack RELEASE has been set to: ${RELEASE}"
|
|
|
|
echo
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# This sets the naming convention for the deb packages
|
|
|
|
setdebpkgname () {
|
|
|
|
|
|
|
|
createvars
|
|
|
|
|
|
|
|
# Set VERSION to {zm version}~{today's date}.{number of commits} e.g. 1.31.0~20170605.82
|
|
|
|
# Set RELEASE to the packpack DIST variable e.g. Trusty
|
|
|
|
export VERSION="${versionfile}~${thedate}.${numcommits}"
|
2017-03-07 08:54:55 +08:00
|
|
|
export RELEASE="${DIST}"
|
|
|
|
|
2017-06-02 01:30:32 +08:00
|
|
|
checkvars
|
|
|
|
|
2017-03-07 08:54:55 +08:00
|
|
|
echo
|
|
|
|
echo "Packpack VERSION has been set to: ${VERSION}"
|
|
|
|
echo "Packpack RELEASE has been set to: ${RELEASE}"
|
|
|
|
echo
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-06-06 01:04:29 +08:00
|
|
|
# This adds an entry to the rpm specfile changelog
|
|
|
|
setrpmchangelog () {
|
|
|
|
|
|
|
|
export CHANGELOG_NAME="Andrew Bauer"
|
|
|
|
export CHANGELOG_EMAIL="zonexpertconsulting@outlook.com"
|
|
|
|
export CHANGELOG_TEXT="Automated, development snapshot of git ${shorthash}"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-03 10:01:59 +08:00
|
|
|
# This adds an entry to the debian changelog
|
|
|
|
setdebchangelog () {
|
|
|
|
DATE=`date -R`
|
|
|
|
cat <<EOF > debian/changelog
|
|
|
|
zoneminder ($VERSION-${DIST}-1) unstable; urgency=low
|
|
|
|
*
|
|
|
|
-- Isaac Connor <iconnor@connortechnology.com> $DATE
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2017-03-05 00:16:05 +08:00
|
|
|
################
|
|
|
|
# MAIN PROGRAM #
|
|
|
|
################
|
|
|
|
|
|
|
|
checksanity
|
|
|
|
|
|
|
|
# We don't want to build packages for all supported distros after every commit
|
|
|
|
# Only build all packages when executed via cron
|
|
|
|
# See https://docs.travis-ci.com/user/cron-jobs/
|
2017-03-06 00:26:36 +08:00
|
|
|
if [ "${TRAVIS_EVENT_TYPE}" == "cron" ] || [ "${TRAVIS}" != "true" ]; then
|
2017-03-05 00:16:05 +08:00
|
|
|
commonprep
|
|
|
|
|
|
|
|
# Steps common to Redhat distros
|
|
|
|
if [ "${OS}" == "el" ] || [ "${OS}" == "fedora" ]; then
|
|
|
|
echo "Begin Redhat build..."
|
|
|
|
|
2017-06-06 01:04:29 +08:00
|
|
|
setrpmpkgname
|
2017-03-07 08:27:45 +08:00
|
|
|
|
2017-03-17 22:32:58 +08:00
|
|
|
ln -sfT distros/redhat rpm
|
2017-03-05 00:16:05 +08:00
|
|
|
|
|
|
|
# The rpm specfile requires the Crud submodule folder to be empty
|
2017-03-08 04:44:53 +08:00
|
|
|
rm -rf web/api/app/Plugin/Crud
|
|
|
|
mkdir web/api/app/Plugin/Crud
|
2017-03-05 00:16:05 +08:00
|
|
|
|
2017-08-19 22:07:32 +08:00
|
|
|
# We use zmrepo to build el6 only. All other redhat distros use rpm fusion
|
|
|
|
if [ "${OS}" == "el" ] && [ "${DIST}" == "6" ]; then
|
|
|
|
baseurl="https://zmrepo.zoneminder.com/el/${DIST}/x86_64/"
|
|
|
|
reporpm="zmrepo"
|
2017-08-20 05:56:17 +08:00
|
|
|
# Let repoquery determine the full url and filename to the latest zmrepo package
|
|
|
|
dlurl=`repoquery --archlist=noarch --repofrompath=zmpackpack,${baseurl} --repoid=zmpackpack --qf="%{location}" ${reporpm} 2> /dev/null`
|
2017-03-05 00:16:05 +08:00
|
|
|
else
|
2017-08-19 22:07:32 +08:00
|
|
|
reporpm="rpmfusion-free-release"
|
2017-08-20 05:56:17 +08:00
|
|
|
dlurl="https://download1.rpmfusion.org/free/${OS}/${reporpm}-${DIST}.noarch.rpm"
|
2017-03-05 00:16:05 +08:00
|
|
|
fi
|
|
|
|
|
2017-08-19 22:07:32 +08:00
|
|
|
# Give our downloaded repo rpm a common name so redhat_package.mk can find it
|
2017-08-20 05:56:17 +08:00
|
|
|
if [ -n "$dlurl" ] && [ $? -eq 0 ]; then
|
2017-08-19 22:07:32 +08:00
|
|
|
echo "Retrieving ${reporpm} repo rpm..."
|
|
|
|
curl $result > build/external-repo.noarch.rpm
|
2017-03-05 00:16:05 +08:00
|
|
|
else
|
2017-08-19 22:07:32 +08:00
|
|
|
echo "ERROR: Failed to retrieve ${reporpm} repo rpm..."
|
2017-03-06 03:41:17 +08:00
|
|
|
exit 1
|
2017-03-05 00:16:05 +08:00
|
|
|
fi
|
|
|
|
|
2017-06-06 01:04:29 +08:00
|
|
|
setrpmchangelog
|
|
|
|
|
2017-03-05 00:16:05 +08:00
|
|
|
echo "Starting packpack..."
|
2017-06-10 01:52:00 +08:00
|
|
|
utils/packpack/heartbeat.sh &
|
|
|
|
mypid=$!
|
|
|
|
packpack/packpack -f utils/packpack/redhat_package.mk redhat_package > buildlog.txt 2>&1
|
|
|
|
kill $mypid
|
2017-06-15 01:06:55 +08:00
|
|
|
tail -n 3000 buildlog.txt | grep -v ONVIF
|
2017-03-05 00:16:05 +08:00
|
|
|
|
|
|
|
# Steps common to Debian based distros
|
|
|
|
elif [ "${OS}" == "debian" ] || [ "${OS}" == "ubuntu" ]; then
|
2017-03-07 08:54:55 +08:00
|
|
|
echo "Begin ${OS} ${DIST} build..."
|
2017-03-07 08:27:45 +08:00
|
|
|
|
2017-06-06 01:04:29 +08:00
|
|
|
setdebpkgname
|
2017-03-05 00:30:36 +08:00
|
|
|
movecrud
|
2017-03-05 00:16:05 +08:00
|
|
|
|
2017-03-05 00:30:36 +08:00
|
|
|
if [ "${DIST}" == "trusty" ] || [ "${DIST}" == "precise" ]; then
|
2017-03-17 22:32:58 +08:00
|
|
|
ln -sfT distros/ubuntu1204 debian
|
2017-03-05 00:30:36 +08:00
|
|
|
elif [ "${DIST}" == "wheezy" ]; then
|
2017-03-17 22:32:58 +08:00
|
|
|
ln -sfT distros/debian debian
|
2017-03-05 00:16:05 +08:00
|
|
|
else
|
2017-03-17 22:32:58 +08:00
|
|
|
ln -sfT distros/ubuntu1604 debian
|
2017-03-05 00:16:05 +08:00
|
|
|
fi
|
2017-06-03 10:01:59 +08:00
|
|
|
|
|
|
|
setdebchangelog
|
|
|
|
|
2017-03-05 00:16:05 +08:00
|
|
|
echo "Starting packpack..."
|
2017-06-10 01:52:00 +08:00
|
|
|
utils/packpack/heartbeat.sh &
|
|
|
|
mypid=$!
|
|
|
|
packpack/packpack > buildlog.txt 2>&1
|
|
|
|
kill $mypid
|
2017-06-15 01:06:55 +08:00
|
|
|
tail -n 3000 buildlog.txt | grep -v ONVIF
|
2017-06-10 01:52:00 +08:00
|
|
|
|
2017-03-08 04:24:06 +08:00
|
|
|
if [ "${OS}" == "ubuntu" ] && [ "${DIST}" == "trusty" ] && [ "${ARCH}" == "x86_64" ] && [ "${TRAVIS}" == "true" ]; then
|
2017-03-05 00:30:36 +08:00
|
|
|
installtrusty
|
|
|
|
fi
|
2017-01-16 05:48:57 +08:00
|
|
|
fi
|
|
|
|
|
2017-03-05 00:16:05 +08:00
|
|
|
# We were not triggered via cron so just build and test trusty
|
2017-03-08 04:43:14 +08:00
|
|
|
elif [ "${OS}" == "ubuntu" ] && [ "${DIST}" == "trusty" ] && [ "${ARCH}" == "x86_64" ]; then
|
2017-03-06 01:14:28 +08:00
|
|
|
echo "Begin Ubuntu Trusty build..."
|
2017-03-07 08:41:48 +08:00
|
|
|
|
2017-03-06 01:37:22 +08:00
|
|
|
commonprep
|
2017-06-06 01:04:29 +08:00
|
|
|
setdebpkgname
|
2017-03-06 01:37:22 +08:00
|
|
|
movecrud
|
|
|
|
|
2017-03-17 22:32:58 +08:00
|
|
|
ln -sfT distros/ubuntu1204 debian
|
2017-03-06 01:37:22 +08:00
|
|
|
|
2017-06-03 10:01:59 +08:00
|
|
|
setdebchangelog
|
|
|
|
|
2017-01-16 10:43:03 +08:00
|
|
|
echo "Starting packpack..."
|
2017-06-10 01:52:00 +08:00
|
|
|
utils/packpack/heartbeat.sh &
|
|
|
|
mypid=$!
|
|
|
|
packpack/packpack > buildlog.txt 2>&1
|
|
|
|
kill $mypid
|
2017-06-15 01:06:55 +08:00
|
|
|
tail -n 3000 buildlog.txt | grep -v ONVIF
|
2017-03-05 00:30:36 +08:00
|
|
|
|
2017-03-05 23:06:57 +08:00
|
|
|
# If we are running inside Travis then attempt to install the deb we just built
|
2017-03-08 04:43:14 +08:00
|
|
|
if [ "${TRAVIS}" == "true" ]; then
|
2017-03-05 23:06:57 +08:00
|
|
|
installtrusty
|
|
|
|
fi
|
2017-01-16 05:48:57 +08:00
|
|
|
fi
|
2017-03-06 04:02:02 +08:00
|
|
|
|
|
|
|
exit 0
|
|
|
|
|