#!/bin/sh # http://www.phys.ethz.ch/~franklin/Projects/dphys2/makesourcepackage # - generate directory structure and content and operate for making packages # - second version which generates source packages, not just binaries # copyright ETH Zuerich Physics Departement, # use under either BSD or GPL license # author Neil Franklin, last modification 2004.01.09 # this script is intended to be run as an normal user # use as makesourcepackage [options] # ------ configuration to run site package # first CONF_* various site or subnet dependant user config variables # then DEBUG_* various debugging settings # last SYS_* various system internal values # some of these are overridable by command line options # --- CONF_* various site or subnet dependant user config variables # this is prepended to packagename if only a hostname is given (no - in name) # do not insert an specific hostname into this, this is prefixed to the hostn # to disable this feature, set this to an empty string # we don't make 100s of host packages any more, so now default disabled CONF_HOST_TO_PKG_PREFIX="" #CONF_HOST_TO_PKG_PREFIX=dphys-host- # this is the contents for all author remarks in files CONF_PRG="dphys2 makesrcpackage script" # this is for the /usr/share/doc/*/changelog.Debian and /DEBIAN/control # and the Packages list entry for apt-get and dpkg CONF_PRG_AND_MAIL="dphys2 make source package script " # this is the contents for all copyright remarks in files # the second line with "#" is part of the string, needed so for scripts #CONF_COPY="released into the Public Domain, no license restrictions # use it for what you want to, share and enjoy" CONF_COPY="copyright ETH Zuerich Physics Departement, use under either BSD or GPL license" # what we put into the package as description # edit this by the user, after -g, to what this package is for CONF_DESC_SH="Simple package, generated by ${CONF_PRG}" # we offer 3 lines, blank at front gets added automatically CONF_DESC_1="This package does not yet know what it does." CONF_DESC_2="The User of the ${CONF_PRG} should edit debian/control." #CONF_DESC_3="" # automatically remove *.changes file, only needed for official Debian uploads # our policy is that, we do not use it here, so delete it CONF_REMOVE_CHANGES_FILE=yes # this is for the -u update, and is *very* site specific code, may need changes # where we store our local packages to be served by local Debian mirror CONF_UPLOAD_BASE=/pub/debian-local/dists/woody/local # where our Makefile is for updating local package lists # comment this out to prevent package list update mechanism being run CONF_UPLOAD_UPDATER=/pub/debian-local/ # --- DEBUG_*, various debugging settings # set this to output debug state info after each step, see also -v #DEBUG_PRINT_STEP=yes # do not delete temporary files (.../debian/tmp etc), see also -n #DEBUG_LEAVE_TEMPFILES=yes # --- SYS_*, various system internal values # set our default architecture, no binary stuff in host or site packages SYS_ARCH=all # set our default section, host or site packages are in admin SYS_SECTION=admin # set out default debianisation level # as we we once use(d) 8 digit date (now 8.6 date.time) for version numbers # this could then be used if multiple versions in one day SYS_PKG_LEVEL=1 ### ------ actual implementation from here on # no user settings any more below this point # --- parse command line # so long next parameter is a set of options (= begins with an - character) while [ x`/bin/echo $1 | /usr/bin/cut -c 1` = x- ] ; do # extract options from parameter (cut off the "-") OPTS=`/bin/echo $1 | /usr/bin/cut -c 2-` shift 1 # so long still unprocessed option characters while [ x${OPTS} != x ] ; do # first option to process OPT=`/bin/echo ${OPTS} | /usr/bin/cut -c 1` # and rest of options for later OPTS=`/bin/echo ${OPTS} | /usr/bin/cut -c 2-` case ${OPT} in g) # generate: generate new package from scratch DO_GEN=yes ;; a) # architecture: user wants to set custom architecture type, not "all" SYS_ARCH=$1 shift 1 ;; s) # section: user wants to set custom section type, not "(main/) admin" SYS_SECTION=$1 shift 1 ;; c) # clone: generate new package, take/clone content from existing package DO_CLONE=$1 shift 1 ;; x) # (e)xpand: expand existing package back to an work directory # this is not -e expand, because it crashes the echo in option test DO_EXPAND=yes ;; f) # fetch: fetch existing package back from local Debian mirror DO_FETCH=yes ;; d) # depend: add an further dependency, extend Depends: line if [ "x${DO_DEPEND}" != x ] ; then DO_DEPEND="${DO_DEPEND}, $1" else DO_DEPEND=$1 fi shift 1 ;; o) # option: add an option line to control file DO_OPTION=$1 shift 1 ;; l) # log: generate an new changelog entry with version number DO_CLOG=$1 shift 1 ;; p) # package: take work directory, and package it DO_PACK=yes ;; n) # nodelete: do not delete temp files (.../debian/temp/*) DEBUG_LEAVE_TEMPFILES=yes ;; t) # tidy: delete work directory, leaves only package file DO_TIDY=yes ;; u) # upload: upload generated package files to local Debian mirror DO_UPLOAD=yes ;; r) # remove: remove work package files, after uploading DO_REMOVE=yes ;; i) # info: show progress DO_INFO=yes ;; v) # verbose: show progress DEBUG_PRINT_STEP=yes ;; h) # help: give out help how this script can be used /bin/cat << EOF Usage is: $0 [options] packagename options: [for creating] -g generate: generate work directories and their content -a arch architecture: set architecture to this, default: ${SYS_ARCH} -s section section: set section to this, default: ${SYS_SECTION} examples: admin, misc, non-free/admin, contrib/misc [for cloning] -c oldpackage clone/copy: clone contents from , instead of new * Makefile and README copied and package name in them changed * control copied and package name in it changed * postinst and prerm copied and package name in them changed * rules file and package name in it changed * all other files just copied unchanged if no - in the oldpackage name, expand like packagename if directory of old package clone that, else temporary unpack [for expanding] -x (e)xpand: take an .tar.gz and make work directories from it this can not work from .deb, that does not have source in it this can undo the effect of -t, so long -p was done before -t gotcha: give only package name, not full .tar.gz file name [for fetching] -f fetch: fetch the .tar.gz and .dsc from local Debian mirror and expand it to an working directory [for modifying] -d dependancy depend: extend the Depends: line with this dependancy if there is no Depends: line in control, it will be added this option can be used multiple times, get all added -o optionline option: add this option line to the control file before Maintainer: line (places after Depends:, newer below) or extend existing line of this type, if one is there use this for Predepends:, Conflicts:, Provides:, Recommends: [for packing] -l logtext log: generate new changelog entry and version number using the given log text for the * line -p pack: pack up the work directories, making package files if there is /debian/makesourcepackage file, run it can be used to update in / install from /debian/ -n nodelete: do not delete temp files (.../debian/temp/*) -t tidy: tidy up, delete work directories, leave only package -u upload: upload generated package files to local Debian mirror *** this is implemented highly specific to our site *** -r remove: delete work copies of package files after upload [other stuff] -i info: show information about an .deb package this will not work if there is only an work directory -v verbose: show progress -h help: output this text, and then abort operation If multiple of (-g or -c or -x or -f) -d -o -r -p -t -u -i are used, they are processed in the row they appear here in the help section, not the row they are typed on the command line. Other options modyfy behaviour. packagename: something like dphys-site dphys-group- dphys-host- if no - in the name, it is regarded as hostname and expanded to an packagename by prepending ${CONF_HOST_TO_PKG_PREFIX} EOF exit 0 ;; *) # not one of our recognized options /bin/echo $0: unknown option at: ${OPT} >&2 /bin/echo # call self with -h to display help $0 -h exit 1 ;; esac done done if [ "x${DO_GEN}${DO_CLONE}${DO_EXPAND}${DO_FETCH}${DO_DEPEND}${DO_OPTION}\ ${DO_CLOG}${DO_PACK}${DO_TIDY}${DO_UPLOAD}${DO_REMOVE}${DO_INFO}" = x ] ; then /bin/echo $0: WARNING: no option selected, doing nothing >&2 fi if [ $# != 1 ] ; then # user did not give an parameter (package name), or gave multiple /bin/echo $0: missing package name to work on, or multiple given >&2 /bin/echo # call self with -h to display help $0 -h exit 1 fi PKG_NAME=$1 if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' options are: DO_GEN: ${DO_GEN}, DO_CLONE: ${DO_CLONE}, \ DO_EXPAND: ${DO_EXPAND}, DO_FETCH: ${DO_FETCH}, \ DO_DEPEND: ${DO_DEPEND}, DO_OPTION: ${DO_OPTION}, \ DO_CLOG: ${DO_CLOG}, DO_PACK: ${DO_PACK}, \ DO_TIDY: ${DO_TIDY}, DO_UPLOAD: ${DO_UPLOAD}, \ DO_REMOVE: ${DO_REMOVE}, DO_INFO: ${DO_INFO}, \ PKG_NAME: ${PKG_NAME} fi # --- extend hostnames to packagenames # no "-" in the given packagename -> is a hostname # ###bug avoidance: the - in the echo part is needed # else cut (at least GNU textutils 2.0) just gives the first field, # instead of an empty line! if [ x`/bin/echo ${PKG_NAME}- | /usr/bin/cut -f 2 -d "-"` = x ] ; then # extend an hostname to an packagename PKG_NAME=${CONF_HOST_TO_PKG_PREFIX}${PKG_NAME} fi # strip possible trailing / in name, from tab completion if user did that PKG_NAME=`/bin/echo ${PKG_NAME} | /usr/bin/cut -f 1 -d "/"` # strip possible version number in name, from tab completion if user did that PKG_NAME=`/bin/echo ${PKG_NAME} | /usr/bin/cut -f 1 -d "_"` if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' expanded package name is: ${PKG_NAME} fi if [ x${DO_CLONE} != x ] ; then # no "-" in the given clone packagename -> is a clone hostname if [ x`/bin/echo ${DO_CLONE}- | /usr/bin/cut -f 2 -d "-" ` = x ] ; then # extend an clone hostname to an clone packagename DO_CLONE=${CONF_HOST_TO_PKG_PREFIX}${DO_CLONE} fi DO_CLONE=`/bin/echo ${DO_CLONE} | /usr/bin/cut -f 1 -d "/"` DO_CLONE=`/bin/echo ${DO_CLONE} | /usr/bin/cut -f 1 -d "_"` if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' expanded clone source name is: ${DO_CLONE} fi fi # --- make the working directories, upstream and debianising # not inside the "if" because used in multiple places/functions later PKG_DIR=${PKG_NAME} DEB_DIR=${PKG_DIR}/debian if [ x${DO_GEN} = xyes -o x${DO_CLONE} != x ] ; then /bin/mkdir -p ${PKG_DIR} /bin/mkdir -p ${DEB_DIR} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' work directories created, upstream and debianising /bin/ls -ald ${PKG_DIR} ${DEB_DIR} fi fi # --- if we are cloning, copy all the stuff from existing package if [ x${DO_CLONE} != x ] ; then # do we find an work directory (must be same or newer than a package) if [ -d ${DO_CLONE}/debian ] ; then # copy clone packages source files into new package /bin/tar cf - -C ${DO_CLONE} . | /bin/tar xpf - -C ${PKG_DIR} else # only got an archive, no possibly newer directory, use archive # find newest version of this package to clone CLONE_TARNAME=`/bin/ls -1d ${DO_CLONE}_*.tar.gz | /usr/bin/tail -1` # unpack clone packages source files into new package /bin/tar zxpf ${CLONE_TARNAME} # copy clone packages source files into new package /bin/tar cf - -C ${DO_CLONE} . | /bin/tar xpf - -C ${PKG_DIR} # and delete unpacked clone packages source files again /bin/rm -rf ${DO_CLONE} fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then if [ -d ${DO_CLONE}/debian ] ; then /bin/echo '###' clone from package work directory name is: ${DO_CLONE} else /bin/echo '###' clone from package archive name is: ${CLONE_TARNAME} fi fi fi # --- expand existing package back to an work directory if [ x${DO_EXPAND} != x ] ; then # do this before all modifying options, so that they can be applied in one go # allows -x -d something -p -t to add an Depends: to an package # find newest version of this package to clone # we need to expand from .tar.gz, as .deb does not have source files PKG_TARNAME=`/bin/ls -1d ${PKG_NAME}_*.tar.gz | /usr/bin/tail -1` # unpack packages source files into new work directory /bin/tar zxpf ${PKG_TARNAME} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' expanded package archive is: ${PKG_TARNAME} fi fi # --- fetch package back from local Debian mirror if [ x${DO_FETCH} != x ] ; then # do this before all modifying options, so that they can be applied in one go # allows -f -d something -p -t to add an Depends: to an package # fetch this using apt-get /usr/bin/apt-get source ${PKG_NAME} PKG_APTGET_DIR=`/bin/ls -1d ${PKG_NAME}-* | /usr/bin/tail -1` /bin/mv ${PKG_APTGET_DIR} ${PKG_DIR} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' fetched package archive is: ${PKG_NAME} fi fi # --- format date string for time stamp, used in various source files if [ x${DO_GEN} = xyes ] ; then # current date for "last modufication" for generated files DATE_STAMP=`/bin/date +%Y.%m.%d` fi # --- "upstream" package # generate the "upstream" package, mainly an dummy Makefile, for extending if [ x${DO_GEN} = xyes ] ; then if [ ! -f ${PKG_DIR}/Makefile ] ; then /bin/cat << EOF > ${PKG_DIR}/Makefile # ${PKG_DIR}/Makefile - drive "upstream" compiling for package # author/generator ${CONF_PRG}, # last modification/generation ${DATE_STAMP} `/bin/sed -e 's/^\([^#].*\)/# \1/' << EOF2 # This Makefile is ${CONF_COPY} EOF2` PREFIX = \$(DESTDIR)/usr MANDIR = \$(PREFIX)/share/man/man8 all: @/bin/echo no action to upstream compile clean: @/bin/echo no action to upstream clean distclean: clean install: @/bin/echo no action to upstream install uninstall: @/bin/echo no action to upstream uninstall EOF fi if [ ! -f ${PKG_DIR}/README ] ; then /bin/cat << EOF > ${PKG_DIR}/README ${PKG_DIR}/README author/generator ${CONF_PRG}, last modification/generation ${DATE_STAMP} This text (and all other files) are ${CONF_COPY} This "upstream" was generated automatically, by ${CONF_PRG} EOF fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' upstream package generated /bin/ls -al ${PKG_DIR}/Makefile ${PKG_DIR}/README fi fi # modify the "upstream" package files from existing package, just new name # leave this unchanged, as we want the old stuff incl user changes in it if [ x${DO_CLONE} != x ] ; then # fix up package name where it appears if [ -f ${PKG_DIR}/Makefile ] ; then /bin/sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" ${PKG_DIR}/Makefile \ > ${PKG_DIR}/.Makefile /bin/mv ${PKG_DIR}/.Makefile ${PKG_DIR}/Makefile fi if [ -f ${PKG_DIR}/README ] ; then /bin/sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" ${PKG_DIR}/README \ > ${PKG_DIR}/.README /bin/mv ${PKG_DIR}/.README ${PKG_DIR}/README fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' upstream files, Makefile and README, modified: /bin/ls -al ${PKG_DIR}/* fi fi # --- control file # generate an basic control file for this package if [ x${DO_GEN} = xyes ] ; then # this control file may need user editing/extending later on # such as adding Depends:, or other such control lines # that is the reason for splitting into generate/pack/tidy functions /bin/cat << EOF > ${DEB_DIR}/control Source: ${PKG_NAME} Section: ${SYS_SECTION} Priority: optional Maintainer: ${CONF_PRG_AND_MAIL} Standards-Version: 3.5.2 Package: ${PKG_NAME} Architecture: ${SYS_ARCH} Description: ${CONF_DESC_SH} ${CONF_DESC_1} ${CONF_DESC_2} ${CONF_DESC_3} EOF if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' control file generated /bin/ls -al ${DEB_DIR}/control fi fi # modify the control file from existing package, just new name # leave this unchanged, as we want the old stuff incl user changes in it if [ x${DO_CLONE} != x ] ; then # fix up the control file with this packages name if [ -f ${DEB_DIR}/control ] ; then /bin/sed -e "/^Source:/s/.*/Source: ${PKG_NAME}/g" ${DEB_DIR}/control \ > ${DEB_DIR}/.control /bin/sed -e "/^Package:/s/.*/Package: ${PKG_NAME}/g" ${DEB_DIR}/.control \ > ${DEB_DIR}/control /bin/rm ${DEB_DIR}/.control else /bin/echo WARNING: no control file, something is fishy here fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' control file modified: /bin/ls -al ${DEB_DIR}/control fi fi # --- satisfy the Debian copyright fetishists for this package # generate our standard copyright text file if [ x${DO_GEN} = xyes ] ; then # we just put in our standard copyright message # we use here cat instead of echo, so that line breaks stay /bin/cat << EOF > ${DEB_DIR}/copyright This package ${PKG_NAME} is ${CONF_COPY} EOF if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' copyright generated /bin/ls -al ${DEB_DIR}/copyright fi fi # modify the copyright file from existing package, just new name # leave this unchanged, as we want the old stuff incl user changes in it # cloning takes over the existing copyright, leave unchanged if [ x${DO_CLONE} != x ] ; then # fix up package name where it appears if [ -f ${DEB_DIR}/copyright ] ; then /bin/sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" ${DEB_DIR}/copyright \ > ${DEB_DIR}/.copyright /bin/mv ${DEB_DIR}/.copyright ${DEB_DIR}/copyright fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' copyright file modified: /bin/ls -al ${DEB_DIR}copyright fi fi # --- changelog # generate empty changelog (later changelog.Debian) if [ "x${DO_GEN}" != x ] ; then # don't fill in changelog file now, as user will do so, with editor or -l # for the moment start an empty changelog file # this allows emacs changelog mode users to just open it in dired /bin/touch ${DEB_DIR}/changelog if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' empty Debian changelog generated /bin/ls -al ${DEB_DIR}/changelog fi fi # cloning use unchanged file # no changing names, as this is part of the history to be logged # --- postinst/prerm stuff # generate the postinst/prerm stuff # this is just the standard linking stuff that everyone needs to repeat # they really should have put this functionality into the actual installer if [ x${DO_GEN} = xyes ] ; then /bin/cat < ${DEB_DIR}/postinst #!/bin/sh # ${DEB_DIR}/postinst - set up package # author/generator ${CONF_PRG}, # last modification/generation ${DATE_STAMP} `/bin/sed -e 's/^\([^#].*\)/# \1/' << EOF2 # This script is ${CONF_COPY} EOF2` set -e # - begin ${CONF_PRG} added for docsymlink if [ \$1 = configure ]; then if [ -d /usr/doc -a ! -e /usr/doc/${PKG_NAME} -a \\ -d /usr/share/doc/${PKG_NAME} ]; then /bin/ln -sf ../share/doc/${PKG_NAME} /usr/doc/${PKG_NAME} fi fi # - end ${CONF_PRG} added for docsymlink exit 0 EOF /bin/cat < ${DEB_DIR}/prerm #!/bin/sh # ${DEB_DIR}/prerm - clean up package # author/generator ${CONF_PRG}, # last modification/generation ${DATE_STAMP} `/bin/sed -e 's/^\([^#].*\)/# \1/' << EOF2 # This script is ${CONF_COPY} EOF2` set -e # - begin ${CONF_PRG} added for docsymlink if [ \$1 = upgrade -o \$1 = remove ]; then if [ -L /usr/doc/${PKG_NAME} ]; then /bin/rm -f /usr/doc/${PKG_NAME} fi fi # - end ${CONF_PRG} added for docsymlink exit 0 EOF /bin/chmod 755 ${DEB_DIR}/postinst ${DEB_DIR}/prerm if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' postinst and prerm scripts made /bin/ls -al ${DEB_DIR}/postinst ${DEB_DIR}/prerm fi fi # modify any post* and pre* files from existing package, just new name # leave this unchanged, as we want the old stuff incl user changes in it # just change name in all files, important for doc links if [ x${DO_CLONE} != x ] ; then # fix up package name where it appears if [ -f ${DEB_DIR}/preinst ] ; then /bin/sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" ${DEB_DIR}/preinst \ > ${DEB_DIR}/.preinst /bin/mv ${DEB_DIR}/.preinst ${DEB_DIR}/preinst /bin/chmod 755 ${DEB_DIR}/preinst fi if [ -f ${DEB_DIR}/postinst ] ; then /bin/sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" ${DEB_DIR}/postinst \ > ${DEB_DIR}/.postinst /bin/mv ${DEB_DIR}/.postinst ${DEB_DIR}/postinst /bin/chmod 755 ${DEB_DIR}/postinst fi if [ -f ${DEB_DIR}/prerm ] ; then /bin/sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" ${DEB_DIR}/prerm \ > ${DEB_DIR}/.prerm /bin/mv ${DEB_DIR}/.prerm ${DEB_DIR}/prerm /bin/chmod 755 ${DEB_DIR}/prerm fi if [ -f ${DEB_DIR}/postrm ] ; then /bin/sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" ${DEB_DIR}/postrm \ > ${DEB_DIR}/.postrm /bin/mv ${DEB_DIR}/.postrm ${DEB_DIR}/postrm /bin/chmod 755 ${DEB_DIR}/postrm fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' post*/pre* files modified: /bin/ls -al ${DEB_DIR}/post* ${DEB_DIR}/pre* fi fi # --- "Makefile" stuff # generate the rules "Makefile" stuff if [ x${DO_GEN} = xyes ] ; then /bin/cat << EOF > ${DEB_DIR}/rules #!/usr/bin/make -f # ${DEB_DIR}/rules - drive debian packaging for package # author/generator ${CONF_PRG}, # last modification/generation ${DATE_STAMP} # made by taking standard Debian New Maintainers Guide example by Joey Hess # and dropping unused functions and stripping/converting the dh_* stuff `/bin/sed -e 's/^\([^#].*\)/# \1/' << EOF2 # This rules file is ${CONF_COPY} EOF2` TMP=debian/tmp build: build-stamp build-stamp: @if [ ! -f debian/control ] ; then \\ /bin/echo sorry, you need to be in source package main directory ; \\ exit 1 ; \\ fi @# compiling can be done as non-root, no test here @# run upstream Makefile @\$(MAKE) @# mark this after compiling @/bin/touch build-stamp install: build @if [ ! -f debian/control ] ; then \\ /bin/echo sorry, you need to be in source package main directory ; \\ exit 1 ; \\ fi @if [ \`/usr/bin/whoami\` != root ] ; then \\ /bin/echo sorry, you need to be root to install ; \\ exit 1 ; \\ fi @# clean up debris from previous install runs @/bin/rm -rf \$(TMP) debian/substvars @if [ ! -e \$(TMP) ] ; then \\ /bin/mkdir -p \$(TMP) ; \\ fi @# run upstream Makefile @CURDIR=. @\$(MAKE) install DESTDIR=\$(CURDIR)/\$(TMP) clean: @if [ ! -f debian/control ] ; then \\ /bin/echo sorry, you need to be in source package main directory ; \\ exit 1 ; \\ fi @if [ \`/usr/bin/whoami\` != root ] ; then \\ /bin/echo sorry, you need to be root to clean ; \\ exit 1 ; \\ fi @# clean up install run and build, I prefer this before clean upstream @/bin/rm -rf \$(TMP) debian/substvars @/bin/rm -rf debian/files @# unmark this before "uncompiling" @/bin/rm -f build-stamp @# run upstream Makefile @\$(MAKE) clean binary-arch: build install @# We have nothing to do by default, as this package arch independant binary-indep: build install @## replaces dh_testdir @if [ ! -f debian/control ] ; then \\ /bin/echo sorry, you need to be in source package main directory ; \\ exit 1 ; \\ fi @## replaces dh_testroot @if [ \`/usr/bin/whoami\` != root ] ; then \\ /bin/echo sorry, you need to be root to package ; \\ exit 1 ; \\ fi @# where all the documentation (debian and upstream) gets installed @/usr/bin/install -g root -o root -d \$(TMP)/usr/share/doc/${PKG_NAME} @## replaces dh_installdocs @# put automatic /usr/doc links into postinst|prerm here some day @/usr/bin/install -g root -o root -m 644 debian/copyright \\ \$(TMP)/usr/share/doc/${PKG_NAME}/copyright @# provide copies of the usual suspects ... @# a FILE [ in .. ] ; do loop would be better, but failed @if [ -f README ] ; then \\ /usr/bin/install -g root -o root -m 644 README \\ \$(TMP)/usr/share/doc/${PKG_NAME}/README ; \\ fi @if [ -f CHANGES ] ; then \\ /usr/bin/install -g root -o root -m 644 CHANGES \\ \$(TMP)/usr/share/doc/${PKG_NAME}/CHANGES ; \\ fi @if [ -f NEWS ] ; then \\ /usr/bin/install -g root -o root -m 644 NEWS \\ \$(TMP)/usr/share/doc/${PKG_NAME}/NEWS ; \\ fi @if [ -f TODO ] ; then \\ /usr/bin/install -g root -o root -m 644 TODO \\ \$(TMP)/usr/share/doc/${PKG_NAME}/TODO ; \\ fi @if [ -f BUGS ] ; then \\ /usr/bin/install -g root -o root -m 644 BUGS \\ \$(TMP)/usr/share/doc/${PKG_NAME}/BUGS ; \\ fi @## replaces dh_installinit and replaces dh_installcron @# subshell this to prevent user script errors propagating @if [ -f debian/makesourcepackage ] ; then \\ ( TMP=\$(TMP) debian/makesourcepackage ) ; \\ fi @## replaces dh_installchangelogs, always native mode @/usr/bin/install -g root -o root -m 644 debian/changelog \\ \$(TMP)/usr/share/doc/${PKG_NAME}/changelog.Debian @/bin/gzip --best \$(TMP)/usr/share/doc/${PKG_NAME}/changelog.Debian @# where all the debianisation stuff gets installed @/usr/bin/install -g root -o root -d \$(TMP)/DEBIAN @## replaces dh_installdeb @if [ -f debian/preinit ] ; then \\ /usr/bin/install -g root -o root -m 755 debian/preinit \\ \$(TMP)/DEBIAN/preinit ; \\ fi @if [ -f debian/postinst ] ; then \\ /usr/bin/install -g root -o root -m 755 debian/postinst \\ \$(TMP)/DEBIAN/postinst ; \\ fi @if [ -f debian/prerm ] ; then \\ /usr/bin/install -g root -o root -m 755 debian/prerm \\ \$(TMP)/DEBIAN/prerm ; \\ fi @if [ -f debian/postrm ] ; then \\ /usr/bin/install -g root -o root -m 755 debian/postrm \\ \$(TMP)/DEBIAN/postrm ; \\ fi @# put automatic generating of conffiles here some day? @if [ -f debian/conffiles ] ; then \\ /usr/bin/install -g root -o root -m 644 debian/conffiles \\ \$(TMP)/DEBIAN/conffiles ; \\ fi @## replaces dh_gencontrol @/usr/bin/dpkg-gencontrol -isp > \$(TMP)/DEBIAN/control @/bin/chmod \644 \$(TMP)/DEBIAN/control @/bin/chown root.root \$(TMP)/DEBIAN/control @## replaces dh_builddeb @/usr/bin/dpkg --build \$(TMP) .. binary: binary-indep binary-arch .PHONY: build clean binary-indep binary-arch binary install EOF /bin/chmod 755 ${DEB_DIR}/rules if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' rules Makefile made /bin/ls -al ${DEB_DIR}/rules fi fi # modify the rules file from existing package, just new name # leave this unchanged, as we want the old stuff incl user changes in it if [ x${DO_CLONE} != x ] ; then # fix up package name where it appears if [ -f ${DEB_DIR}/rules ] ; then /bin/sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" ${DEB_DIR}/rules \ > ${DEB_DIR}/.rules /bin/mv ${DEB_DIR}/.rules ${DEB_DIR}/rules /bin/chmod 755 ${DEB_DIR}/rules else /bin/echo WARNING: no rules file, something is fishy here fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' rules file modified: /bin/ls -al ${DEB_DIR}/rules fi fi # --- add an dependency if [ "x${DO_DEPEND}" != x ] ; then if [ `/bin/grep -c '^Depends: ' ${DEB_DIR}/control` != 0 ] ; then # extend Depends: line with one or multiple dependencies # sed substitute line end = extend line /bin/sed -e "/^Depends: /s/$/, ${DO_DEPEND}/" ${DEB_DIR}/control \ > ${DEB_DIR}/.control /bin/mv ${DEB_DIR}/.control ${DEB_DIR}/control if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' control Depends: line extended /bin/grep '^Depends: ' ${DEB_DIR}/control fi else # add Depends: line to control file, with one or multiple dependencies # place it before the Description: line (= after the Architecture: line) # not /^Architecture: /a because that adds before earlier options /bin/sed -e "/^Description: /i\\ Depends: ${DO_DEPEND}" ${DEB_DIR}/control > ${DEB_DIR}/.control /bin/mv ${DEB_DIR}/.control ${DEB_DIR}/control if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' control Depends: line added /bin/grep '^Depends: ' ${DEB_DIR}/control fi fi fi # --- add an option line if [ "x${DO_OPTION}" != x ] ; then OPTION=`/bin/echo ${DO_OPTION} | /usr/bin/cut -f 1 -d " "` VALUE=`/bin/echo ${DO_OPTION} | /usr/bin/cut -f 2- -d " " ` if [ `/bin/grep -c "^${OPTION} " ${DEB_DIR}/control` != 0 ] ; then # extend any option line with an element /bin/sed -e "/^${OPTION} /s/$/, ${VALUE}/" ${DEB_DIR}/control \ > ${DEB_DIR}/.control /bin/mv ${DEB_DIR}/.control ${DEB_DIR}/control if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' control option line extended /bin/grep "^${OPTION} " ${DEB_DIR}/control fi else # add any option line to control file, with one element # place it before the Description: line (= after the Architecture: line) # not /^Architecture: /a because that adds before earlier options /bin/sed -e "/^Description: /i\\ ${DO_OPTION}" ${DEB_DIR}/control > ${DEB_DIR}/.control /bin/mv ${DEB_DIR}/.control ${DEB_DIR}/control if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' control option line added /bin/grep "^${OPTION} " ${DEB_DIR}/control fi fi fi # --- make the changelog (later changelog.Debian) for this package and level # delay this until just before actual packaging, after users modifications # so that packaging date (not generation date) is used for version number if [ "x${DO_CLOG}" != x ] ; then if [ -f ${DEB_DIR}/changelog ] ; then # save existing changelog /bin/mv ${DEB_DIR}/changelog ${DEB_DIR}/changelog.old fi # compute package version, for this packaging run # use current date.time as automatically generated major.minor version DATE_VERSION=`/bin/date +%Y%m%d.%H%M%S` # there is usually only one level, as starting from 1 per version # can be changed with -l, patch for making multiple releases in one day PKG_VERSION=${DATE_VERSION}-${SYS_PKG_LEVEL} # when packaging, debianise this version with RFC date from now DATE_RFC=`/bin/date -R` /bin/cat << EOF > ${DEB_DIR}/changelog ${PKG_NAME} (${PKG_VERSION}) stable; urgency=low * ${DO_CLOG} -- ${CONF_PRG_AND_MAIL} ${DATE_RFC} EOF if [ -f ${DEB_DIR}/changelog.old ] ; then # tag existing changelog on to new entry /bin/echo >> ${DEB_DIR}/changelog /bin/cat ${DEB_DIR}/changelog.old >> ${DEB_DIR}/changelog fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' Debian changelog generated/extended /bin/ls -al ${DEB_DIR}/changelog fi fi # --- build the package files and check it for errors if [ x${DO_PACK} = xyes ] ; then if [ ! -s ${DEB_DIR}/changelog ] ; then # user hat not produced even one changelog entry, we have no version number /bin/echo $0: FATAL ERROR: no changelog entry, no version num, aborting >&2 exit 1 fi # save and eliminate CVS stuff, if we have any SAVE_TAR=.tmp-makepackage-$$-save.tar if [ -f ${SAVE_TAR} ] ; then /bin/rm ${SAVE_TAR} fi if [ -d ${PKG_DIR}/CVS ] ; then /bin/tar cf ${SAVE_TAR} ${PKG_DIR} /usr/bin/find ${PKG_DIR} -name CVS -exec /bin/rm -rf {} \; 2> /dev/null fi # then build the actual package stuff if [ -d ~/.gnupg -o -d ~/.pgp ] ; then ( cd ${PKG_NAME} ; /usr/bin/dpkg-buildpackage -rfakeroot ) else ( cd ${PKG_NAME} ; /usr/bin/dpkg-buildpackage -rfakeroot -uc -us ) fi # and tidy up compiling leftovers if [ x${DEBUG_LEAVE_TEMPFILES} != xyes ] ; then ( cd ${PKG_NAME} ; /usr/bin/fakeroot debian/rules clean ) fi # restore CVS stuff, if we had any if [ -f ${SAVE_TAR} ] ; then /bin/tar xpf ${SAVE_TAR} /bin/rm ${SAVE_TAR} fi # run a test over package, to get more error messages /usr/bin/lintian -i ${PKG_NAME}_*.changes # and get rid of superfluous .changes file if [ x${CONF_REMOVE_CHANGES_FILE} = xyes ] ; then /bin/rm ${PKG_NAME}_*.changes fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then # find newest version of this package to inform on PKG_GENNAMES=`/bin/ls -1d ${PKG_NAME}_*` /bin/echo '###' package files generated are: /bin/ls -al ${PKG_GENNAMES} fi fi # --- delete temporary work directory if [ x${DO_TIDY} = xyes ] ; then /bin/rm -rf ${PKG_DIR} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' work directory deleted for: ${PKG_DIR} fi fi # --- upload finished packages to local Debian mirror if [ x${DO_UPLOAD} = xyes ] ; then # this stuff is all site dependant, required NFS access to package server # find newest version of this package to upload PKG_TARNAME=`/bin/ls -1d ${PKG_NAME}_*.tar.gz | /usr/bin/tail -1` PKG_DSCNAME=`/bin/ls -1d ${PKG_NAME}_*.dsc | /usr/bin/tail -1` PKG_DEBNAME=`/bin/ls -1d ${PKG_NAME}_*.deb | /usr/bin/tail -1` if [ x${CONF_REMOVE_CHANGES_FILE} != xyes ] ; then PKG_CHGNAME=`/bin/ls -1d ${PKG_NAME}_*.changes | /usr/bin/tail -1` fi # don't use ${SYS_SECTION} or ${SYS_ARCH} here anymore # after -g -s and later just with -p -u they are unset / wrong (default) UPLOAD_SECT=`/usr/bin/dpkg -f ${PKG_DEBNAME} Section` UPLOAD_ARCH=`/usr/bin/dpkg -f ${PKG_DEBNAME} Architecture` # split section desciptor into main and sub sections if [ x`/bin/echo ${UPLOAD_SECT} | /bin/grep '/'` != x ] ; then UPLOAD_MAINSECT=`/bin/echo ${UPLOAD_SECT} | /usr/bin/cut -f 1 -d '/'` UPLOAD_SUBSECT=`/bin/echo ${UPLOAD_SECT} | /usr/bin/cut -f 2 -d '/'` else UPLOAD_MAINSECT=main UPLOAD_SUBSECT=${UPLOAD_SECT} fi # upload them via NFS to our server structure, no FTP or HTTP support # build our basic paths for this storing this package UPLOAD_BASE=${CONF_UPLOAD_BASE}/${UPLOAD_MAINSECT} UPLOAD_SOURCE_SECT=${UPLOAD_BASE}/source/${UPLOAD_SUBSECT} UPLOAD_BINARY_SECT=${UPLOAD_BASE}/binary-${UPLOAD_ARCH}/${UPLOAD_SUBSECT} # upload sources, incl ensure directory exists, and removing old version if [ ! -d ${UPLOAD_SOURCE_SECT} ] ; then /bin/mkdir -p ${UPLOAD_SOURCE_SECT} fi if [ `/bin/ls -1 ${UPLOAD_SOURCE_SECT}/${PKG_NAME}_* 2> /dev/null | \ /usr/bin/wc -l` != 0 ] ; then /bin/rm ${UPLOAD_SOURCE_SECT}/${PKG_NAME}_* fi /bin/cp -p ${PKG_TARNAME} ${PKG_DSCNAME} ${PKG_CHGNAME} ${UPLOAD_SOURCE_SECT} # upload binary, incl ensure directory exists, and removing old version if [ ! -d ${UPLOAD_BINARY_SECT} ] ; then /bin/mkdir -p ${UPLOAD_BINARY_SECT} fi if [ `/bin/ls -1 ${UPLOAD_BINARY_SECT}/${PKG_NAME}_* 2> /dev/null | \ /usr/bin/wc -l` != 0 ] ; then /bin/rm ${UPLOAD_BINARY_SECT}/${PKG_NAME}_* fi /bin/cp -p ${PKG_DEBNAME} ${UPLOAD_BINARY_SECT} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' package files uploaded for: ${PKG_TARNAME} ${PKG_DSCNAME} \ ${PKG_CHGNAME} ${PKG_DEBNAME} to: ${UPLOAD_MAINSECT} / ${UPLOAD_SUBSECT} /bin/ls -al ${UPLOAD_SOURCE_SECT}/${PKG_NAME}_* /bin/ls -al ${UPLOAD_BINARY_SECT}/${PKG_NAME}_* fi # this part is hopelessly site dependant, requires Makefile to update site # only do it if directory ${CONF...} set and we have an Makefile in there if [ x${CONF_UPLOAD_UPDATER} != x -a \ -f ${CONF_UPLOAD_UPDATER}/Makefile ] ; then ( cd ${CONF_UPLOAD_UPDATER}; /usr/bin/make ${UPLOAD_MAINSECT} ) if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' updated local package lists for: ${UPLOAD_MAINSECT} fi fi fi # --- remove all generated files of an package # these are ${PKG_NAME}_*.dsc *.tar.gz *.deb and possibly *.changes # do this before -p in case someone is using -rp to clean and then pack newly if [ x${DO_REMOVE} != x ] ; then # find all versions of this package PKG_GENNAMES=`/bin/ls -1d ${PKG_NAME}_*` # and remove them /bin/rm ${PKG_GENNAMES} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' removed package files are: ${PKG_GENNAMES} fi fi # --- information on package if [ x${DO_INFO} = xyes ] ; then # find newest version of this package to inform on PKG_DEBNAME=`/bin/ls -1d ${PKG_NAME}_*.deb | /usr/bin/tail -1` # print out packages info /usr/bin/dpkg-deb --info ${PKG_DEBNAME} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' information given for: ${PKG_DEBNAME} fi fi # that's all folks!