#!/bin/sh # /usr/bin/makesourcepackage - make debian packages from source # - generate directory structure and content and operate for making packages # - second version which generates source packages, not just binaries # author Neil Franklin, last modification 2006.12.01 # copyright ETH Zuerich Physics Departement, # use under either modified/non-advertising BSD or GPL license # this script is intended to be run as an normal user ### ------ configuration for this site # first CONF_* various site or user 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_AUTHOR="makesourcepackage script" # this is used for debian/control Maintainer: and debian/changelog remarks CONF_MAINT_NAME="Not Configured Full Name" CONF_MAINT_EMAIL="not-configured-user@not-configured-site" # 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 -u and -i options # server where we put our packages # makesourcepackage -u uploads to this CONF_PKG_SERVER="not-configured-server" # user as which we login to above server # makesourcepackage -u uploads as 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 our packages file tree # this is base directory for adding dists//local/
/*/*/*.deb # paralleling Debians dists//
/*/*/*.deb on their servers # and so should appear in the http:// DocumentRoot space of your server # makesourcepackage -u uploads everything relative to this # and entire makelocalsite process runs relative to this CONF_PKG_BASE="/not/configured/directory" # distribution directory within our package server # we have added /local subdirectory analog to /non-US or /updates CONF_DISTRIB="sarge/local" # (re-)index local packages server using makelocalsite after upload # makesourcepackage -i runs this on server # 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_INDEXER="/usr/bin/makelocalsite" # --- DEBUG_*, various debugging settings # these can be set to "yes" by -D option, followed by name without DEBUG_ # such as like this: makesourcepackage -D PRINT_STEP -D LEAVE_TEMPFILES ... # set this to sleep after displaying each steps header #DEBUG_SLEEP=yes # set this to output debug state info after each step #DEBUG_PRINT_STEP=yes # set this to wait after each debug state info #DEBUG_WAIT_STEP=yes # set this to not delete temporary files (.../debian/tmp) after -g #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_AUTHOR}" # 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_AUTHOR} 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 # for disabling the anti root upload lossage test, if this is really wanted SYS_ALLOW_ROOT_UPLOAD_LOSSAGE=no # where we want to put together stuff for upload # not ./upload as this may collide with something user already has SYS_UPLOADDIR=/var/tmp/makesourcepackage-$$-upload # for saving and restoring CVS stuff, which we must delete before packaging SYS_SAVE_TAR=/var/tmp/makesourcepackage-$$-save.tar ### ------ actual implementation from here on # no user settings any more below this point set -e # --- get ready to work # sanitise this place, else some commands may fail # must be before any commands are executed, incl config/input processing PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH # --- tidy up some commands, make systematic # stuff that goes wrong, not expected by user, not in data output, use >&2 # so also with $0 in case this script was called by an other script # something within the system that user does not expect, give up CMD_FATAL="echo $0: FATAL:" # something from users input, user will correct this and continue CMD_ERROR="echo $0: ERROR:" # something we can continue with, but may be wrong, and user may not suspect it CMD_WARNING="echo $0: WARNING:" # something most likely not wrong, but tell user for the odd case it is wrong CMD_NOTE="echo $0: NOTE:" # normal stuff users expect, so to stdout as normal output, no $0, no marking CMD_INFO="echo" # stuff users asked for, so add to stdout as normal output, no $0, but mark it CMD_DEBUG="echo DEBUG:" # other stuff we may want to use CMD_SLEEP="sleep 2" CMD_WAIT="read -p ---DEBUG-wait-after-step--- dummy" # DEBUG_* or option controllable stuff CMD_INFO_PRINT="${CMD_INFO}" CMD_VERBOSE_PRINT=true CMD_DEBUG_SLEEP=true CMD_DEBUG_PRINT=true CMD_DEBUG_WAIT=true # set debug option controllable stuff here if [ "${DEBUG_SLEEP}" = yes ] ; then CMD_DEBUG_SLEEP="${CMD_SLEEP}" fi if [ "${DEBUG_PRINT_STEP}" = yes ] ; then CMD_DEBUG_PRINT="${CMD_DEBUG}" fi if [ "${DEBUG_WAIT_STEP}" = yes ] ; then CMD_DEBUG_WAIT="${CMD_WAIT}" fi # --- config file stuff # what we are, program and package name NAME=makesourcepackage PNAME=dphys-pkgtools # check user config file(s), let user override settings # same config files used in makelocalsite if [ -e /etc/"${PNAME}" ] ; then . /etc/"${PNAME}" fi if [ -e ~/."${PNAME}" ] ; then . ~/."${PNAME}" fi if [ -f ./"${PNAME}" ] ; then . ./"${PNAME}" fi # --- parse command line # so long next parameter is a set of options (= begins with an - character) while [ "`echo "$1" | cut -c 1`" = - ] ; do # extract options from parameter (cut off the "-") OPTS="`echo "$1" | cut -c 2-`" shift 1 # so long still unprocessed option characters while [ "${OPTS}" != "" ] ; do # first option to process OPT="`echo "${OPTS}" | cut -c 1`" # and rest of options for later OPTS="`echo "${OPTS}" | cut -c 2-`" case "${OPT}" in g) # generate: generate new package from scratch DO_GEN=yes COMMAND_OPTION=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 COMMAND_OPTION=yes ;; 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 COMMAND_OPTION=yes ;; f) # fetch: fetch existing package back from local Debian mirror DO_FETCH=yes COMMAND_OPTION=yes ;; l) # log: generate an new changelog entry with version number DO_CLOG="$1" shift 1 COMMAND_OPTION=yes ;; p) # package: take work directory, and package it DO_PACK=yes COMMAND_OPTION=yes ;; t) # tidy: delete work directory, leaves only package file DO_TIDY=yes COMMAND_OPTION=yes ;; u) # upload: upload generated package files to local Debian server DO_UPLOAD=yes COMMAND_OPTION=yes ;; b) # base: upload generated package files to this base directory CONF_PKG_BASE="$1" INDEXER_OPT="${INDEXER_OPT} -b $1" shift 1 ;; d) # distrib: upload generated package files to this distribution CONF_DISTRIB="$1" INDEXER_OPT="${INDEXER_OPT} -d $1" shift 1 ;; i) # index: (re-)index package files on local Debian server DO_INDEX=yes COMMAND_OPTION=yes ;; r) # remove: remove work package files, after uploading DO_REMOVE=yes COMMAND_OPTION=yes ;; q) # quiet: don't inform user what we are doing CMD_INFO_PRINT=true INDEXER_OPT="${INDEXER_OPT} -q" ;; v) # verbose: detailed inform user what we are doing CMD_VERBOSE_PRINT="${CMD_INFO}" ;; D) # Debug: set an debug option to yes eval "DEBUG_$1"=yes INDEXER_OPT="${INDEXER_OPT} -D $1" if [ "DEBUG_$1" = DEBUG_SLEEP ] ; then CMD_DEBUG_SLEEP="${CMD_SLEEP}" fi if [ "DEBUG_$1" = DEBUG_PRINT_STEP ] ; then CMD_DEBUG_PRINT="${CMD_DEBUG}" fi if [ "DEBUG_$1" = DEBUG_WAIT_STEP ] ; then CMD_DEBUG_WAIT="${CMD_WAIT}" fi shift 1 ;; h) # help: give out help how this script can be used cat << END-HELP-TEXT Usage is: $0 command [option]... [command [option]... ]... packagename command/function/action letters: one or multiple of the following commands must be used, default nothing done if multiple of these are used, they are processed in the row they appear here, not the row they are typed on the command line only one of -g -c -x -f should be used per run, else clobber each other -g -c only once per package, only before anything else, else data lost -g generate: generate work directories and their content -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 -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 -f fetch: fetch the .tar.gz and .dsc from local Debian mirror and expand it to an working directory -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 -t tidyup: delete work dir after packaging, leave only package this can be reversed by -x or -f -u upload: upload generated package files to local Debian server (this requires ssh and rsync on the server) -i index: (re-)index the Debian server, is a bit site dependant (this requires ssh and makelocalsite on the server) -r remove: delete package files after upload options: [only for -g generate] -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 [only for -u upload and -i index] -b baseaddr base: upload generated package files to this base directory -d distrib distrib: upload generated package files to this distribution [for all commands] -q quiet: don't give user an running report of what we are doing -v verbose: give user detailed running report -D Debug: activate an debug option, see source for operation -h help: output this text, and then abort operation packagename: name of the package to be handled END-HELP-TEXT exit 0 ;; *) # not one of our recognized options ${CMD_ERROR} "unknown option: ${OPT}" >&2 ${CMD_INFO} >&2 # call self with -h to display help "$0" -h >&2 exit 1 ;; esac done done if [ "${COMMAND_OPTION}" = "" ] ; then ${CMD_ERROR} "no command option selected, will not do anything" >&2 ${CMD_INFO} >&2 # call self with -h to display help "$0" -h >&2 exit 1 fi if [ "$#" != 1 ] ; then # user did not give an parameter (package name), or gave multiple ${CMD_ERROR} "missing package name to work on, or multiple given" >&2 ${CMD_INFO} >&2 # call self with -h to display help "$0" -h >&2 exit 1 fi PARAM="$1" ${CMD_DEBUG_PRINT} "options are:" \ "DO_GEN: ${DO_GEN}, DO_CLONE: ${DO_CLONE}," \ "DO_EXPAND: ${DO_EXPAND}, DO_FETCH: ${DO_FETCH}," \ "DO_CLOG: ${DO_CLOG}, DO_PACK: ${DO_PACK}," \ "DO_TIDY: ${DO_TIDY}, DO_UPLOAD: ${DO_UPLOAD}," \ "DO_INDEX: ${DO_INDEX}, DO_REMOVE: ${DO_REMOVE}, PARAM: ${PARAM}" ${CMD_DEBUG_WAIT} # --- sanitize name parameters from possible tab completion junk # remove possible trailing / on directory name if [ "`echo "${PARAM}" | rev | cut -c 1`" = "/" ] ; then PARAM="`echo "${PARAM}" | rev | cut -c 2- | rev`" fi if [ "${DO_CLONE}" != "" ] ; then if [ "`echo "${DO_CLONE}" | rev | cut -c 1`" = "/" ] ; then DO_CLONE="`echo "${DO_CLONE}" | rev | cut -c 2- | rev`" fi fi # remove possible .gz or .bz2 stuff from tar filenames for ENDING in gz bz2 ; do if [ "`echo "${PARAM}" | rev | cut -f 1 -d '.' | rev`" = "${ENDING}" ] ; then PARAM="`echo "${PARAM}" | rev | cut -f 2- -d '.' | rev`" fi if [ "${DO_CLONE}" != "" ] ; then if [ "`echo "${DO_CLONE}" | rev | cut -f 1 -d '.' | rev`" = \ "${ENDING}" ] ; then DO_CLONE="`echo "${DO_CLONE}" | rev | cut -f 2- -d '.' | rev`" fi fi done # remove possible .tar or .deb stuff from package filenames for ENDING in tar deb ; do if [ "`echo "${PARAM}" | rev | cut -f 1 -d '.' | rev`" = "${ENDING}" ] ; then PARAM="`echo "${PARAM}" | rev | cut -f 2- -d '.' | rev`" fi if [ "${DO_CLONE}" != "" ] ; then if [ "`echo "${DO_CLONE}" | rev | cut -f 1 -d '.' | rev`" = \ "${ENDING}" ] ; then DO_CLONE="`echo "${DO_CLONE}" | rev | cut -f 2- -d '.' | rev`" fi fi done # remove possible _version(_arch) stuff from Debian package filenames # should be no _ in packge name or directory name, so can cut first field PARAM="`echo "${PARAM}" | cut -f 1 -d '_'`" if [ "${DO_CLONE}" != "" ] ; then DO_CLONE="`echo "${DO_CLONE}" | cut -f 1 -d '_'`" fi ${CMD_DEBUG_PRINT} "sanitized package name parameter: ${PARAM}" if [ "${DO_CLONE}" != "" ] ; then ${CMD_DEBUG_PRINT} "sanitized clone source name: ${DO_CLONE}" fi ${CMD_DEBUG_WAIT} # --- extend simple names to prefixed packagenames # no "-" in the given name -> is a hostname, extend to packagename # ###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 [ "`echo "${PARAM}-" | cut -f 2 -d '-'`" = "" ] ; then # extend an hostname to an -host- packagename PARAM="${CONF_HOST_TO_PKG_PREFIX}${PARAM}" ${CMD_DEBUG_PRINT} "extended package name parameter: ${PARAM}" ${CMD_DEBUG_WAIT} fi if [ "${DO_CLONE}" != "" ] ; then # no "-" in the given clone packagename -> is a clone hostname if [ "`echo "${DO_CLONE}-" | cut -f 2 -d '-' `" = "" ] ; then # extend an clone hostname to an clone -host- packagename DO_CLONE="${CONF_HOST_TO_PKG_PREFIX}${DO_CLONE}" ${CMD_DEBUG_PRINT} "extended clone source name: ${DO_CLONE}" ${CMD_DEBUG_WAIT} fi fi # --- expand existing .tar.gz source package back to an work directory # this code section is not used, badly tested if [ "${DO_EXPAND}" != "" ] ; then ${CMD_INFO_PRINT} "expanding existing tar for ${PARAM} ..." ${CMD_DEBUG_SLEEP} # we need to expand from .tar.gz, as .deb does not have source files # find newest version of this package to clone, in case of multiple # find the archive heuristic: whatever file has *.tar.gz # no _*.tar.gz here, so can fall back onto upstream maintainer version # Debian _version.tar.gz will sort after upstream .tar.gz filename # upstream current .tar.gz will sort after upstream archive -version.tar.gz PKG_TARNAME="`ls -1d "${PARAM}"*.tar.gz 2> /dev/null | tail -1`" if [ "${PKG_TARNAME}" = "" ] ; then ${CMD_FATAL} "no package ${PARAM}*.tar.gz to expand to for ${PARAM}" >&2 exit 1 fi # unpack packages source files into new work directory tar zxpf "${PKG_TARNAME}" # where did we unpack to # leave PKG_NAME unset, later derive it from package contents PKG_DIR="`tar ztf "${PKG_TARNAME}" | head -1 | cut -f 1 -d '/'`" ${CMD_DEBUG_PRINT} "expanded package archive: ${PKG_TARNAME} to ${PKG_DIR}" ${CMD_DEBUG_WAIT} fi # --- fetch existing package from Debian mirror or local Debian site # this code section is not used, badly tested if [ "${DO_FETCH}" != "" ] ; then ${CMD_INFO_PRINT} "fetching archive for ${PARAM} ..." ${CMD_DEBUG_SLEEP} # no package files here at moment, no existing file to look at # but user will have typed the wanted package name, so use that PKG_NAME="${PARAM}" # leave PKG_DIR unset, later derive it from finding directory # fetch the official Debian source, directly unpacked as directory apt-get source "${PKG_NAME}" ${CMD_DEBUG_PRINT} "fetched package archive: ${PKG_NAME} to ${PKG_DIR}" ${CMD_DEBUG_WAIT} fi # --- generating new, make the working directory for upstream if [ "${DO_GEN}" = yes -o "${DO_CLONE}" != "" ] ; then ${CMD_INFO_PRINT} "generating new for ${PARAM} ..." ${CMD_DEBUG_SLEEP} # new package, no existing dir, user will have typed wanted package name # and make identical directory, as no other info for this # set both PKG_NAME and PKG_DIR as neither can be derived from nothing PKG_NAME="${PARAM}" PKG_DIR="${PARAM}" ${CMD_INFO_PRINT} "generating upstream directory ..." ${CMD_DEBUG_SLEEP} # user may be working on an existing program directory, don't overwrite it if [ ! -d "${PKG_DIR}" ] ; then mkdir -p "${PKG_DIR}" else ${CMD_NOTE} "Package directory ${PKG_DIR} exists, skiping" >&2 fi ${CMD_DEBUG_PRINT} "generated package: ${PKG_NAME}" ${CMD_DEBUG_WAIT} fi # --- set directory for cases when using existing one if [ "${DO_FETCH}" != "" -o "${DO_CLOG}" != "" -o \ "${DO_PACK}" != "" -o "${DO_TIDY}" != "" ] ; then # no new package generated/cloned, nor package already expanded # so find an existing package directory, and extract name from that # user most likely has entered directory name, by tab completion # find by directory heuristic: whatever has no . # upstream current / will sort before older -version/ PKG_DIR="`ls -1dF "${PARAM}"* 2> /dev/null | grep '/$' | \ cut -f 1 -d '/' | head -1`" if [ "${PKG_DIR}" = "" ] ; then ${CMD_FATAL} "no package directory for ${PARAM} could be found" >&2 exit 1 fi ${CMD_DEBUG_PRINT} "using existing package directory: ${PKG_DIR}" ${CMD_DEBUG_WAIT} fi # --- find package name for any remaining cases needing it if [ "${PKG_NAME}" = "" ] ; then # existing dir, user possibly tab expanded, _version number already smashed # is the case after doing -x or for an already unpacked/neverpacked package # but not case if only upload/indexing with standalone (binary only?) .deb if [ -f "${PKG_DIR}/debian/control" ] ; then # already debianised, so we can look it up officially PKG_NAME="`grep '^Source: ' "${PKG_DIR}/debian/control" | cut -f 2 -d ' '`" ${CMD_DEBUG_PRINT} "using existing package name: ${PKG_NAME}" ${CMD_DEBUG_WAIT} else # assume that it should be named after the project directory # without any _version number in the name, so use already sanitized name PKG_NAME="${PARAM}" ${CMD_DEBUG_PRINT} "using generated package name: ${PKG_NAME}" ${CMD_DEBUG_WAIT} fi fi # --- if we are cloning existing package, copy all stuff from existing package # this code section is seldom used, sort of half tested if [ "${DO_CLONE}" != "" ] ; then ${CMD_INFO_PRINT} "cloning ${DO_CLONE} ..." ${CMD_DEBUG_SLEEP} # 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 tar cf - -C "${DO_CLONE}" . | 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="`ls -1 "${DO_CLONE}"_*.tar.gz 2> /dev/null | tail -1`" if [ "${CLONE_TARNAME}" != "" ] ; then # unpack to be cloned packages source files into new package tar zxpf "${CLONE_TARNAME}" # copy clone packages source files into new package tar cf - -C "${DO_CLONE}" . | tar xpf - -C "${PKG_DIR}" # and delete unpacked clone packages source files again rm -rf "${DO_CLONE}" else ${CMD_FATAL} "no package ${DO_CLONE} to clone" >&2 exit 1 fi fi if [ -d "${DO_CLONE}/debian" ] ; then ${CMD_DEBUG_PRINT} "cloned from package work directory: ${DO_CLONE}" else ${CMD_DEBUG_PRINT} "cloned from package archive: ${CLONE_TARNAME}" fi ${CMD_DEBUG_WAIT} fi # --- format date string for time stamp, used in various source files # current date for "last modufication" for generated files DATE_STAMP="`date +%Y.%m.%d`" # --- generate "upstream" Makefile # generate new "upstream" package, first step dummy Makefile, for extending if [ "${DO_GEN}" = yes ] ; then ${CMD_INFO_PRINT} "generating upstream Makefile ..." ${CMD_DEBUG_SLEEP} # user may be debianising an existing program directory, don't overwrite if [ ! -f "${PKG_DIR}/Makefile" ] ; then # this backticks + sed + here document trick here is a bit messy # we need to modify ${CONF_COPY} which is plain text # to include the # after newline, to make it commented code cat << END-MAKEFILE > "${PKG_DIR}/Makefile" # ${PKG_DIR}/Makefile - drive "upstream" compiling for package # author/generator ${CONF_AUTHOR}, # last modification/generation ${DATE_STAMP} `sed -e 's/^\([^#].*\)/# \1/' << END-SED-INPUT # This Makefile is ${CONF_COPY} END-SED-INPUT` PREFIX = \$(DESTDIR)/usr BINDIR = \$(PREFIX)/bin LIBDIR = \$(PREFIX)/lib/${PKG_NAME} SBINDIR = \$(PREFIX)/sbin MAN1DIR = \$(PREFIX)/share/man/man1 MAN7DIR = \$(PREFIX)/share/man/man7 MAN8DIR = \$(PREFIX)/share/man/man8 DOCDIR = \$(PREFIX)/share/doc/${PKG_NAME} EXADIR = \$(DOCDIR)/examples all: @# man pages need making and deleting of compressed versions @#gzip -9 -c ${PKG_NAME}.1 > ${PKG_NAME}.1.gz clean: @#rm -f ${PKG_NAME}.1.gz distclean: clean install: @# programs and man pages need installing to and deleting from system @#mkdir -p \$(BINDIR) @#cp -p ${PKG_NAME} \$(BINDIR) @#mkdir -p \$(MAN1DIR) @#cp -p ${PKG_NAME}.1.gz \$(MAN1DIR) uninstall: @#rm -f \$(BINDIR)/${PKG_NAME} @#rm -f \$(MAN1DIR)/${PKG_NAME}.1.gz END-MAKEFILE else ${CMD_NOTE} "File ${PKG_DIR}/Makefile exists, skiping" >&2 fi ${CMD_DEBUG_PRINT} "`ls -al "${PKG_DIR}/Makefile"`" ${CMD_DEBUG_WAIT} fi # modify the "upstream" packages Makefile from existing package, just new name # leave rest unchanged, as we want the old stuff incl user changes to it if [ "${DO_CLONE}" != "" ] ; then ${CMD_INFO_PRINT} "modifying existing upstream Makefile ..." ${CMD_DEBUG_SLEEP} # fix up package name where it appears if [ -f "${PKG_DIR}/Makefile" ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" "${PKG_DIR}/Makefile" \ > "${PKG_DIR}/.Makefile" mv "${PKG_DIR}/.Makefile" "${PKG_DIR}/Makefile" fi ${CMD_DEBUG_PRINT} "`ls -al "${PKG_DIR}/Makefile"`" ${CMD_DEBUG_WAIT} fi # --- generate "upstream" README # generate new "upstream" package, second step dummy README, for extending if [ "${DO_GEN}" = yes ] ; then ${CMD_INFO_PRINT} "generating upstream README ..." ${CMD_DEBUG_SLEEP} # user may be debianising an existing program directory, don't overwrite if [ ! -f "${PKG_DIR}/README" ] ; then cat << END-README-FILE > "${PKG_DIR}/README" ${PKG_DIR}/README author/generator ${CONF_AUTHOR}, last modification/generation ${DATE_STAMP} This text (and all other files) are ${CONF_COPY} This "upstream" was generated automatically, by ${CONF_AUTHOR} END-README-FILE else ${CMD_NOTE} "File ${PKG_DIR}/README exists, skiping" >&2 fi ${CMD_DEBUG_PRINT} "`ls -al "${PKG_DIR}/README"`" ${CMD_DEBUG_WAIT} fi # modify the "upstream" packages README from existing package, just new name # leave rest unchanged, as we want the old stuff incl user changes to it if [ "${DO_CLONE}" != "" ] ; then ${CMD_INFO_PRINT} "modifying existing upstream README ..." ${CMD_DEBUG_SLEEP} # fix up package name where it appears if [ -f "${PKG_DIR}/README" ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" "${PKG_DIR}/README" \ > "${PKG_DIR}/.README" mv "${PKG_DIR}/.README" "${PKG_DIR}/README" fi ${CMD_DEBUG_PRINT} "`ls -al "${PKG_DIR}/README"`" ${CMD_DEBUG_WAIT} fi # --- generating new, make the working directory for debianising # this is used in a few places, in many commands, so set it here DEB_DIR="${PKG_DIR}/debian" if [ "${DO_GEN}" = yes -o "${DO_CLONE}" != "" ] ; then ${CMD_INFO_PRINT} "generating debianisation directory ..." ${CMD_DEBUG_SLEEP} if [ ! -d "${DEB_DIR}" ] ; then mkdir -p "${DEB_DIR}" # else # # drop this, because else incomprehensible message when cloning # ${CMD_NOTE} "Debianising directory ${DEB_DIR} exists, skiping" >&2 fi ${CMD_DEBUG_PRINT} "`ls -ald "${DEB_DIR}"`" ${CMD_DEBUG_WAIT} fi # --- control file # generate an new basic control file for this package if [ "${DO_GEN}" = yes ] ; then ${CMD_INFO_PRINT} "generating control file ..." ${CMD_DEBUG_SLEEP} # 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 # "all" are architecture independant, "any" or "i386"/etc are dependant # due to Debian brain lossage syntax here differs unnecessarily if [ "${CONF_ARCH}" = "all" ] ; then BUILD_DEPENDS="Build-Depends-Indep" else BUILD_DEPENDS="Build-Depends" fi # user may be re-debianising an existing program directory, don't overwrite # such as re-generating after destroying one generated file if [ ! -f "${DEB_DIR}/control" ] ; then cat << END-CONTROL-FILE > "${DEB_DIR}/control" Source: ${PKG_NAME} Section: ${CONF_SECTION} Priority: optional Maintainer: ${CONF_MAINT_NAME} <${CONF_MAINT_EMAIL}> ${BUILD_DEPENDS}: debhelper (>> 3.0.0) Standards-Version: 3.7.2 Package: ${PKG_NAME} Architecture: ${CONF_ARCH} Description: ${SYS_DESC_SH} ${SYS_DESC_1} ${SYS_DESC_2} END-CONTROL-FILE else ${CMD_NOTE} "File ${DEB_DIR}/control exists, skiping" >&2 fi ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/control"`" ${CMD_DEBUG_WAIT} 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 [ "${DO_CLONE}" != "" ] ; then ${CMD_INFO_PRINT} "modifying existing control file ..." ${CMD_DEBUG_SLEEP} # fix up the control file with this packages name if [ -f "${DEB_DIR}/control" ] ; then sed -e "/^Source:/s/.*/Source: ${PKG_NAME}/g" "${DEB_DIR}/control" \ > "${DEB_DIR}/.control" sed -e "/^Package:/s/.*/Package: ${PKG_NAME}/g" "${DEB_DIR}/.control" \ > "${DEB_DIR}/control" rm "${DEB_DIR}/.control" else ${CMD_WARNING} "no control file in package being cloned," \ "something is fishy here" >&2 fi ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/control"`" ${CMD_DEBUG_WAIT} fi # --- satisfy the Debian copyright fetishists for this package # generate our standard copyright text file if [ "${DO_GEN}" = yes ] ; then ${CMD_INFO_PRINT} "generating copyright file ..." ${CMD_DEBUG_SLEEP} # we just put in our standard copyright message # we use here cat instead of echo, so that line breaks stay # user may be re-debianising an existing program directory, don't overwrite # such as re-generating after destroying one generated file if [ ! -f "${DEB_DIR}/copyright" ] ; then cat << END-COPYRIGHT-FILE > "${DEB_DIR}/copyright" This package ${PKG_NAME} is ${CONF_COPY} END-COPYRIGHT-FILE else ${CMD_NOTE} "File ${DEB_DIR}/copyright exists, skiping" >&2 fi ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/copyright"`" ${CMD_DEBUG_WAIT} 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 [ "${DO_CLONE}" != "" ] ; then ${CMD_INFO_PRINT} "modifying existing copyright file ..." ${CMD_DEBUG_SLEEP} # fix up package name where it appears if [ -f "${DEB_DIR}/copyright" ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" \ "${DEB_DIR}/copyright" > "${DEB_DIR}/.copyright" mv "${DEB_DIR}/.copyright" "${DEB_DIR}/copyright" else ${CMD_WARNING} "no copyright file in package being cloned," \ "something is fishy here" >&2 fi ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/copyright"`" ${CMD_DEBUG_WAIT} fi # --- changelog # generate empty changelog file (later changelog.Debian) if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "generating changelog file ..." ${CMD_DEBUG_SLEEP} # 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 # user may be re-debianising an existing program directory, don't overwrite # such as re-generating after destroying one generated file if [ ! -f "${DEB_DIR}/changelog" ] ; then touch "${DEB_DIR}/changelog" else ${CMD_NOTE} "File ${DEB_DIR}/changelog exists, skiping" >&2 fi ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/changelog"`" ${CMD_DEBUG_WAIT} fi # cloning use unchanged file # no changing names, as this is part of the history to be logged # --- docs list # generate docs list with just README file in it if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "generating docs list ..." ${CMD_DEBUG_SLEEP} # start an .docs file with what we have generated # user may be re-debianising an existing program directory, don't overwrite # such as re-generating after destroying one generated file if [ ! -f "${DEB_DIR}/${PKG_NAME}.docs" ] ; then echo "README" > "${DEB_DIR}/${PKG_NAME}.docs" else ${CMD_NOTE} "File ${DEB_DIR}/${PKG_NAME}.docs exists, skiping" >&2 fi ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/${PKG_NAME}.docs"`" ${CMD_DEBUG_WAIT} fi # modify the docs list file from existing package, just new name and filename # leave rest unchanged, as we want the old stuff incl user changes to it if [ "${DO_CLONE}" != "" ] ; then ${CMD_INFO_PRINT} "modifying existing docs list ..." ${CMD_DEBUG_SLEEP} # fix up file name where it appears if [ -f "${DEB_DIR}/${DO_CLONE}.docs" ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" \ "${DEB_DIR}/${DO_CLONE}.docs" > "${DEB_DIR}/${PKG_NAME}.docs" rm "${DEB_DIR}/${DO_CLONE}.docs" fi ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/${PKG_NAME}.docs"`" ${CMD_DEBUG_WAIT} fi # --- postinst/prerm stuff # don't generate any [pre|post]* stuff any more # as debian/rules and dh_installdeb now does this for us # if users need additions then by hand make ${PKG_NAME}.postinst/prerm # so this entire section is obsolete for new packages # this section is now only for cloning old packages which had no dh_* # so still use the old postinst/prerm names without ${PKG_NAME} in them # modify any post* and pre* files from existing packages, just new name in them # 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 # do this for old makepackage style names and new makesourcepackage style if [ "${DO_CLONE}" != "" ] ; then ${CMD_INFO_PRINT} "modifying existing [pre/post][inst/rm] ..." ${CMD_DEBUG_SLEEP} # fix up package name where it appears, old style file names if [ -f "${DEB_DIR}/preinst" ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" "${DEB_DIR}/preinst" \ > "${DEB_DIR}/.preinst" mv "${DEB_DIR}/.preinst ${DEB_DIR}/preinst" chmod "755 ${DEB_DIR}/preinst" ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/preinst"`" fi if [ -f "${DEB_DIR}/postinst" ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" "${DEB_DIR}/postinst" \ > "${DEB_DIR}/.postinst" mv "${DEB_DIR}/.postinst" "${DEB_DIR}/postinst" chmod 755 "${DEB_DIR}/postinst" ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/postinst"`" fi if [ -f "${DEB_DIR}/prerm" ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" "${DEB_DIR}/prerm" \ > "${DEB_DIR}/.prerm" mv "${DEB_DIR}/.prerm" "${DEB_DIR}/prerm" chmod 755 "${DEB_DIR}/prerm" ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/prerm"`" fi if [ -f "${DEB_DIR}/postrm" ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" "${DEB_DIR}/postrm" \ > "${DEB_DIR}/.postrm" mv "${DEB_DIR}/.postrm" "${DEB_DIR}/postrm" chmod 755 "${DEB_DIR}/postrm" ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/postrm"`" fi # fix up package name where it appears, new style file names if [ -f "${DEB_DIR}"/*.preinst ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" "${DEB_DIR}"/*.preinst \ > "${DEB_DIR}/${PKG_NAME}.preinst" chmod 755 "${DEB_DIR}/${PKG_NAME}.preinst" ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/${PKG_NAME}.preinst"`" fi if [ -f "${DEB_DIR}"/*.postinst ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" "${DEB_DIR}"/*.postinst \ > "${DEB_DIR}/${PKG_NAME}.postinst" chmod 755 "${DEB_DIR}/${PKG_NAME}.postinst" ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/${PKG_NAME}.postinst"`" fi if [ -f "${DEB_DIR}"/*.prerm ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" "${DEB_DIR}"/*.prerm \ > "${DEB_DIR}/${PKG_NAME}.prerm" chmod 755 "${DEB_DIR}/${PKG_NAME}.prerm" ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/${PKG_NAME}.prerm"`" fi if [ -f "${DEB_DIR}"/*.postrm ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" "${DEB_DIR}"/*.postrm \ > "${DEB_DIR}/${PKG_NAME}.postrm" chmod 755 "${DEB_DIR}/${PKG_NAME}.postrm" ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/${PKG_NAME}.postrm"`" fi ${CMD_DEBUG_WAIT} fi # --- rules "Makefile" stuff # lots of \ or even \\ quoting in this section, so stuff survives into Makefile # sh written Makefile runs shell with variables + multilined + backticks, grr # generate the build rules "Makefile" script if [ "${DO_GEN}" = yes ] ; then ${CMD_INFO_PRINT} "generating build rules script ..." ${CMD_DEBUG_SLEEP} # "all" are architecture independant, "any" or "i386"/etc are dependant # due to Debian brain lossage syntax here differs unnecessarily if [ "${CONF_ARCH}" = "all" ] ; then TARG_DONT="arch" TARG_DO="indep" else TARG_DONT="indep" TARG_DO="arch" fi # user may be re-debianising an existing program directory, don't overwrite # such as re-generating after destroying one generated file if [ ! -f "${DEB_DIR}/rules" ] ; then # this backticks + sed + here document trick here is a bit messy # we need to modify ${CONF_COPY} which is plain text # to include the # after newline, to make it commented code cat << END-RULES-MAKEFILE > "${DEB_DIR}/rules" #!/usr/bin/make -f # ${DEB_DIR}/rules - drive debian packaging for package # author/generator ${CONF_AUTHOR}, # 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 `sed -e 's/^\([^#].*\)/# \1/' << END-SED-INPUT # This rules file is ${CONF_COPY} END-SED-INPUT` # 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: @dh_testdir @# compiling can be done as non-root, no test here @# run upstream Makefile @\$(MAKE) @# mark this after compiling @touch build-stamp clean: @dh_testdir @dh_testroot @# clean up install run and build, I prefer this before clean upstream @dh_clean @# unmark "compile done" flag before "uncompiling" @rm -f build-stamp @# run upstream Makefile @\$(MAKE) clean install: build @dh_testdir @dh_testroot @# clean up debris from previous install runs, leave Debian files @dh_clean -k @# create our debian/ directory @dh_installdirs @# run upstream Makefile @\$(MAKE) install DESTDIR=\$(CURDIR)/debian/${PKG_NAME} binary-${TARG_DONT}: build install @# We have nothing to do here, package of other type (arch or indep) binary-${TARG_DO}: build install @dh_testdir @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 symlink (un)makers @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 [ "\$\${LINE}" != "" ] ; 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 END-RULES-MAKEFILE else ${CMD_NOTE} "File ${DEB_DIR}/rules exists, skiping" >&2 fi chmod 755 "${DEB_DIR}/rules" ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/rules"`" ${CMD_DEBUG_WAIT} 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 [ "${DO_CLONE}" != "" ] ; then ${CMD_INFO_PRINT} "modifying existing build rules script ..." ${CMD_DEBUG_SLEEP} # fix up package name where it appears if [ -f "${DEB_DIR}/rules" ] ; then sed -e "/${DO_CLONE}/s//${PKG_NAME}/g" \ "${DEB_DIR}/rules" > "${DEB_DIR}/.rules" mv "${DEB_DIR}/.rules" "${DEB_DIR}/rules" chmod 755 "${DEB_DIR}/rules" else ${CMD_WARNING} "no rules file in package being cloned," \ "something is fishy here" >&2 fi ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/rules"`" ${CMD_DEBUG_WAIT} fi # --- add an changelog entry 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 [ "${DO_CLOG}" != "" ] ; then ${CMD_INFO_PRINT} "adding changelog entry: ${DO_CLOG} ..." ${CMD_DEBUG_SLEEP} # save existing changelog if existing if [ -f "${DEB_DIR}/changelog" ] ; then 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_FOR_VERSION="`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 DATE_BASED_VERSION="${DATE_FOR_VERSION}-${SYS_PKG_LEVEL}" # when packaging, debianise this version with RFC date from now DATE_RFC="`date -R`" cat << END-CHANGELOG-FILE > "${DEB_DIR}/changelog" ${PKG_NAME} (${DATE_BASED_VERSION}) stable; urgency=low * ${DO_CLOG} -- ${CONF_MAINT_NAME} <${CONF_MAINT_EMAIL}> ${DATE_RFC} END-CHANGELOG-FILE ${CMD_INFO_PRINT} "new changelog version number is: ${DATE_BASED_VERSION}" ${CMD_DEBUG_SLEEP} # tag existing changelog on to new entry if one was saved if [ -f "${DEB_DIR}/changelog.old" ] ; then echo >> "${DEB_DIR}/changelog" cat "${DEB_DIR}/changelog.old" >> "${DEB_DIR}/changelog" fi ${CMD_DEBUG_PRINT} "`ls -al "${DEB_DIR}/changelog"`" ${CMD_DEBUG_WAIT} fi # --- build the package files and check it for errors if [ "${DO_PACK}" = yes ] ; then ${CMD_INFO_PRINT} "building package ${PKG_NAME} ..." ${CMD_DEBUG_SLEEP} if [ ! -s "${DEB_DIR}/changelog" ] ; then # user hat not produced even one changelog entry, we have no version number ${CMD_FATAL} "no changelog entry, no version number, aborting" >&2 exit 1 fi # save and eliminate CVS stuff, if we have any if [ -d "${PKG_DIR}/CVS" ] ; then if [ -f "${SYS_SAVE_TAR}" ] ; then rm "${SYS_SAVE_TAR}" fi tar cf "${SYS_SAVE_TAR}" "${PKG_DIR}" CVS_SAVED_AS_TAR=yes find "${PKG_DIR}" -name CVS -exec rm -rf {} \; 2> /dev/null fi # then build the actual package stuff if [ -d ~/.gnupg -o -d ~/.pgp ] ; then ( cd "${PKG_DIR}" ; dpkg-buildpackage -rfakeroot ) else ( cd "${PKG_DIR}" ; dpkg-buildpackage -rfakeroot -uc -us ) fi # and tidy up compiling leftovers if [ "${DEBUG_LEAVE_TEMPFILES}" != yes ] ; then # but offer to leave them to investigate bugs ( cd "${PKG_DIR}" ; fakeroot debian/rules clean ) fi # restore CVS stuff, if we had any if [ "${CVS_SAVED_AS_TAR}" != "" ] ; then tar xpf "${SYS_SAVE_TAR}" rm "${SYS_SAVE_TAR}" fi # run a test over package, to get more error messages lintian -i "${PKG_NAME}"_*.changes # and get rid of superfluous .changes file if [ "${CONF_REMOVE_CHANGES_FILE}" = yes ] ; then rm "${PKG_NAME}"_*.changes fi ${CMD_DEBUG_PRINT} "+++ begin packaged files listing +++" ls -al "${PKG_NAME}"_*.tar.gz if [ -f "${PKG_NAME}"_*.diff.gz ] ; then ls -al "${PKG_NAME}"_*.diff.gz fi ls -al "${PKG_NAME}"_*.dsc if [ -f "${PKG_NAME}"_*.changes ] ; then ls -al "${PKG_NAME}"_*.changes fi ls -al "${PKG_NAME}"_*_*.deb ${CMD_DEBUG_PRINT} "+++ end packaged files listing +++" ${CMD_DEBUG_WAIT} fi # --- tidy up (delete) work directory if [ "${DO_TIDY}" = yes ] ; then ${CMD_INFO_PRINT} "tidying up work directory ${PKG_NAME} ..." ${CMD_DEBUG_SLEEP} rm -rf "${PKG_DIR}" ${CMD_DEBUG_PRINT} "work directory deleted: ${PKG_DIR}" ${CMD_DEBUG_WAIT} fi # --- common filenames and section determination for upload and index if [ "${DO_UPLOAD}" = yes -o "${DO_INDEX}" = yes ] ; then if ls "${PKG_NAME}"_*.dsc > /dev/null 2>&1 ; then # - determine the source files # if we have an full source package with .dsc file, extract version from it # find the .dsc file for newest version of this package to upload PKG_DSCNAME="`ls -1 "${PKG_NAME}"_*.dsc 2> /dev/null | tail -1`" ${CMD_DEBUG_PRINT} "PKG_DSCNAME=${PKG_DSCNAME}" ${CMD_DEBUG_WAIT} # some .dsc files are PGP/gpg signed, strip the signature # to avoid Version: line in signature block, or possible later in header if [ "`grep '^-----BEGIN PGP SIGNED' "${PKG_DSCNAME}" | \ cut -f 1 -d ' '`" != "" ] ; then # using gpg itsself for this fails, because it crashes first time round # if user has no ~/.gnupg, auto-generate, but too stupid to auto-reread # also don't litter world with content-free default ~/.gnupg directory # which gpg goes and creates, even if never used again, silly PKG_VERSION="`sed -ne \ '/^-----BEGIN PGP SIGNE/,/^-----BEGIN PGP SIGNA/p' \ "${PKG_DSCNAME}" | \ sed -ne '/^$/,$ { /^Version:/p }' | cut -f 2 -d ' '`" else PKG_VERSION="`grep '^Version:' "${PKG_DSCNAME}" | cut -f 2 -d ' '`" fi # strip ':' epoch from version number, as it does not appear in filenames if echo "${PKG_VERSION}" | grep ':' > /dev/null ; then PKG_VERSION="`echo "${PKG_VERSION}" | cut -f 2 -d ':'`" fi ${CMD_DEBUG_PRINT} "PKG_VERSION=${PKG_VERSION}" ${CMD_DEBUG_WAIT} # names for the actual source files, one of each type, some facultative PKG_TARNAME="${PKG_NAME}_${PKG_VERSION}.tar.gz" if [ ! -f "${PKG_TARNAME}" ] ; then # original .tar.gz files do not have an debianisation level PKG_TARNAME="${PKG_NAME}_"`echo "${PKG_VERSION}" | \ cut -f 1 -d '-'`".orig.tar.gz" fi # may not exist, but define anyway, test later PKG_DIFFNAME="${PKG_NAME}_${PKG_VERSION}.diff.gz" # .changes are architecture specific because contain full .deb file names PKG_CHGNAME="`echo "${PKG_NAME}_${PKG_VERSION}"_*.changes | \ cut -f 1 -d ' '`" ${CMD_DEBUG_PRINT} "PKG_TARNAME=${PKG_TARNAME} \ PKG_DIFFNAME=${PKG_DIFFNAME} PKG_CHGNAME=${PKG_CHGNAME}" ${CMD_DEBUG_WAIT} # - determine the binary files base names # names for the actual binary files, mult of same type (.deb), count varies # the .dsc file lists the package names for all of these # this in not dependant on gpg signing, that has no ^Binary: lines in it BINARYS="`grep '^Binary:' "${PKG_DSCNAME}" | cut -f 2- -d ':' | \ tr -d ' ' | tr ',' ' '`" # no "${BINARYS}" in for, else intervening spaces end up in BINARY # and that would then really confuse the stuff processing ${BINARY} # sanitise binary list, only valid chars, avoid escaping bugs hitting "for" # other user error junk will get caught by ${BINARY} name processsing # note: the tr will fail if the - after 9 is not specially placed for BINARY in `echo ${BINARYS} | tr -c -d 'a-zA-Z0-9-_.+:%~'` ; do PKG_DEBNAMES="${PKG_DEBNAMES} ` \ ls -1 ${BINARY}_${PKG_VERSION}_*.deb 2> /dev/null | \ tail -1 | tr -c -d 'a-zA-Z0-9-_.+:%~'`" done # ${PKG_NAME} has been stripped of .deb and _vers_arch while sanitizing elif ls "${PKG_NAME}"_*_*.deb > /dev/null 2>&1 ; then ${CMD_NOTE} "falling back from .dsc to .deb for package ${PKG_NAME}" # no .dsc, but at least an stray (binary only?) .deb file # set only the binary package, there can only be one in this case PKG_DEBNAME="`ls -1 "${PKG_NAME}"_*_*.deb 2> /dev/null | \ tail -1 | tr -c -d 'a-zA-Z0-9-_.+:%~'`" PKG_DEBNAMES="${PKG_DEBNAME}" else ${CMD_FATAL} "no .dsc or .deb found for package ${PKG_NAME}" >&2 exit 1 fi ${CMD_DEBUG_PRINT} "PKG_DEBNAMES=${PKG_DEBNAMES}" ${CMD_DEBUG_WAIT} # - extract section if [ "${PKG_DSCNAME}" != "" ] ; then # extract section for source package, CONF_SECTION is only valid if with -g # why is this information not contained in the .dsc file? # we may not have an .changes file, if deleted, so do not depend on that # this also requires all generated binary packages to have the same # *main* section as the source, no multiple are possible, else -i fails # mixed are unlikely to exist, and may even violate Debian policy # the subsection can vary, as that is not relevant for indexer calling if [ -f "${PKG_DIFFNAME}" ] ; then # get this from debianisation control, extracted from diff format SECTION="`zcat "${PKG_DIFFNAME}" | \ sed -ne '/^\+\+\+ .*\/debian\/control/,/^--- /p' | \ cut -f 2- -d '+' | grep '^Section: ' | head -1 | cut -f 2 -d ' '`" else # get this from debianisation control, extracted from tar archive SECTION="`tar zxOf "${PKG_TARNAME}" '*/debian/control' | \ grep '^Section: ' | head -1 | cut -f 2 -d ' '`" fi else # no .dsc, and so no .diff or .tar.gz, so read this from .deb SECTION="`dpkg -f "${PKG_DEBNAME}" Section`" fi ${CMD_DEBUG_PRINT} "full SECTION=${SECTION}" ${CMD_DEBUG_WAIT} # split section descriptor into part 1 (main) and part 2 (sub) sections if echo "${SECTION}" | grep '/' > /dev/null ; then SUBSECT="`echo "${SECTION}" | cut -f 2 -d '/'`" SECTION="`echo "${SECTION}" | cut -f 1 -d '/'`" else # nothing to split, so it must be main as part 1 SUBSECT="${SECTION}" SECTION="main" fi ${CMD_DEBUG_PRINT} "split SECTION=${SECTION} SUBSECT=${SUBSECT}" ${CMD_DEBUG_WAIT} fi # --- upload finished packages to local Debian package server if [ "${DO_UPLOAD}" = yes ] ; then ${CMD_INFO_PRINT} "uploading ${PKG_NAME} to ${CONF_DISTRIB} on" \ "${CONF_USER}@${CONF_PKG_SERVER}:${CONF_PKG_BASE} ..." ${CMD_DEBUG_SLEEP} # - prevent uploading permission handling from trashing anything # we chmod restricted access on the non-free branch directory # running as root@ would allow scp/rsync to kill this mode # setting it each time for each upload would fix the mode here in code # that would be highly unportable, so eimply not allow root uploads if [ "${SYS_ALLOW_ROOT_UPLOAD_LOSSAGE}" != yes ] ; then if [ "${CONF_USER}" = root ] ; then ${CMD_ERROR} "you shall not upload to root@, this will smash" \ "access restrictions to \"non-free\" or similar, aborting ..." >&2 exit 1 fi fi # - copy the source files # path for storing all of this packages source files SOURCE_DIR="dists/${CONF_DISTRIB}/${SECTION}/source/${SUBSECT}" for SOURCE_FILE in "${PKG_DSCNAME}" "${PKG_TARNAME}" \ "${PKG_DIFFNAME}" "${PKG_CHGNAME}" ; do if [ -f "${SOURCE_FILE}" ] ; then mkdir -p "${SYS_UPLOADDIR}/${SOURCE_DIR}" cp -p "${SOURCE_FILE}" "${SYS_UPLOADDIR}/${SOURCE_DIR}" ${CMD_VERBOSE_PRINT} "- ${SOURCE_DIR}/${SOURCE_FILE}" fi done # - copy the binary files # no "${PKG_DEBNAMES}" in for, else intervening spaces end up in PKG_DEBNAME # and that would then really confuse the stuff processing ${PKG_DEBNAME} # content of ${PKG_DEBNAMES} has already been sanitised up above for PKG_DEBNAME in ${PKG_DEBNAMES} ; do if [ -f "${PKG_DEBNAME}" ] ; then # extract section from package, CONF_SECTION is only valid if with -g SECTION="`dpkg-deb -f "${PKG_DEBNAME}" Section`" # split section descriptor into part 1 (main) and part 2 (sub) sections if [ "`echo "${SECTION}" | grep '/'`" != "" ] ; then SUBSECT="`echo "${SECTION}" | cut -f 2 -d '/'`" SECTION="`echo "${SECTION}" | cut -f 1 -d '/'`" else # nothing to split, so it must be main as part 1 SUBSECT="${SECTION}" SECTION="main" fi # extract architecture from package, var CONF_ARCH only set if doing -g # some may be "all" (such as docs), some may be "any"/specific ARCH="`dpkg-deb -f "${PKG_DEBNAME}" Architecture`" # path for storing this particular binary file B_ARCH_DIR="dists/${CONF_DISTRIB}/${SECTION}/binary-${ARCH}/${SUBSECT}" mkdir -p "${SYS_UPLOADDIR}/${B_ARCH_DIR}" cp -p "${PKG_DEBNAME}" "${SYS_UPLOADDIR}/${B_ARCH_DIR}" ${CMD_VERBOSE_PRINT} "${B_ARCH_DIR}/${PKG_DEBNAME}" else ${CMD_WARNING} "no binary ${PKG_DEBNAME}, something is fishy here" >&2 fi done # - upload all the copied files to the server # get permissons right for on server if [ "${CONF_GROUP}" != "" ] ; then # get all directories, but also hits all files in them chgrp -R "${CONF_GROUP}" "${SYS_UPLOADDIR}" chmod -R 2775 "${SYS_UPLOADDIR}" # get all the files back to something sensible # the */*/*/* are:
/[source|binary-${ARCH}]// chgrp "${CONF_GROUP}" "${SYS_UPLOADDIR}/dists/${CONF_DISTRIB}"/*/*/*/* chmod 664 "${SYS_UPLOADDIR}/dists/${CONF_DISTRIB}"/*/*/*/* fi if [ "${CONF_PKG_SERVER}" != "" ] ; then # copy an temp directory, for single ssh/scp upload (may require password) # include directory tree, duplicate tree to server, case server has none # may be none if new package is in an previously unused section # 2> needed to get rid of error message, because can not change dir modes # this loses us progress bar, because scp tests also 2> for tty or not # this is a bit site dependant, you need ssh on your local package server #scp -pr "${SYS_UPLOADDIR}"/* \ # "${CONF_USER}@${CONF_PKG_SERVER}:${CONF_PKG_BASE}" 2> /dev/null # replaced with rsync because scp bug, forgets -r after large file upload if rsync -a "${SYS_UPLOADDIR}"/* \ "${CONF_USER}@${CONF_PKG_SERVER}:${CONF_PKG_BASE}" 2> /dev/null ; then # screw up with else is needed to avoid losing return code from rsync # using ! in above if would store the resulting code, allways 0 true else ${CMD_DEBUG_PRINT} "rsync failled with $? return code" fi else ${CMD_FATAL} "no server to upload package files to" >&2 exit 1 fi ${CMD_DEBUG_PRINT} "+++ begin files listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${SYS_UPLOADDIR}/dists/${CONF_DISTRIB}"/*/*/*/* 2> /dev/null fi ${CMD_DEBUG_PRINT} "+++ end files listing +++" ${CMD_DEBUG_WAIT} # remove temporary directory and its contents, to save space # must be after debug printout if [ "${DEBUG_LEAVE_TEMPDIRS}" != yes ] ; then # but offer to leave this to investigate bugs rm -rf "${SYS_UPLOADDIR}" fi fi # --- (re-)index package files on local Debian server if [ "${DO_INDEX}" = yes ] ; then ${CMD_INFO_PRINT} "indexing for package ${PKG_NAME} in ${CONF_DISTRIB}" \ "on ${CONF_USER}@${CONF_PKG_SERVER}:${CONF_PKG_BASE} ..." ${CMD_DEBUG_SLEEP} # run an local package server index update command # this is even more site dependant than uploading, you not only need ssh # but also makelocalsite (or whatever you call) install on the server if [ "${CONF_INDEXER}" != "" ] ; then ${CMD_VERBOSE_PRINT} "running indexer on section ${SECTION} ..." ${CMD_DEBUG_SLEEP} if ssh "${CONF_USER}@${CONF_PKG_SERVER}" \ "cd \"${CONF_PKG_BASE}\"; \ ${CONF_INDEXER} ${INDEXER_OPT} ${SECTION}" ; then # screw up with else is needed to avoid losing return code from ssh # using ! in above if would store the resulting code, allways 0 true else ${CMD_DEBUG_PRINT} "indexer run by ssh failled with $? return code" fi else ${CMD_ERROR} "no site indexer configured" >&2 exit 1 fi ${CMD_DEBUG_PRINT} "updated local server indexes: ${SECTION}" ${CMD_DEBUG_WAIT} fi # --- remove all generated files of an package if [ "${DO_REMOVE}" != "" ] ; then ${CMD_INFO_PRINT} "removing packaged ${PKG_NAME} ..." ${CMD_DEBUG_SLEEP} ${CMD_DEBUG_PRINT} "removed package files:" \ "`ls -1 "${PKG_NAME}"_* 2> /dev/null`" ${CMD_DEBUG_WAIT} # are ${PKG_NAME}_*.dsc ..._*.tar.gz ..._*_*.deb, and possibly ..._*.changes rm -f "${PKG_NAME}"_* fi exit 0 # that's all folks!