2015-08-21 08:35:01 +08:00
#!/bin/bash
2016-01-21 05:09:12 +08:00
if [ " $1 " = = "clean" ] ; then
read -p "Do you really want to delete existing packages? [y/N]"
[ [ $REPLY = = [ yY] ] ] && { rm -fr zoneminder*.build zoneminder*.changes zoneminder*.deb; echo "Existing package files deleted" ; } || { echo "Packages have NOT been deleted" ; }
exit;
fi
2019-06-24 23:57:52 +08:00
DEBUILD = ` which debuild` ;
if [ " $DEBUILD " = = "" ] ; then
echo "You must install the devscripts package. Try sudo apt-get install devscripts" ;
exit;
fi
2017-01-16 01:18:51 +08:00
for i in " $@ "
do
case $i in
-b= *| --branch= *)
BRANCH = " ${ i #*= } "
shift # past argument=value
; ;
-d= *| --distro= *)
2019-06-24 23:57:52 +08:00
DISTROS = " ${ i #*= } "
2017-01-16 01:18:51 +08:00
shift # past argument=value
; ;
-i= *| --interactive= *)
INTERACTIVE = " ${ i #*= } "
shift # past argument=value
; ;
2019-06-24 23:50:58 +08:00
-p= *| --ppa= *)
PPA = " ${ i #*= } "
shift # past argument=value
; ;
2017-04-25 04:50:33 +08:00
-r= *| --release= *)
RELEASE = " ${ i #*= } "
shift
; ;
2017-01-16 01:18:51 +08:00
-s= *| --snapshot= *)
SNAPSHOT = " ${ i #*= } "
shift # past argument=value
; ;
-t= *| --type= *)
TYPE = " ${ i #*= } "
shift # past argument=value
; ;
2017-01-17 10:13:56 +08:00
-u= *| --urgency= *)
URGENCY = " ${ i #*= } "
shift # past argument=value
; ;
2017-01-16 01:18:51 +08:00
-f= *| --fork= *)
GITHUB_FORK = " ${ i #*= } "
shift # past argument=value
; ;
2017-04-25 04:50:33 +08:00
-v= *| --version= *)
PACKAGE_VERSION = " ${ i #*= } "
shift
; ;
2021-05-23 14:45:07 +08:00
-x= *| --debbuild-extra= *)
DEBBUILD_EXTRA = " ${ i #*= } "
shift
; ;
--dput= *)
DPUT = " ${ i #*= } "
shift
; ;
2017-01-16 01:18:51 +08:00
--default)
DEFAULT = YES
shift # past argument with no value
; ;
*)
2017-05-10 04:57:28 +08:00
# unknown option
read -p " Unknown option $i , continue? (Y|n) "
[ [ $REPLY = = [ yY] ] ] && { echo "continuing..." ; } || exit 1;
2017-01-16 01:18:51 +08:00
; ;
esac
done
2016-01-21 05:09:12 +08:00
2015-08-21 08:35:01 +08:00
DATE = ` date -R`
if [ " $TYPE " = = "" ] ; then
2017-01-14 22:58:36 +08:00
echo "Defaulting to source build"
TYPE = "source" ;
2017-06-09 22:38:20 +08:00
else
echo " Doing $TYPE build "
2015-08-21 08:35:01 +08:00
fi ;
2019-06-24 23:57:52 +08:00
if [ " $DISTROS " = = "" ] ; then
if [ " $RELEASE " != "" ] ; then
2021-09-04 22:17:41 +08:00
DISTROS = "xenial,bionic,focal,hirsute,impish"
2019-06-24 23:57:52 +08:00
else
DISTROS = ` lsb_release -a 2>/dev/null | grep Codename | awk '{print $2}' ` ;
fi ;
echo " Defaulting to $DISTROS for distribution " ;
2017-05-10 04:57:28 +08:00
else
2019-06-24 23:57:52 +08:00
echo " Building for $DISTROS " ;
2017-04-25 04:54:01 +08:00
fi ;
2017-04-25 04:50:33 +08:00
# Release is a special mode... it uploads to the release ppa and cannot have a snapshot
if [ " $RELEASE " != "" ] ; then
if [ " $SNAPSHOT " != "" ] ; then
echo "Releases cannot have a snapshot.... exiting."
exit 0;
fi
if [ " $GITHUB_FORK " != "" ] && [ " $GITHUB_FORK " != "ZoneMinder" ] ; then
echo " Releases cannot have a fork ( $GITHUB_FORK ).... exiting. "
exit 0;
2017-06-09 22:38:20 +08:00
else
GITHUB_FORK = "ZoneMinder" ;
2017-04-25 04:50:33 +08:00
fi
2019-06-24 23:57:52 +08:00
# We use a tag instead of a branch atm.
BRANCH = $RELEASE
2017-01-14 22:58:36 +08:00
else
2017-04-25 04:50:33 +08:00
if [ " $GITHUB_FORK " = = "" ] ; then
echo "Defaulting to ZoneMinder upstream git"
GITHUB_FORK = "ZoneMinder"
2017-01-14 22:58:36 +08:00
fi ;
2017-04-25 04:50:33 +08:00
if [ " $SNAPSHOT " = = "stable" ] ; then
if [ " $BRANCH " = = "" ] ; then
2021-06-21 09:42:43 +08:00
#REV=$(git rev-list --tags --max-count=1)
2020-03-30 22:05:19 +08:00
BRANCH = ` git describe --tags $( git rev-list --tags --max-count= 1) ` ;
2021-06-21 09:42:43 +08:00
if [ -z " $BRANCH " ] ; then
# This should only happen in CI environments where tag info isn't available
2021-07-24 23:37:07 +08:00
BRANCH = ` cat version`
2021-06-21 10:11:06 +08:00
echo " Building branch $BRANCH "
2021-06-21 09:42:43 +08:00
fi
2020-03-30 22:05:19 +08:00
if [ " $BRANCH " = = "" ] ; then
echo "Unable to determine latest stable branch!"
exit 0;
fi
2017-04-25 04:50:33 +08:00
echo " Latest stable branch is $BRANCH " ;
fi ;
else
if [ " $BRANCH " = = "" ] ; then
echo "Defaulting to master branch" ;
BRANCH = "master" ;
fi ;
if [ " $SNAPSHOT " = = "NOW" ] ; then
SNAPSHOT = ` date +%Y%m%d%H%M%S` ;
2019-10-20 23:44:19 +08:00
else
if [ " $SNAPSHOT " = = "CURRENT" ] ; then
SNAPSHOT = " `date +%Y%m%d.` $( git rev-list ${ versionhash } ..HEAD --count) "
fi ;
2017-04-25 04:50:33 +08:00
fi ;
fi ;
fi
2017-01-17 10:13:56 +08:00
2020-02-12 06:10:08 +08:00
IFS = '.' read -r -a VERSION_PARTS <<< " $RELEASE "
2019-06-24 23:50:58 +08:00
if [ " $PPA " = = "" ] ; then
if [ " $RELEASE " != "" ] ; then
# We need to use our official tarball for the original source, so grab it and overwrite our generated one.
2020-02-12 06:10:08 +08:00
if [ " ${ VERSION_PARTS [0] } . ${ VERSION_PARTS [1] } " = = "1.30" ] ; then
2019-06-24 23:50:58 +08:00
PPA = "ppa:iconnor/zoneminder-stable"
else
2020-02-12 06:10:08 +08:00
PPA = " ppa:iconnor/zoneminder- ${ VERSION_PARTS [0] } . ${ VERSION_PARTS [1] } "
2019-06-24 23:50:58 +08:00
fi ;
else
if [ " $BRANCH " = = "" ] ; then
PPA = "ppa:iconnor/zoneminder-master" ;
else
PPA = " ppa:iconnor/zoneminder- $BRANCH " ;
fi ;
fi ;
fi ;
2017-01-14 22:58:36 +08:00
# Instead of cloning from github each time, if we have a fork lying around, update it and pull from there instead.
if [ ! -d " ${ GITHUB_FORK } _zoneminder_release " ] ; then
if [ -d " ${ GITHUB_FORK } _ZoneMinder.git " ] ; then
echo " Using local clone ${ GITHUB_FORK } _ZoneMinder.git to pull from. "
cd " ${ GITHUB_FORK } _ZoneMinder.git "
2020-09-17 03:23:47 +08:00
echo "git fetch..."
git fetch
2017-01-14 22:58:36 +08:00
echo " git checkout $BRANCH "
git checkout $BRANCH
2020-09-17 03:23:47 +08:00
if [ $? -ne 0 ] ; then
echo "Failed to switch to branch."
exit 1;
fi ;
2017-01-14 22:58:36 +08:00
echo "git pull..."
git pull
cd ../
echo " git clone ${ GITHUB_FORK } _ZoneMinder.git ${ GITHUB_FORK } _zoneminder_release "
2017-06-09 22:38:20 +08:00
git clone " ${ GITHUB_FORK } _ZoneMinder.git " " ${ GITHUB_FORK } _zoneminder_release "
2017-01-14 22:58:36 +08:00
else
echo " git clone https://github.com/ $GITHUB_FORK /ZoneMinder.git ${ GITHUB_FORK } _zoneminder_release "
2017-06-09 22:38:20 +08:00
git clone " https://github.com/ $GITHUB_FORK /ZoneMinder.git " " ${ GITHUB_FORK } _zoneminder_release "
2017-01-14 22:58:36 +08:00
fi
else
echo "release dir already exists. Please remove it."
exit 0;
2015-08-21 08:35:01 +08:00
fi ;
2017-01-14 22:58:36 +08:00
cd " ${ GITHUB_FORK } _zoneminder_release "
2017-04-25 04:50:33 +08:00
git checkout $BRANCH
2017-01-14 22:58:36 +08:00
cd ../
VERSION = ` cat ${ GITHUB_FORK } _zoneminder_release/version`
2017-04-25 04:50:33 +08:00
2019-12-30 04:13:49 +08:00
if [ -z " $VERSION " ] ; then
2017-06-09 22:38:20 +08:00
exit 1;
2015-08-21 08:35:01 +08:00
fi ;
2017-01-14 22:58:36 +08:00
if [ " $SNAPSHOT " != "stable" ] && [ " $SNAPSHOT " != "" ] ; then
2017-04-25 04:50:33 +08:00
VERSION = " $VERSION ~ $SNAPSHOT " ;
2017-01-14 22:58:36 +08:00
fi ;
2017-04-25 04:50:33 +08:00
2017-05-10 04:57:28 +08:00
DIRECTORY = " zoneminder_ $VERSION " ;
2019-06-24 23:57:52 +08:00
if [ -d " $DIRECTORY .orig " ] ; then
echo " $DIRECTORY .orig already exists. Please delete it. "
exit 0;
fi ;
2017-01-14 22:58:36 +08:00
echo " Doing $TYPE release $DIRECTORY " ;
mv " ${ GITHUB_FORK } _zoneminder_release " " $DIRECTORY .orig " ;
2017-06-09 22:38:20 +08:00
if [ $? -ne 0 ] ; then
echo " Error status code is: $? "
echo "Setting up build dir failed." ;
exit $? ;
fi ;
2019-06-24 23:57:52 +08:00
2017-01-14 22:58:36 +08:00
cd " $DIRECTORY .orig " ;
2019-06-24 23:57:52 +08:00
# Init submodules
2015-08-21 08:35:01 +08:00
git submodule init
git submodule update --init --recursive
2019-06-24 23:57:52 +08:00
# Cleanup
rm -rf .git
rm .gitignore
cd ../
2021-09-04 09:59:36 +08:00
2019-06-24 23:57:52 +08:00
if [ ! -e " $DIRECTORY .orig.tar.gz " ] ; then
tar zcf $DIRECTORY .orig.tar.gz $DIRECTORY .orig
fi ;
IFS = ',' ; for DISTRO in ` echo " $DISTROS " ` ; do
echo " Generating package for $DISTRO " ;
cd $DIRECTORY .orig
if [ -e "debian" ] ; then
rm -rf debian
fi ;
# Generate Changlog
2021-09-04 22:33:33 +08:00
if [ " $DISTRO " = = "focal" ] || [ " $DISTRO " = = "buster" ] || [ " $DISTRO " = = "hirsute" ] || [ " $DISTRO " = = "impish" ] ; then
2020-04-24 03:02:00 +08:00
cp -Rpd distros/ubuntu2004 debian
2020-08-11 21:21:48 +08:00
elif [ " $DISTRO " = = "beowulf" ]
then
cp -Rpd distros/beowulf debian
else
cp -Rpd distros/ubuntu1604 debian
2017-01-14 22:58:36 +08:00
fi ;
2015-08-21 08:35:01 +08:00
2019-06-24 23:57:52 +08:00
if [ " $DEBEMAIL " != "" ] && [ " $DEBFULLNAME " != "" ] ; then
AUTHOR = " $DEBFULLNAME < $DEBEMAIL > "
2017-01-14 23:53:05 +08:00
else
2019-06-24 23:57:52 +08:00
if [ -z ` hostname -d` ] ; then
AUTHOR = " `getent passwd $USER | cut -d ':' -f 5 | cut -d ',' -f 1` <`whoami`@`hostname`.local> "
else
AUTHOR = " `getent passwd $USER | cut -d ':' -f 5 | cut -d ',' -f 1` <`whoami`@`hostname`> "
fi
2017-01-14 23:53:05 +08:00
fi
2016-01-19 22:05:40 +08:00
2019-06-24 23:57:52 +08:00
if [ " $URGENCY " = "" ] ; then
URGENCY = "medium"
fi ;
2017-04-25 04:50:33 +08:00
2019-06-24 23:57:52 +08:00
if [ " $SNAPSHOT " = = "stable" ] ; then
cat <<EOF > debian/changelog
2017-04-25 04:50:33 +08:00
zoneminder ( $VERSION -$DISTRO ${ PACKAGE_VERSION } ) $DISTRO ; urgency = $URGENCY
2017-01-14 22:58:36 +08:00
* Release $VERSION
2017-01-14 23:01:55 +08:00
-- $AUTHOR $DATE
2017-01-14 22:58:36 +08:00
EOF
2019-06-24 23:57:52 +08:00
cat <<EOF > debian/NE WS
2017-06-09 22:38:20 +08:00
zoneminder ( $VERSION -$DISTRO ${ PACKAGE_VERSION } ) $DISTRO ; urgency = $URGENCY
* Release $VERSION
-- $AUTHOR $DATE
EOF
2019-06-24 23:57:52 +08:00
else
cat <<EOF > debian/changelog
2017-04-25 04:50:33 +08:00
zoneminder ( $VERSION -$DISTRO ${ PACKAGE_VERSION } ) $DISTRO ; urgency = $URGENCY
2015-08-21 08:35:01 +08:00
*
2017-01-14 23:01:55 +08:00
-- $AUTHOR $DATE
2017-06-09 22:38:20 +08:00
EOF
2019-06-24 23:57:52 +08:00
cat <<EOF > debian/changelog
2017-06-09 22:38:20 +08:00
zoneminder ( $VERSION -$DISTRO ${ PACKAGE_VERSION } ) $DISTRO ; urgency = $URGENCY
*
2015-08-21 08:35:01 +08:00
2017-06-09 22:38:20 +08:00
-- $AUTHOR $DATE
2015-08-21 08:35:01 +08:00
EOF
2019-06-24 23:57:52 +08:00
fi ;
2017-04-25 04:50:33 +08:00
2021-09-04 09:59:36 +08:00
# Leave the .orig so that we don't pollute it when building deps
cd ..
2019-06-24 23:57:52 +08:00
if [ $TYPE = = "binary" ] ; then
2021-09-04 09:59:36 +08:00
# Auto-install all ZoneMinder's depedencies using the Debian control file
sudo apt-get install devscripts equivs
sudo mk-build-deps -ir $DIRECTORY .orig/debian/control
echo " Status: $? "
DEBUILD = debuild
2019-06-24 23:57:52 +08:00
else
2021-09-04 09:59:36 +08:00
if [ $TYPE = = "local" ] ; then
# Auto-install all ZoneMinder's depedencies using the Debian control file
sudo apt-get install devscripts equivs
sudo mk-build-deps -ir $DIRECTORY .orig/debian/control
echo " Status: $? "
DEBUILD = "debuild -i -us -uc -b"
else
# Source build, don't need build depends.
DEBUILD = "debuild -S -sa"
fi ;
2019-06-24 23:57:52 +08:00
fi ;
2021-09-04 09:59:36 +08:00
cd $DIRECTORY .orig
2019-06-24 23:57:52 +08:00
if [ " $DEBSIGN_KEYID " != "" ] ; then
DEBUILD = " $DEBUILD -k $DEBSIGN_KEYID "
fi
2021-05-23 14:45:07 +08:00
# Add any extra options specified on the CLI
DEBUILD = " $DEBUILD $DEBBUILD_EXTRA "
2019-06-24 23:57:52 +08:00
eval $DEBUILD
if [ $? -ne 0 ] ; then
2021-05-23 14:45:07 +08:00
echo " Error status code is: $? "
2019-06-24 23:57:52 +08:00
echo "Build failed." ;
exit $? ;
2017-01-14 22:58:36 +08:00
fi ;
2016-01-05 22:04:04 +08:00
2019-06-24 23:57:52 +08:00
cd ../
2016-01-21 05:09:12 +08:00
2019-06-24 23:57:52 +08:00
if [ $TYPE = = "binary" ] ; then
if [ " $INTERACTIVE " != "no" ] ; then
read -p "Not doing dput since it's a binary release. Do you want to install it? (y/N)"
if [ [ $REPLY = = [ yY] ] ] ; then
sudo dpkg -i $DIRECTORY *.deb
fi ;
2017-06-09 22:38:20 +08:00
read -p "Do you want to upload this binary to zmrepo? (y/N)"
if [ [ $REPLY = = [ yY] ] ] ; then
if [ " $RELEASE " != "" ] ; then
2020-02-12 06:10:08 +08:00
scp " zoneminder_ ${ VERSION } - ${ DISTRO } " * " zoneminder-doc_ ${ VERSION } - ${ DISTRO } " * " zoneminder-dbg_ ${ VERSION } - ${ DISTRO } " * " zoneminder_ ${ VERSION } .orig.tar.gz " " zmrepo@zmrepo.connortechnology.com:debian/release- ${ VERSION_PARTS [0] } . ${ VERSION_PARTS [1] } /mini-dinstall/incoming/ "
2017-06-09 22:38:20 +08:00
else
if [ " $BRANCH " = = "" ] ; then
2019-06-24 23:57:52 +08:00
scp " zoneminder_ ${ VERSION } - ${ DISTRO } " * " zoneminder-doc_ ${ VERSION } - ${ DISTRO } " * " zoneminder-dbg_ ${ VERSION } - ${ DISTRO } " * " zoneminder_ ${ VERSION } .orig.tar.gz " "zmrepo@zmrepo.connortechnology.com:debian/master/mini-dinstall/incoming/"
2017-06-09 22:38:20 +08:00
else
2019-06-24 23:57:52 +08:00
scp " $DIRECTORY - ${ DISTRO } " * " zoneminder-doc_ ${ VERSION } - ${ DISTRO } " * " zoneminder-dbg_ ${ VERSION } - ${ DISTRO } " * " zoneminder_ ${ VERSION } .orig.tar.gz " " zmrepo@zmrepo.connortechnology.com:debian/ ${ BRANCH } /mini-dinstall/incoming/ "
2017-06-09 22:38:20 +08:00
fi ;
2017-04-25 04:50:33 +08:00
fi ;
2017-06-09 22:38:20 +08:00
fi ;
2017-04-25 04:50:33 +08:00
fi ;
2019-06-24 23:57:52 +08:00
else
SC = " zoneminder_ ${ VERSION } - ${ DISTRO } ${ PACKAGE_VERSION } _source.changes " ;
2017-01-14 22:58:36 +08:00
2019-06-24 23:57:52 +08:00
dput = "Y" ;
if [ " $INTERACTIVE " != "no" ] ; then
2020-09-17 03:29:16 +08:00
read -p " Ready to dput $SC to $PPA ? Y/n... " ;
2019-06-24 23:57:52 +08:00
if [ [ " $REPLY " = = [ yY] ] ] ; then
dput $PPA $SC
fi ;
else
2021-05-23 14:45:07 +08:00
if [ " $DPUT " != "no" ] ; then
echo " dputting to $PPA " ;
dput $PPA $SC
fi ;
2019-06-24 23:50:58 +08:00
fi ;
2017-06-09 22:38:20 +08:00
fi ;
2019-06-24 23:57:52 +08:00
done ; # foreach distro
if [ " $INTERACTIVE " != "no" ] ; then
read -p "Do you want to keep the checked out version of Zoneminder (incase you want to modify it later) [y/N]"
[ [ $REPLY = = [ yY] ] ] && { mv " $DIRECTORY .orig " zoneminder_release; echo "The checked out copy is preserved in zoneminder_release" ; } || { rm -fr " $DIRECTORY .orig " ; echo "The checked out copy has been deleted" ; }
echo "Done!"
else
rm -fr " $DIRECTORY .orig " ; echo "The checked out copy has been deleted" ;
fi