#!/bin/sh # http://www.phys.ethz.ch/~franklin/Projects/dphys2/makepackage # - generate directory structure and files for generating packages # copyright ETH Zuerich Physics Deparement, use under either BSD or GPL license # author Neil Franklin, last modification 2003.04.11 # this script is intended to be run as an normal user # use as makepackage [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 # --- 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 CONF_HOST_TO_PKG_PREFIX=dphys-host- # this is the contents for /usr/share/doc/*/copyright file # not that we expect anyone else to ever use these packages :-) CONF_PKG_COPY="copyright ETH Zuerich Physics Deparement, use under either BSD or GPL license" # this is for the /usr/share/doc/*/changelog.Debian and /DEBIAN/control # and the Packages list entry for apt-get and dpkg CONF_PKG_MAINTAINER="dphys2 make package script " # this is the site package to put into the "Depends:" of this package # it itsself then refers to all packages that we want to have loaded #CONF_SITE_PKG=dphys-site CONF_SITE_PKG=dphys-site-franklin-experimental # --- DEBUG_*, various debugging settings # set this to output debug state info and wait after each step DEBUG_PRINT_STEP=no # --- SYS_*, various system internal values # set our architecture, no binary stuff in these SYS_ARCH=all # ------ actual implementation from here on # no user settings any more # --- parse command line while [ x`echo $1 | cut -c 1` = x- ] ; do # options from command line and cut off the "-" OPTS=`echo $1 | cut -c 2-` shift 1 while [ x${OPTS} != x ] ; do # first option to process OPT=`echo ${OPTS} | cut -c 1` OPTS=`echo ${OPTS} | cut -c 2-` # creating packages case ${OPT} in g) # generate: generate work directories DO_GEN=yes ;; b) # blank: user wants to set no site package name, delete the default CONF_SITE_PKG='' ;; s) # site: user wants to set custom site package name, overwrite default CONF_SITE_PKG=$1 shift 1 ;; c) # clone: take/clone content from this existing package DO_CLONE=$1 shift 1 ;; x) # (e)xpand: expand package back to an work directory # this is not -e expand, because it craches echo in option test DO_EXPAND=yes ;; d) # depend: user wants to add an further dependency, make list of them if [ "x${DO_DEPEND}" != x ] ; then DO_DEPEND="${DO_DEPEND}, $1" else DO_DEPEND=$1 fi shift 1 ;; r) # remove: remove existing/old .deb files DO_REMOVE=yes ;; p) # package: take work directory, and package it DO_PACK=yes ;; l) # level: user wants to set debianisation level OPT_LEVEL=$1 shift 1 ;; t) # tidy: delete work directory DO_TIDY=yes ;; i) # info: show progress DO_INFO=yes ;; v) # verbose: show progress DEBUG_PRINT_STEP=yes ;; *) # not one of our options echo $0: unknown option at: ${OPT} >&2 echo # call self without parameter to output help $0 exit 1 ;; esac done done if [ $# != 1 ] ; then # user did not give an parameter (package name), or gave multiple # give out help how this script should be used cat << EOF Usage is: $0 [options] packagename options: [for creating] -g generate: generate work directories and their content -b blank: no setting of any Depends: used mainly for making site packages, which have no Depends: on an other site package. Usually together with -g as then user modification of DEBIAN/control file is needed, using -d -s sitepackage site: use Depends: on this site package, instead of the default site package ${CONF_SITE_PKG} [for cloning] -c oldpackage clone/copy: clone contents from , instead of new * changelog new, with remark that it was cloned (* all installable files copied) not yet * control copied and package name in it changed * postinst and prerm copied unchanged *** all other files presently ignored *** if no - in the oldpackage name, expand like packagename [for expanding] -x (e)xpand: take an .deb and make work directories from it this can undo the effect of -t, so long -p was done before it [for modifying] -d dependancy depend: add this dependancy to the Depends: line this option can be used multiple times [for packing] -r remove: delete all existing/old .deb files -p pack: pack up the work directories, making .deb file this also generates the actual package version (date) -l level level: set debianisation level, default 1 as we we use 8 digit date for version numbers this can be used if multiple versions in one day -t tidy: tidy up, delete work directories [other stuff] -i info: show information about an .deb package -v verbose: show progress 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 fi PKG_NAME=$1 if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' options are: DO_GEN: ${DO_GEN}, DO_CLONE: ${DO_CLONE}, \ DO_EXPAND: ${DO_EXPAND}, DO_DEPEND: ${DO_DEPEND}, \ DO_PACK: ${DO_PACK}, DO_TIDY: ${DO_TIDY}, 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`echo ${PKG_NAME}- | cut -f 2 -d "-" ` = x ] ; then # extend an hostname to an packagename PKG_NAME=${CONF_HOST_TO_PKG_PREFIX}${PKG_NAME} fi if [ x${DO_CLONE} != x ] ; then # no "-" in the given clone packagename -> is a clone hostname if [ x`echo ${DO_CLONE}- | cut -f 2 -d "-" ` = x ] ; then # extend an clone hostname to an clone packagename DO_CLONE=${CONF_HOST_TO_PKG_PREFIX}${DO_CLONE} fi fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' expanded names are: PKG_NAME: ${PKG_NAME}, DO_CLONE: ${DO_CLONE} fi # --- make the minimal set of working directories # not inside the "if" because used in multiple places/functions later PKGDIR=${PKG_NAME} DOCDIR=${PKGDIR}/usr/share/doc/${PKG_NAME} DEBDIR=${PKGDIR}/DEBIAN if [ x${DO_GEN} = xyes -o x${DO_CLONE} != x ] ; then mkdir -p ${PKGDIR} mkdir -p ${DOCDIR} mkdir -p ${DEBDIR} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' mkdir done ls -ald ${PKGDIR} ${DOCDIR} ${DEBDIR} fi fi # --- if we are cloning, copy all the stuff from existing package if [ x${DO_CLONE} != x ] ; then if [ -d ${DO_CLONE}/DEBIAN ] ; then # do we find an work directory (must be same or newer than a package) CLONE_FULLNAME=${DO_CLONE} # copy clone packages data files into new package tar cf - -C ${CLONE_FULLNAME} --exclude DEBIAN . | tar xpf - -C ${PKGDIR} # copy clone packages control files into new package cp -p ${CLONE_FULLNAME}/DEBIAN/* ${DEBDIR} else # only got an .deb archive, no possibly newer directory, use .deb # find newest version of this package to clone CLONE_FULLNAME=`ls -1d ${DO_CLONE}* | tail -1` # unpack clone packages data files into new package dpkg-deb --extract ${CLONE_FULLNAME} ${PKGDIR} # unpack clone packages control files into new package (cd ${PKGDIR}; dpkg-deb --control ../${CLONE_FULLNAME}) fi # move over documentation to the new directory and lose old directory mv ${PKGDIR}/usr/share/doc/${DO_CLONE}/* ${DOCDIR} rmdir ${PKGDIR}/usr/share/doc/${DO_CLONE} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' clone package name is: CLONE_FULLNAME: ${CLONE_FULLNAME} fi fi # --- satisfy the Debian copyright fetishists for this package # cloning takes over the existing copyright, leave unchanged if [ x${DO_GEN} = xyes ] ; then # we just put in our standard copyright echo ${CONF_PKG_COPY} > ${DOCDIR}/copyright if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' copyright generated ls -al ${DOCDIR}/copyright fi fi # --- make the changelog for this package CONF_PKG_CL_VERS="current:" CONF_PKG_CL_TEXT="\tcurrent version, changes constantly, versioning done only on debianising" CONF_PKG_CL_CLON="\tinitially cloned from ${DO_CLONE}" if [ x${DO_GEN} = xyes -o x${DO_CLONE} != x ] ; then # we mention only one package version, then this package is done # is not strictly true, but simpler so, and sufficient for our purpose # if someone wants newer versions to remark of the old, add it later echo ${CONF_PKG_CL_VERS} > ${DOCDIR}/changelog echo -e ${CONF_PKG_CL_TEXT} >> ${DOCDIR}/changelog if [ x${DO_CLONE} != x ] ; then echo -e ${CONF_PKG_CL_CLON} >> ${DOCDIR}/changelog fi echo >> ${DOCDIR}/changelog echo "since:" >> ${DOCDIR}/changelog echo -e "\tnothing" >> ${DOCDIR}/changelog if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' changelog generated ls -al ${DOCDIR}/changelog fi fi # --- make the postinst/prerm stuff # this is just the standard inking stuff that everyone needs to repeat # they really should have put this into the actual installer # clone leave this unchanged, as we want the old stuff incl user changes in it if [ x${DO_GEN} = xyes ] ; then cat < ${DEBDIR}/postinst #!/bin/sh set -e # Automatically added by dh_installdocs if [ "$1" = "configure" ]; then if [ -d /usr/doc -a ! -e /usr/doc/crashed -a -d /usr/share/doc/crashed ]; then ln -sf ../share/doc/crashed /usr/doc/crashed fi fi # End automatically added section EOF cat < ${DEBDIR}/prerm #!/bin/sh set -e # Automatically added by dh_installdocs if [ \( "$1" = "upgrade" -o "$1" = "remove" \) -a -L /usr/doc/crashed ]; then rm -f /usr/doc/crashed fi # End automatically added section EOF chmod 755 ${DEBDIR}/postinst ${DEBDIR}/prerm if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' postinst and prerm scripts made ls -al ${DEBDIR}/postinst ${DEBDIR}/prerm fi fi # --- make the control file for the Packages list if [ x${DO_GEN} = xyes ] ; then echo "Package: ${PKG_NAME}" > ${DEBDIR}/control echo "Version: +++ updated later when packaging +++" \ >> ${DEBDIR}/control echo "Section: misc" >> ${DEBDIR}/control echo "Priority: optional" >> ${DEBDIR}/control echo "Architecture: ${SYS_ARCH}" >> ${DEBDIR}/control # this line is the important one, sets the Depends: line we want # this is the main reason for all these packages to exist # this may need user editing, is reason for generate/pack/tidy split echo "Depends: ${CONF_SITE_PKG}" >> ${DEBDIR}/control echo "Maintainer: ${CONF_PKG_MAINTAINER}" \ >> ${DEBDIR}/control echo "Description: Pull in packages via Depends: and config files" \ >> ${DEBDIR}/control echo " This package exists soley to produce Depends: dependencies." \ >> ${DEBDIR}/control echo " This is to get apt-get to load all packages we want." \ >> ${DEBDIR}/control echo " It also loads various config files that we want to have." \ >> ${DEBDIR}/control if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' control file generated ls -al ${DEBDIR}/control fi fi # --- modify control file from existing package if [ x${DO_CLONE} != x ] ; then # fix up the control file withr this packages name sed -e "/^Package:/s/.*/Package: ${PKG_NAME}/" ${DEBDIR}/control > \ ${DEBDIR}/.control mv ${DEBDIR}/.control ${DEBDIR}/control if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' control file modified ls -al ${DEBDIR}/control fi fi # --- expand existing package back to an work directory if [ x${DO_EXPAND} != x ] ; then # find newest version of this package to clone PKG_FULLNAME=`ls -1d ${PKG_NAME}* | tail -1` # expand packages data files into new package dpkg-deb --extract ${PKG_FULLNAME} ${PKGDIR} # expand packages control files into new package (cd ${PKGDIR}; dpkg-deb --control ../${PKG_FULLNAME}) if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' extracted package name is: PKG_FULLNAME: ${PKG_FULLNAME} fi fi # --- add an dependency if [ "x${DO_DEPEND}" != x ] ; then # one or multiple dependencies to control file sed -e "/^Depends: /s/$/, ${DO_DEPEND}/" ${DEBDIR}/control > \ ${DEBDIR}/.control mv ${DEBDIR}/.control ${DEBDIR}/control if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' control Depends added grep '^Depends: ' ${DEBDIR}/control fi fi # --- remove all .deb archives of an package # 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_FULLNAME=`ls -1d ${PKG_NAME}* | tail -1` # and remove them rm ${PKG_FULLNAME} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' removed package name is: PKG_FULLNAME: ${PKG_FULLNAME} fi fi # --- compute package version if [ x${DO_PACK} = xyes ] ; then # we base our versions on the current date DATE_NUM=`date +%Y%m%d` DATE_ISO=`date +%Y-%m-%d` PKG_VERSION=${DATE_NUM} PKG_LEVEL=1 if [ x${OPT_LEVEL} != x ] ; then PKG_LEVEL=${OPT_LEVEL} fi PKG_DEBVERS=${PKG_VERSION}-${PKG_LEVEL} PKG_FILENAME=${PKG_NAME}_${PKG_DEBVERS}_${SYS_ARCH}.deb if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' package version is: PKG_DEBVERS: ${PKG_DEBVERS} fi fi # --- make the changelog.Debian for this package and level if [ x${DO_PACK} = xyes ] ; then # when packaging, debianise this version with date from now # this is usually only one level, as startign from 1 per version # can be changed with -l, patch for making multiple releases in one day echo "${PKG_NAME} (${PKG_DEBVERS}) stable; urgency=high" \ > ${DOCDIR}/changelog.Debian echo >> ${DOCDIR}/changelog.Debian echo " * auto-generated release from versionless (=current) upstream" \ >> ${DOCDIR}/changelog.Debian echo >> ${DOCDIR}/changelog.Debian echo " -- ${CONF_PKG_MAINTAINER} ${DATE_ISO}" \ >> ${DOCDIR}/changelog.Debian # fix up the control file for this packages version being packaged sed -e "/^Version:/s/.*/Version: ${PKG_DEBVERS}/" ${DEBDIR}/control > \ ${DEBDIR}/.control mv ${DEBDIR}/.control ${DEBDIR}/control if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' Debian changelog generated ls -al ${DOCDIR}/changelog.Debian fi fi # --- make the .deb package file and check it for errors if [ x${DO_PACK} = xyes ] ; then # first compress the changelog files, with the newest edits in them # get rid of any existing old compressed versions rm -f ${DOCDIR}/changelog.gz ${DOCDIR}/changelog.Debian.gz # and pack the current ones, the --best way that lintian wants to see gzip --best ${DOCDIR}/changelog ${DOCDIR}/changelog.Debian # then do the actual .deb stuff fakeroot dpkg-deb --build ${PKGDIR} . # and run a test over it, to get more error messages lintian ${PKG_FILENAME} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' .deb package generated ls -al ${PKG_FILENAME} fi fi # --- delete temporary work directory if [ x${DO_TIDY} = xyes ] ; then rm -rf ${PKGDIR} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' work directory deleted for ${PKGDIR} fi fi # --- information on package if [ x${DO_INFO} = xyes ] ; then # find newest version of this package to inform on PKG_FULLNAME=`ls -1d ${PKG_NAME}* | tail -1` # print out packages info dpkg-deb --info ${PKG_FULLNAME} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then echo '###' information given for ${PKGDIR} fi fi # that's all folks!