#!/bin/sh # http://www.phys.ethz.ch/~franklin/Projects/dphys-pkgtools/makesourcepackage # = /usr/bin/makesourcepackage # - generate directory structure and content and operate for making packages # - second version which generates source packages, not just binaries # author Neil Franklin, last modification 2004.07.29 # copyright ETH Zuerich Physics Departement, # use under either BSD or GPL license # this script is intended to be run as an normal user ### ------ configuration for this site # 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 # set our default architecture # this is used by -g (generate), and overridable with -a (architecture) # our packages usually contain config files and scripts, no binary stuff CONF_ARCH=all # set our default section # this is used by -g (generate), and overridable with -s (section) # our packages usually contain config files and scripts for administration CONF_SECTION=admin # this is prepended to packagenames with no - in the name # this can be used to add an - to every package name generated # this feature is deactivated by setting this to an empty string CONF_HOST_TO_PKG_PREFIX="" # this is used for all author remarks in file headers CONF_PRG="makesourcepackage script" # this is used for debian/control Maintainer: and the debian/changelog CONF_PRG_AND_MAIL="make source package script " # this is used for all copyright remarks in file headers # the second line (with "#") is the second line of the string # needs to be done so (no \) for multi-line text in an variable CONF_COPY="released into the Public Domain, no license restrictions use it for what you want to, share and enjoy" # automatically remove *.changes file, only needed for official Debian uploads # our policy is that we do not use them here, so delete them CONF_REMOVE_CHANGES_FILE=yes # from here on only CONF_* for makesourcepackage -u # server where we put out packages # makesourcepackage -u uploads to this CONF_PKG_SERVER=not-configured-server # user as which we login to above server # makesourcepackage -u uploads with this CONF_USER=not-configured-user # make sure multiple users (group of them) can install files on package server # if this is set, chgrp directories and files to this group and chmod g+w CONF_GROUP= # base directory on server where we put out packages file tree # this is the base directory for adding dists/woody/local/
/*/*/*.deb # paralleling Debians use dists/woody/main/
/*/* on their servers # and so should appear in the http:// space of the server # makesourcepackage -u uploads everything relative to this # and entire makelocalsite process runs relative to this CONF_PKG_BASE=/not/configured/debian-local # (re-)index local packages server using makelocalsite after upload # this program will be run cd ${CONF_PKG_BASE} with section as parameter # set this to empty variable to prevent package list update being run CONF_INDEX_SITE=/usr/bin/makelocalsite # --- DEBUG_*, various debugging settings # set this to output debug state info after each step, see also -v option #DEBUG_PRINT_STEP=yes # set this to not delete temporary files (.../debian/tmp), see also -n option #DEBUG_LEAVE_TEMPFILES=yes # set this to leave temporary directories undeleted, after -u #DEBUG_LEAVE_TEMPDIRS=yes # --- SYS_*, various system internal values # this is used for the debian/control Description: # edit this by the user, after -g, to what this package is actually used for SYS_DESC_SH="Package generated by ${CONF_PRG}" # we offer 3 lines, blank at front gets added automatically SYS_DESC_1="This package does not yet know what it does." SYS_DESC_2="The user of ${CONF_PRG} should really edit debian/control." # set out default debianisation level # as we we once use(d) 8 digit date for version numbers # this could then be used if multiple versions in one day # today we use 8.6 digit date.time, so this is irrelevant now SYS_PKG_LEVEL=1 # path for packages we put on our server # this is set the same in makelocalsite SYS_OWNPACKAGES=dists/woody/local # --- config file stuff # what we are # same config files used in makelocalsite NAME=dphys-pkgtools # check user config file(s), let user override settings CONFFILE=/etc/${NAME} DCONFFILE=/etc/default/${NAME} UCONFFILE=${HOME}/.${NAME} if [ -e ${CONFFILE} ] ; then . ${CONFFILE} fi if [ -e ${DCONFFILE} ] ; then . ${DCONFFILE} fi if [ -e ${UCONFFILE} ] ; then . ${UCONFFILE} fi ### ------ 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" CONF_ARCH=$1 shift 1 ;; s) # section: user wants to set custom section type, not "(main/) admin" CONF_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 ;; b) # base: upload generated package files to base directory CONF_PKG_BASE=$1 shift 1 ;; 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: ${CONF_ARCH} examples: all, any, i386 -s section section: set section to this; default: ${CONF_SECTION} examples: admin, misc, non-free/admin, contrib/misc [for cloning] -c oldpackage clone/copy: clone contents from instead of making new files do: * Makefile and README copied and package name in them changed * control and copyright copied and package name in it changed * rules file copied 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, as that no 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, they all get added up -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 there is one use this for Predepends:, Conflicts:, Provides:, Recommends: [for packaging] -l logtext log: generate new changelog entry and (dated) version number using the given log text for the * line -p pack: pack up the work directory, making package files -n nodelete: do not delete temp files (.../debian/temp/*) -t tidyup: delete work dir after packaging, leave only package [for uploading] -u upload: upload generated package files to local Debian mirror and run indexing command there, this is a bit site dependant -b baseaddr base: upload generated package files to this base directory -r remove: delete 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 (debug information) -h help: output this text, and then abort operation If (-g or -c or -x or -f) followed by multiple of -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 modify behaviour. packagename: something like my- - (here dphys-) EOF exit 0 ;; *) # not one of our recognized options /bin/echo "$0: ERROR: 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: ERROR: 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 -host- 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 -host- 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 any of the "if"s 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 # clone existing package /bin/echo cloning ${DO_CLONE} ... # do we find an work directory (must be same or newer than a package) if [ -d ${DO_CLONE}/debian ] ; then # copy to be cloned 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 of newer directory, use archive # find newest version of this package to clone CLONE_TARNAME=`/bin/ls -1 ${DO_CLONE}_*.tar.gz 2> /dev/null | \ /usr/bin/tail -1` if [ x${CLONE_TARNAME} != x ] ; then # unpack to be cloned 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} else /bin/echo "$0: ERROR: no package ${DO_CLONE} to clone" >&2 exit 1 fi 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 # expand existing package /bin/echo expanding ${PKG_NAME} ... # 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 -1 ${PKG_NAME}_*.tar.gz 2> /dev/null | /usr/bin/tail -1` if [ x${PKG_TARNAME} != x ] ; then # unpack packages source files into new work directory /bin/tar zxpf ${PKG_TARNAME} else /bin/echo "$0: ERROR: no package ${PKG_NAME} to expand" >&2 exit 1 fi 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 # fetch existing package /bin/echo fetching ${PKG_NAME} ... # 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}-* 2> /dev/null | /usr/bin/tail -1` if [ x${PKG_APTGET_DIR} != x ] ; then /bin/mv ${PKG_APTGET_DIR} ${PKG_DIR} else /bin/echo "$0: ERROR: no package ${PKG_NAME} to fetch" >&2 exit 1 fi 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 # current date for "last modufication" for generated files DATE_STAMP=`/bin/date +%Y.%m.%d` # --- "upstream" package # generate the "upstream" package, mainly an dummy Makefile, for extending if [ x${DO_GEN} = xyes ] ; then # generate new package /bin/echo generating ${PKG_NAME} ... # user may be debianising an existing program directory, don't overwrite 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 BINDIR = \$(PREFIX)/bin SBINDIR = \$(PREFIX)/sbin MAN1DIR = \$(PREFIX)/share/man/man1 MAN8DIR = \$(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 # user may be debianising an existing program directory, don't overwrite 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 rest unchanged, as we want the old stuff incl user changes to 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: ${CONF_SECTION} Priority: optional Maintainer: ${CONF_PRG_AND_MAIL} Build-Depends-Indep: debhelper (>> 3.0.0) Standards-Version: 3.5.2 Package: ${PKG_NAME} Architecture: ${CONF_ARCH} Description: ${SYS_DESC_SH} ${SYS_DESC_1} ${SYS_DESC_2} 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 rest unchanged, as we want the old stuff incl user changes to 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 rest unchanged, as we want the old stuff incl user changes to it 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 # don't generate any postinst/prerm stuff, debian/rules does this # this code is obsolete, only for cloning old packages which had no dh_* # modify any post* and pre* files from existing package, just new name # just change name in all files, important for any doc links, if any # leave rest unchanged, as we want the old stuff incl user changes to it 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 # lots of \ or even \\ quoting in this section, so stuff survives into Makefile # sh written Makefile runs shell with variables + multilined + backticks, grr /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} # derived from Debian New Maintainers Guide example by Joey Hess # dropping unused functions, and coding instead of deleting dh_* stuff calls `/bin/sed -e 's/^\([^#].*\)/# \1/' << EOF2 # This rules file is ${CONF_COPY} EOF2` # This is the debhelper compatibility version to use. export DH_COMPAT=3 # copied, in case something used these ifneq (,\$(findstring debug,\$(DEB_BUILD_OPTIONS))) CFLAGS += -g endif ifeq (,\$(findstring nostrip,\$(DEB_BUILD_OPTIONS))) INSTALL_PROGRAM += -s endif build: build-stamp build-stamp: @/usr/bin/dh_testdir @# compiling can be done as non-root, no test here @# run upstream Makefile @\$(MAKE) @# mark this after compiling @/bin/touch build-stamp clean: @/usr/bin/dh_testdir @/usr/bin/dh_testroot @# clean up install run and build, I prefer this before clean upstream @/usr/bin/dh_clean @# unmark "compile done" flag before "uncompiling" @/bin/rm -f build-stamp @# run upstream Makefile @\$(MAKE) clean install: build @/usr/bin/dh_testdir @/usr/bin/dh_testroot @# clean up debris from previous install runs, leave Debian files @/usr/bin/dh_clean -k @# create our debian/ directory @/usr/bin/dh_installdirs @# run upstream Makefile @\$(MAKE) install DESTDIR=\$(CURDIR)/debian/${PKG_NAME} binary-arch: build install @# We have nothing to do here, packages assumed to be arch independant binary-indep: build install @/usr/bin/dh_testdir @/usr/bin/dh_testroot @# no dh_installdebconf @# where all the documentation (debian and upstream) gets installed @# installs debian/copyright, debian/README.[Dd]ebian, debian/TODO @# and any file listed in debian/${PKG_NAME}.docs @# also generates the /usr/doc -> /usr/share/doc symlinks (un)makers @/usr/bin/dh_installdocs @# no dh_installexamples or dh_installmenu @# no dh_installlogrotate or dh_installemacsen @# no dh_installpam or dh_installmime @# set up init script links, possibly user specified run level @# for this use an line in init script such as: #@rc.d@ start 37 S . @# installs debian/.init and debian/.default @# and yes, Debian kills the links only long after the script is gone @# gives temp "dangling link", is broken, but they want it this way @if [ -f debian/${PKG_NAME}.init ] ; then \\ PARAMS="defaults" ; \\ LINE=\`grep '^#@rc.d@ ' debian/${PKG_NAME}.init\` ; \\ if [ x\`echo \$\${LINE} | cut -f 1 -d " "\` != x ] ; then \\ PARAMS=\`echo \$\${LINE} | cut -f 2- -d " "\` ; \\ fi ; \\ dh_installinit -- \$\${PARAMS} ; \\ fi @if [ -f \`ls -1 debian/${PKG_NAME}.cron.* 2> /dev/null | \\ head -1\` ] ; then \\ dh_installcron ; \\ fi @# no dh_installman or dh_installinfo or dh_undocumented @# if man or info pages wanted, use Makefile install as for program @# install changelogs, upstream+debian or just native debian @if [ -f changelog ] ; then \\ dh_installchangelogs changelog ; \\ elif [ -f CHANGES ] ; then \\ dh_installchangelogs CHANGES ; \\ else \\ dh_installchangelogs ; \\ fi @# dh_link or dh_strip @dh_compress @dh_fixperms @# no dh_makeshlibs @# this does all debian/pre* and post*, and also generates conffiles @dh_installdeb @# no dh_perl or dh_shlibdeps @dh_gencontrol @dh_md5sums @dh_builddeb 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 rest unchanged, as we want the old stuff incl user changes to 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 # add dependency /bin/echo adding dependency ${DO_DEPEND} ... 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 # add option /bin/echo adding option ${DO_OPTION} ... 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 # add changelog entry /bin/echo adding changelog entry ${DO_CLOG} ... 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 # build package /bin/echo building package ${PKG_NAME} ... if [ ! -s ${DEB_DIR}/changelog ] ; then # user hat not produced even one changelog entry, we have no version number /bin/echo $0: ERROR: no changelog entry, no version num, aborting >&2 exit 1 fi # save and eliminate CVS stuff, if we have any SAVE_TAR=./.tmp-makesourcepackage-$$-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}_* 2> /dev/null` /bin/echo '###' package files generated are: /bin/ls -al ${PKG_GENNAMES} fi fi # --- delete temporary work directory if [ x${DO_TIDY} = xyes ] ; then # tidy up work directory /bin/echo tidying up work directory ${PKG_NAME} ... /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 # upload to local package server /bin/echo uploading ${PKG_NAME} ... # find newest version of this package to upload PKG_TARNAME=`/bin/ls -1 ${PKG_NAME}_*.tar.gz 2> /dev/null | \ /usr/bin/tail -1` PKG_DIFFNAME=`/bin/ls -1 ${PKG_NAME}_*.diff.gz 2> /dev/null | \ /usr/bin/tail -1` PKG_DSCNAME=`/bin/ls -1 ${PKG_NAME}_*.dsc 2> /dev/null | \ /usr/bin/tail -1` PKG_CHGNAME=`/bin/ls -1 ${PKG_NAME}_*.changes 2> /dev/null | \ /usr/bin/tail -1` PKG_DEBNAME=`/bin/ls -1 ${PKG_NAME}_*.deb 2> /dev/null | \ /usr/bin/tail -1` if [ x${PKG_DEBNAME} = x ] ; then /bin/echo "$0: ERROR: no package ${PKG_NAME} to upload" >&2 exit 1 fi # don't use ${CONF_SECTION} or ${CONF_ARCH} here anymore # they are only valid when set by with -g and then -a and/or -s # on later calls with just -p -u they are unset/default/wrong # so then extract the settings at -g time from the package SECTION=`/usr/bin/dpkg -f ${PKG_DEBNAME} Section` ARCH=`/usr/bin/dpkg -f ${PKG_DEBNAME} Architecture` # split section descriptor into part 1 (main) and part 2 (sub) sections if [ x`/bin/echo ${SECTION} | /bin/grep '/'` != x ] ; then SUBSECT=`/bin/echo ${SECTION} | /usr/bin/cut -f 2 -d '/'` SECTION=`/bin/echo ${SECTION} | /usr/bin/cut -f 1 -d '/'` else # nothing to split, so it must be main as part 1 SUBSECT=${SECTION} SECTION=main fi # upload them to our local packages server # build our ssh/scp paths for this storing this package SOURCE=${SYS_OWNPACKAGES}/${SECTION}/source/${SUBSECT} B_ARCH=${SYS_OWNPACKAGES}/${SECTION}/binary-${ARCH}/${SUBSECT} # put together stuff to upload, needs an temp dir # not ./upload as this may collide with something user already has TO_UPLOAD=./.tmp-makesourcepackage-$$-upload /bin/mkdir -p ${TO_UPLOAD}/${SOURCE} /bin/mkdir -p ${TO_UPLOAD}/${B_ARCH} if [ x${GROUP} != x ] ; then /bin/chgrp -R ${CONF_GROUP} ${TO_UPLOAD} /bin/chmod -R 2775 ${TO_UPLOAD} fi /bin/cp -p ${PKG_TARNAME} ${PKG_DIFFNAME} ${PKG_DSCNAME} ${PKG_CHGNAME} \ ${TO_UPLOAD}/${SOURCE} /bin/cp -p ${PKG_DEBNAME} ${TO_UPLOAD}/${B_ARCH} if [ x${GROUP} != x ] ; then /bin/chgrp ${CONF_GROUP} ${TO_UPLOAD}/${SOURCE}/* ${TO_UPLOAD}/${B_ARCH}/* /bin/chmod 664 ${TO_UPLOAD}/${SOURCE}/* ${TO_UPLOAD}/${B_ARCH}/* fi # include directory tree, duplicating tree to server, in case server has none # may be none if new package is in an previously unused section # this is a bit site dependant, you need ssh on your local package server # 2> needed to get wird of error message, because can not change dir modes # this loses us the progress bar, because scp tests also 2> for tty or not /usr/bin/scp -pr ${TO_UPLOAD}/* \ ${CONF_USER}@${CONF_PKG_SERVER}:${CONF_PKG_BASE} 2> /dev/null if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' uploaded local package files: /bin/ls -alR ${TO_UPLOAD}/* fi # remove temporary directory and its contents # must be after debug printout if [ x${DEBUG_LEAVE_TEMPDIRS} != xyes ] ; then # but offer to leave this to investigate bugs /bin/rm -rf ${TO_UPLOAD} fi # index local package server /bin/echo indexing local server ... # run an local package server index update command # this is even more site dependant, you need ssh and makelocalsite if [ x${CONF_INDEX_SITE} != x ] ; then ssh ${CONF_USER}@${CONF_PKG_SERVER} \ "cd ${CONF_PKG_BASE}; ${CONF_INDEX_SITE} ${SECTION}" if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' updated local server indexes for: ${SECTION} 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 # remove package files /bin/echo removing ${PKG_NAME} ... # find all versions of this package PKG_GENNAMES=`/bin/ls -1d ${PKG_NAME}_* 2> /dev/null` if [ x${PKG_GENNAMES} != x ] ; then # and remove them /bin/rm ${PKG_GENNAMES} else /bin/echo "$0: ERROR: no package ${PKG_NAME} to remove" >&2 exit 1 fi 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 # output information /bin/echo informing on ${PKG_NAME} ... # find newest version of this package to inform on PKG_DEBNAME=`/bin/ls -1 ${PKG_NAME}_*.deb 2> /dev/null | /usr/bin/tail -1` if [ x${PKG_DEBNAME} != x ] ; then # print out packages info /usr/bin/dpkg-deb --info ${PKG_DEBNAME} else /bin/echo "$0: ERROR: no package ${PKG_NAME} to get info on" >&2 exit 1 fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' information given for: ${PKG_DEBNAME} fi fi # that's all folks!