#!/bin/sh
# Small script using apt-ftparchive to update a debian pool.
# Modifing the following vars and having a good apt-ftparchive.conf
# with FileList "$(DIST)/$(SECTION)/$(ARCH)/filelist" should suffice.
#
# POOLDIR tree should be ${POOLDIR}/${DIST}/${SECTION}/<AnyPkgSubtree>, or you
# will need to modify phase 1 loop.

ARCHIVEDIR=${HOME}/public_html/debian
POOLDIR=${ARCHIVEDIR}/pool

FTPARCHIVEDIR=${ARCHIVEDIR}/ftparchive
FTPARCHIVECONF=${ARCHIVEDIR}/apt-ftparchive.conf

# remember to update opts in ${FTPARCHIVECONF} according to them
SECTIONS="postfix postfix-ipv6 ANN"
ARCHS="all i386"
DISTS="woody sid"



### Do not touch the above code unless you know what you are doing.

# 1 - Create filelist files
TIMESTAMP=`date +%Y%m%d_%s` # YYYYMMGG_EPOCH to be readable and unique.
for ARCH in ${ARCHS}; do
  for DIST in ${DISTS}; do
    for SECTION in ${SECTIONS}; do
      RESULTFILE=${FTPARCHIVEDIR}/dists/${DIST}/${SECTION}/${ARCH}/filelist
      
	  # create a new filelist with today's timestamp
	  find ${POOLDIR}/${DIST}/${SECTION}/ -name \*_${ARCH}.deb > \
      	${RESULTFILE}.${TIMESTAMP}

	  # and update symlink to the generic one used in ${FTPARCHIVECONF}
	  # so you can revert to old list if needed
	  rm -f ${RESULTFILE}
	  ln -s `basename ${RESULTFILE}.${TIMESTAMP}` ${RESULTFILE}
      echo "updated ${RESULTFILE}"
    done
  done
done

for DIST in ${DISTS}; do
	for SECTION in ${SECTIONS}; do
		RESULTFILE=${FTPARCHIVEDIR}/dists/${DIST}/${SECTION}/filelist.sources
		echo ${RESULTFILE}
		find ${POOLDIR}/sources/ -name \*.dsc > \
	      	${RESULTFILE}.${TIMESTAMP}

		# and update symlink to the generic one used in ${FTPARCHIVECONF}
		# so you can revert to old list if needed
		rm -f ${RESULTFILE}
		ln -s `basename ${RESULTFILE}.${TIMESTAMP}` ${RESULTFILE}
    	echo "updated ${RESULTFILE}"
	done
done

# 2 - generate Packages 
apt-ftparchive generate ${FTPARCHIVECONF}

