#!/bin/sh # http://www.phys.ethz.ch/~franklin/Projects/dphys-pkgtools/makelocalsite # = /usr/bin/makelocalsite # - build/ensure an local packages site file tree # (- delete duplicate (old and new version) packages) # - link "all" packages into corresponding "${CONF_ARCH}" directories # - generate override files to stop Debian complaining # - generate Packages[.gz] and Sources[.gz] for local package site # author Neil Franklin, last modification 2004.07.23 # copyright ETH Zuerich Physics Departement, # use under either BSD or GPL license # this script is intended to be run as normal user, with access to the server # to use this: # - make an http virtualserver or directory in an http server (= base URL) # this will contain an Debian-like package structure # - place your local packages within that base URL: # dists/woody/local//[source|binary-*]//*.deb # (this is done automatically by makesourcepackage -u) # - run this script, possibly with parameter(s) # - binary-all packages are auto-linked from binary-${CONF_ARCH} # - override files are generated from the packages # - Packages, Packages.gz, Sources, Sources.gz are generated, takes while :-) # (this is also done automatically by makesourcepackage -u) # - add the base URL to your clients /etc/apt/sources.list # - run apt-get update, then apt-get install as you wish ### ------ 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 # 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 # what architecture we use # this is used to link *_all.deb into *_${CONF_BINARCH}.deb # presently we can only handle single architecture package sites CONF_BINARCH=i386 # --- DEBUG_*, various debugging settings # set this to output debug state info after each step, see also -v option #DEBUG_PRINT_STEP=yes # --- SYS_*, various system internal values # path for packages we put on our server # this is set the same in makesourcepackage SYS_OWNPACKAGES=dists/woody/local # --- config file stuff # what we are # same config files used in makesourcepackage 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 b) # base: upload generated package files to base directory CONF_PKG_BASE=$1 shift 1 ;; 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] section [section ...] options: -b baseaddr base: upload generated package files to this base directory -v verbose: show progress (debug information) -h help: output this text, and then abort operation section: must be section part 1 name (such as main or non-free or contrib) or multiple of them 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 [ $# = 0 ] ; then # user did not give an parameter (package name), or gave multiple /bin/echo "$0: ERROR: missing section name(s) to work on" >&2 /bin/echo # call self with -h to display help $0 -h exit 1 fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' sections: ${SECTIONS} fi # --- set work environment # ensure we have an work directory, environment sane if [ ! -d ${CONF_PKG_BASE} ] ; then /bin/echo $0: ERROR: work directory ${CONF_PKG_BASE} not found exit 1 fi # switch to our packages file tree, so all paths can be shorter relative ones cd ${CONF_PKG_BASE} # --- check if demanded sections are valid # only process valid sections, else massive error cascade and junk files while [ x$1 != x ] ; do if [ x`/bin/ls -1d ${SYS_OWNPACKAGES}/$1 2> /dev/null` = x ] ; then /bin/echo "$0: ERROR: there exists no section $1" >&2 exit 1 fi SECTIONS="${SECTIONS} $1" shift 1 done if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '###' sections: ${SECTIONS} fi # -- handle each section for SECTION in ${SECTIONS}; do # --- set up for this section # stuff to work on B_ALL=${SYS_OWNPACKAGES}/${SECTION}/binary-all B_ARCH=${SYS_OWNPACKAGES}/${SECTION}/binary-${CONF_BINARCH} SOURCE=${SYS_OWNPACKAGES}/${SECTION}/source # --- eliminate duplicate/multicate (new and older) versions of packages # tidy up "all" /bin/echo duplicate removing ${SECTION}/binary-all .deb ... for DEB in ${B_ALL}/*/*.deb ; do if [ -e ${DEB} ]; then PKG=`/usr/bin/basename ${DEB}` NAME=`/bin/echo ${PKG} | /usr/bin/cut -f 1 -d "_"` if [ `/bin/ls -1 ${B_ALL}/*/${NAME}_*.deb | /usr/bin/wc -l` != 1 ] ; then # time sort -tr may fail for links, doesn't matter, will remake anyway NEWEST=`/bin/ls -1tr ${B_ALL}/*/${NAME}_*.deb | /usr/bin/tail -1` /bin/mv ${NEWEST} .tmp.${NAME}.deb /bin/rm ${B_ALL}/*/${NAME}_*.deb /bin/mv .tmp.${NAME}.deb ${NEWEST} fi fi done # tidy up "${CONF_BINARCH}" /bin/echo duplicate removing ${SECTION}/binary-${CONF_BINARCH} .deb ... for DEB in ${B_ARCH}/*/*.deb ; do if [ -e ${DEB} ]; then PKG=`/usr/bin/basename ${DEB}` NAME=`/bin/echo ${PKG} | /usr/bin/cut -f 1 -d "_"` if [ `/bin/ls -1 ${B_ARCH}/*/${NAME}_*.deb | \ /usr/bin/wc -l` != 1 ] ; then # time sort -tr may fail for links, doesn't matter, will remake anyway NEWEST=`/bin/ls -1tr ${B_ARCH}/*/${NAME}_*.deb | /usr/bin/tail -1` /bin/mv ${NEWEST} .tmp.${NAME}.deb /bin/rm ${B_ARCH}/*/${NAME}_*.deb /bin/mv .tmp.${NAME}.deb ${NEWEST} fi fi done # tidy up source # these do not generate error messages, so keep them for archival purpose # --- links from binary-${CONF_BINARCH} to binary-all # remove old ones from ${CONF_BINARCH} /bin/echo link deleting old ${SECTION}/binary-${CONF_BINARCH} ... for DEB in ${B_ARCH}/*/*_all.deb ; do if [ -L ${DEB} ] ; then /bin/rm -f ${DEB} fi done # generate new ones /bin/echo link making new ${SECTION}/binary-${CONF_BINARCH} to binary-all ... for DEB in ${B_ALL}/*/*.deb ; do if [ -e ${DEB} ]; then # extract last directory name in path (= section) SEC=`/usr/bin/dirname ${DEB}` while [ x`/bin/echo ${SEC} | /bin/grep '/'` != x ] ; do SEC=`/bin/echo ${SEC} | /usr/bin/cut -f 2- -d '/'` done PKG=`/usr/bin/basename ${DEB}` # ensure there is an ${CONF_BINARCH} directory for this package section if [ ! -d ${B_ARCH}/${SEC} ] ; then /bin/mkdir -p ${B_ARCH}/${SEC} if [ x${GROUP} != x ] ; then /bin/chgrp ${CONF_GROUP} ${B_ARCH}/${SEC} /bin/chmod 2775 ${B_ARCH}/${SEC} fi fi /bin/ln -s ../../binary-all/${SEC}/${PKG} \ ${B_ARCH}/${SEC} fi done if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '### all packages linked:' /bin/ls -al ${B_ARCH}/*/*.deb 2> /dev/null fi # --- override files # ensure there is an directory for then if [ ! -d indices ] ; then /bin/mkdir -p indices if [ x${GROUP} != x ] ; then /bin/chgrp ${GROUP} indices /bin/chmod 2775 indices fi fi # stuff to work on OVRS=indices/override.woody.${SECTION}.src OVRB=indices/override.woody.${SECTION} # generate source override files /bin/echo override making ${SECTION}.src ... # delete old file and its owner, else /bin/chmod complains /bin/rm ${OVRS} # start empty file, for loop using >> /bin/echo -n > ${OVRS} # here we need to evaluate .dsc files, as .tar.gz no recognizable content for DSC in ${SOURCE}/*/*.dsc ; do if [ -e ${DSC} ]; then DIR=`/usr/bin/dirname ${DSC}` TAR=`/bin/grep '.* [0-9]* .*\.tar\.gz' ${DSC} | /usr/bin/cut -f 4 -d " "` if [ x`/bin/echo ${TAR} | /bin/grep '\.orig\.'` = x ] ; then # simple .tar.gz file, extract control from that /bin/tar zxvf ${DIR}/${TAR} -O "*/debian/control" > .ctrl 2> /dev/null else # combination of .orig.tar.gz + .diff.gz files, reconstruct from .diff DIFF=`/bin/grep ' .* [0-9]* .*\.diff\.gz' ${DSC} | \ /usr/bin/cut -f 4 -d " "` /bin/zcat ${DIR}/${DIFF} | \ /bin/sed -n -e '/^+++.*\/debian\/control$/,/^---/p' | /bin/grep '^+' | /usr/bin/cut -f 2 -d '+' > .ctrl fi # use head -1 here because multi-package sources have repeat lines PKG=`/bin/grep "Source: " .ctrl | head -1 | /usr/bin/cut -f 2 -d " "` PRI=`/bin/grep "Priority: " .ctrl | head -1 | /usr/bin/cut -f 2 -d " "` SEC=`/bin/grep "Section: " .ctrl | head -1 | /usr/bin/cut -f 2 -d " "` if [ x${PKG} != x -a x${PRI} != x -a x${SEC} != x ]; then /bin/echo -e "${PKG}\t${PRI}\t${SEC}" >> ${OVRS} else /bin/echo $0: WARNING: Source ${DSC} incomplete control file, ommitted if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/cat .ctrl fi fi /bin/rm .ctrl fi done # eliminate duplicates (2 versions of same package), so no warning /usr/bin/sort ${OVRS} | /usr/bin/uniq > ${OVRS}.tmp /bin/mv ${OVRS}.tmp ${OVRS} # we have multiple users adding packages, so they need group access here if [ x${GROUP} != x ] ; then /bin/chgrp ${GROUP} ${OVRS} /bin/chmod 664 ${OVRS} fi # generate binary override files, similar code as above /bin/echo override making ${SECTION} ... /bin/rm ${OVRB} /bin/echo -n > ${OVRB} # here we need to evaluate .deb files, as they contain everything # only search ${CONF_BINARCH}, as all .all packages have links in there for DEB in ${B_ARCH}/*/*.deb ; do if [ -e ${DEB} ]; then PKG=`/usr/bin/dpkg-deb --info ${DEB} | /bin/grep "Package: " | /usr/bin/cut -f 3 -d " "` PRI=`/usr/bin/dpkg-deb --info ${DEB} | /bin/grep "Priority: " | /usr/bin/cut -f 3 -d " "` SEC=`/usr/bin/dpkg-deb --info ${DEB} | /bin/grep "Section: " | /usr/bin/cut -f 3 -d " "` /bin/echo -e "${PKG}\t${PRI}\t${SEC}" >> ${OVRB} fi done /usr/bin/sort ${OVRB} | /usr/bin/uniq > ${OVRB}.tmp /bin/mv ${OVRB}.tmp ${OVRB} if [ x${GROUP} != x ] ; then /bin/chgrp ${GROUP} ${OVRB} /bin/chmod 664 ${OVRB} fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '### overviews generated:' /bin/ls -al ${OVRS} ${OVRB} fi # --- source and package lists # check for stray files, else these are not in override # and dpkg-scanpackages shouts then for DEB in ${SECTION}/*.tar.gz ${B_ALL}/*.deb ${B_ARCH}/*.deb ; do if [ -e ${DEB} ] ; then echo $0: WARNING: missplaced package file: ${DEB} fi done # generate source lists /bin/echo sources list making ${SECTION}/source ... if [ -d ${SOURCE} ] ; then /usr/bin/fakeroot /usr/bin/dpkg-scansources \ ${SOURCE} ${OVRS} > ${SOURCE}/Sources /usr/bin/fakeroot /bin/gzip < ${SOURCE}/Sources > ${SOURCE}/Sources.gz fi # generate "all" package lists /bin/echo packages list making ${SECTION}/binary-all ... if [ -d ${B_ALL} ] ; then /usr/bin/fakeroot /usr/bin/dpkg-scanpackages \ ${B_ALL} ${OVRB} > ${B_ALL}/Packages /usr/bin/fakeroot /bin/gzip < ${B_ALL}/Packages > ${B_ALL}/Packages.gz fi # generate "${CONF_BINARCH}" package lists /bin/echo packages list making ${SECTION}/binary-${CONF_BINARCH} ... if [ -d ${B_ARCH} ] ; then /usr/bin/fakeroot /usr/bin/dpkg-scanpackages \ ${B_ARCH} ${OVRB} > ${B_ARCH}/Packages /usr/bin/fakeroot /bin/gzip < ${B_ARCH}/Packages > ${B_ARCH}/Packages.gz fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo '### lists generated:' /bin/ls -al ${SOURCE}/Sources* ${B_ALL}/Packages* ${B_ARCH}/Packages* fi done