1#!/bin/bash -ev
2
3# Based on instructions at https://wiki.debian.org/IntroDebianPackaging
4
5# Before using this you probably need to install
6#   sudo pbuilder devscripts lintian cdeboostrap (or debootstrap)
7# and maybe dpkg-sig.  Also:
8# set up for sudo
9# set up pbuilder with
10#   sudo emacs -nw /etc/pbuilderrc
11#   ...change MIRRORSITE
12#   sudo pbuilder create --distribution sarge/etch/whatever
13# and/or update with
14#   sudo pbuilder update
15# Expect a lot of warnings re LOGNAME - see Debian bug Bug#275118
16
17# TODO: DEBEMAIL
18
19VER=`./VERSION`
20
21TARBALL=fracplanet-${VER}.tar.gz
22
23if [ ! -s ${TARBALL} ] ; then
24    echo "Could't find ${TARBALL}" ;
25    exit ;
26fi
27
28export DISTRIBUTION=`lsb_release -s -c`
29
30echo "*** Will package ${TARBALL} for distribution \"${DISTRIBUTION}\""
31echo -n "*** Starting in 5 seconds..."
32for t in 5 4 3 2 1 ; do sleep 1 ; echo -n "." ; done
33
34PROJECT=`echo $TARBALL | sed 's/-.*//'`
35TARBALLORIG="${PROJECT}_${VER}.orig.tar.gz"
36REV="1${DISTRIBUTION}1"
37
38WORKDIR=pkg_${VER}-${REV}
39rm -r -f ${WORKDIR}
40mkdir ${WORKDIR}
41cd ${WORKDIR}
42
43cp ../${TARBALL} ${TARBALLORIG}
44
45tar xfz ${TARBALLORIG}
46
47if [! -d fracplanet-${VER} ] ; then
48    echo "Could't find fracplanet-${VER} after unpacking" ;
49    exit ;
50fi
51
52cd fracplanet-${VER}
53
54mkdir debian
55dch --create -v ${VER}-${REV} --package fracplanet Create debian package from tarball
56
57echo "9" > debian/compat
58
59cat <<EOF > debian/control
60Source: fracplanet
61Section: graphics
62Priority: optional
63Standards-Version: 3.9.4
64Maintainer: ${DEBEMAIL}
65Build-Depends: debhelper (>=9),qt4-qmake,libqt4-dev,libqt4-opengl-dev,libboost-dev,libboost-program-options-dev,xsltproc
66Homepage: http://www.bottlenose.demon.co.uk/share/fracplanet/
67
68Package: fracplanet
69Architecture: any
70Depends: \${shlibs:Depends}, \${misc:Depends}
71Description: Fractal terrain generator
72 Fracplanet generates random planets and terrain with oceans, 
73 mountains, icecaps and rivers.  Parameters are specified interactively 
74 and the results displayed using OpenGL.  The generated objects can be
75 exported as geometry for Pov-Ray or Blender, or as textures.
76Suggests: blender
77Homepage: http://www.bottlenose.demon.co.uk/share/fracplanet/
78EOF
79
80echo "Copyright 2014 ${DEBEMAIL}" > debian/copyright
81echo "GPL2 license; see /usr/share/common-licenses/GPL-2" >> debian/copyright
82
83echo '#!/usr/bin/make -f' > debian/rules
84echo '%:' >> debian/rules
85echo -e '\tdh $@' >> debian/rules
86echo '' >> debian/rules
87echo 'override_dh_auto_configure:' >> debian/rules
88echo -e '\tQTDIR=/usr/share/qt4 bash -c "`dpkg-buildflags --export=configure` ./configure"' >> debian/rules
89echo '' >> debian/rules
90echo 'override_dh_auto_install:' >> debian/rules
91echo -e '\tmkdir -p debian/fracplanet/usr/bin && cp fracplanet debian/fracplanet/usr/bin/' >> debian/rules
92echo -e '\tmkdir -p debian/fracplanet/usr/share/man/man1 && cp man/man1/fracplanet.1 debian/fracplanet/usr/share/man/man1/' >> debian/rules
93echo -e '\tmkdir -p debian/fracplanet/usr/share/doc/fracplanet && cp fracplanet.htm fracplanet.css BUGS TODO NEWS THANKS debian/fracplanet/usr/share/doc/fracplanet/' >> debian/rules
94
95cp fracplanet.menu debian/
96
97chmod 755 debian/rules
98
99echo <<EOF > debian/fracplanet.dirs
100/usr/bin
101/usr/share/man/man1
102/usr/share/doc/fracplanet
103EOF
104
105mkdir debian/source
106echo "3.0 (quilt)" > debian/source/format
107
108debuild -us -uc -S  # -S just builds dsc.
109#debuild -us -uc -b  # Builds binary package, but not in isolated enironment.
110
111cd ..
112
113echo ${PROJECT}_${VER}-${REV}.dsc
114ls -lh ${PROJECT}_${VER}-${REV}.dsc
115mkdir pbuilder
116sudo pbuilder --build --buildresult pbuilder ${PROJECT}_${VER}-${REV}.dsc
117sudo chown ${USER}:${USER} pbuilder/*
118
119#RESULT=`(cd .. ; find ${WORKDIR} -name '*.deb')`
120#echo "Results: ${RESULT}"
121#echo "Don't forget to lintian ${RESULT}"
122#echo 'Also dpkg-sig --sign builder -k $DPKGSIG_KEYID any .deb files'
123