1#!/bin/sh 2# ebusd - daemon for communication with eBUS heating systems. 3# Copyright (C) 2014-2017 John Baier <ebusd@ebusd.eu> 4# 5# This program is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 3 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18keepbuilddir= 19if [ "x$1" = "x--keepbuilddir" ]; then 20 keepbuilddir=1 21 shift 22fi 23reusebuilddir= 24if [ "x$1" = "x--reusebuilddir" ]; then 25 reusebuilddir=1 26 shift 27fi 28 29echo "*************" 30echo " prepare" 31echo "*************" 32echo 33tags=`git fetch -t` 34if [ -n "$tags" ]; then 35 echo "tags were updated:" 36 echo $tags 37 echo "git pull is recommended. stopped." 38 exit 1 39fi 40VERSION=`head -n 1 VERSION` 41ARCH=`dpkg --print-architecture` 42BUILD="build-$ARCH" 43RELEASE="ebusd-$VERSION" 44PACKAGE="${RELEASE}_${ARCH}" 45if [ -n "$reusebuilddir" ]; then 46 echo "reusing build directory $BUILD" 47else 48 if [ -n "$keepbuilddir" ]; then 49 ./autogen.sh $@ || exit 1 50 fi 51 rm -rf "$BUILD" 52fi 53mkdir -p "$BUILD" || exit 1 54cd "$BUILD" || exit 1 55if [ -z "$reusebuilddir" ]; then 56 (tar cf - -C .. "--exclude=./$BUILD" --exclude=./.* "--exclude=*.o" "--exclude=*.a" .| tar xf -) || exit 1 57fi 58 59echo 60echo "*************" 61echo " build" 62echo "*************" 63echo 64if [ -n "$reusebuilddir" ] || [ -z "$keepbuilddir" ]; then 65 ./autogen.sh $@ || exit 1 66fi 67make DESTDIR="$PWD/$RELEASE" install-strip || exit 1 68extralibs= 69ldd $RELEASE/usr/bin/ebusd | egrep -q libmosquitto.so.0 70if [ $? -eq 0 ]; then 71 extralibs=', libmosquitto0' 72 PACKAGE="${PACKAGE}_mqtt0" 73else 74 ldd $RELEASE/usr/bin/ebusd | egrep -q libmosquitto.so.1 75 if [ $? -eq 0 ]; then 76 extralibs=', libmosquitto1' 77 PACKAGE="${PACKAGE}_mqtt1" 78 fi 79fi 80 81echo 82echo "*************" 83echo " test" 84echo "*************" 85echo 86(cd src/lib/ebus/test && make >/dev/null && ./test_filereader && ./test_data && ./test_message && ./test_symbol) || (echo "test failed"; exit 1) 87 88echo 89echo "*************" 90echo " pack" 91echo "*************" 92echo 93mkdir -p $RELEASE/DEBIAN $RELEASE/etc/default $RELEASE/etc/logrotate.d || exit 1 94rm $RELEASE/usr/bin/ebusfeed 95mkdir -p $RELEASE/lib/systemd/system || exit 1 96cp contrib/debian/systemd/ebusd.service $RELEASE/lib/systemd/system/ebusd.service || exit 1 97mkdir -p $RELEASE/etc/init.d || exit 1 98cp contrib/debian/init.d/ebusd $RELEASE/etc/init.d/ebusd || exit 1 99cp contrib/debian/default/ebusd $RELEASE/etc/default/ebusd || exit 1 100cp contrib/etc/logrotate.d/ebusd $RELEASE/etc/logrotate.d/ || exit 1 101cp ChangeLog.md $RELEASE/DEBIAN/changelog || exit 1 102cat <<EOF > $RELEASE/DEBIAN/control 103Package: ebusd 104Version: $VERSION 105Section: net 106Priority: required 107Architecture: $ARCH 108Maintainer: John Baier <ebusd@ebusd.eu> 109Homepage: https://github.com/john30/ebusd 110Bugs: https://github.com/john30/ebusd/issues 111Depends: logrotate, libstdc++6 (>= 4.8.1), libc6, libgcc1$extralibs 112Description: eBUS daemon. 113 ebusd is a daemon for handling communication with eBUS devices connected to a 114 2-wire bus system. 115EOF 116cat <<EOF > $RELEASE/DEBIAN/dirs 117/etc/ebusd 118/etc/default 119/etc/init.d 120/etc/logrotate.d 121/lib/systemd/system 122/usr/bin 123EOF 124cat <<EOF > $RELEASE/DEBIAN/postinst 125#!/bin/sh 126if [ -d /run/systemd/system ]; then 127 start='systemctl start ebusd' 128 autostart='systemctl enable ebusd' 129else 130 start='service ebusd start' 131 autostart='update-rc.d ebusd defaults' 132fi 133echo "Instructions:" 134echo "1. Edit /etc/default/ebusd if necessary" 135echo " (especially if your device is not /dev/ttyUSB0)" 136echo "2. Start the daemon with '$start'" 137echo "3. Check the log file /var/log/ebusd.log" 138echo "4. Make the daemon autostart with '$autostart'" 139EOF 140chmod 755 $RELEASE/DEBIAN/postinst 141 142dpkg -b $RELEASE || exit 1 143mv $RELEASE.deb "../${PACKAGE}.deb" || exit 1 144 145echo 146echo "*************" 147echo " cleanup" 148echo "*************" 149echo 150cd .. 151if [ -n "$keepbuilddir" ]; then 152 echo "keeping build directory $BUILD" 153else 154 rm -rf "$BUILD" 155fi 156 157echo 158echo "Package created: ${PACKAGE}.deb" 159echo 160echo "Info:" 161dpkg --info "${PACKAGE}.deb" 162echo 163echo "Content:" 164dpkg -c "${PACKAGE}.deb" 165