-#/bin/sh
+#/bin/bash
+## package-update.sh -- Create a package archive from the elpa repository
-ROOT=$1
-LOG=$ROOT/update-log
-PKGROOT=$ROOT/packages
-ADMINROOT=$ROOT/admin
+## Usage: ./package-update.sh DEST [FULL-UPDATE]
+##
+## This creates a package archive beginning in DEST.
+##
+## The package archive itself is created in DEST/packages. This dir
+## contains the package files.
+##
+## If a second argument FULL-UPDATE is specified (whatever its value),
+## also create the following:
+## - the archive admin scripts in DEST/admin
+## - a tarball containing the entire archive in
+## DEST/packages/emacs-packages-latest.tgz
+## - the Org mode daily package
-TARBALL=$PKGROOT/emacs-packages-latest.tgz
-TARBALL_ROOT="emacs-24.1-packages-`/bin/date +'%F'`"
+PATH="/bin:/usr/bin:/usr/local/bin:${PATH}"
+## Remove any trailing slash from DEST
+DEST=${1%/}
+FULL=$2
-REPO=bzr://bzr.savannah.gnu.org/emacs/elpa
-REPO_PACKAGES=$REPO/packages
-REPO_ADMIN=$REPO/admin
+EMACS=emacs
+BZR=bzr
+TAR=tar
+REPO_PACKAGES=packages
-if [ -z $ROOT ]; then
- echo "Syntax: $0 HOMEDIR"
+## Parse arguments
+if [ -z $DEST ]; then
+ echo "Syntax: $0 DEST [fetch-extras-boolean]"
exit 1
-elif [ -d $ROOT ]; then
- echo "Installing into '$ROOT', log is '$LOG'"
- echo "Installing into '$ROOT'" > $LOG
+elif [ -d $DEST ]; then
+ cd $DEST
+ DEST_FULL=$(pwd)
+ PKGROOT=$DEST_FULL/packages
+ TMP_PKGROOT=$DEST_FULL/packages-new
+ echo "Installing into '$DEST_FULL'"
+ if [ -z $FULL ]; then
+ echo "Base archive update only (pass second arg for full update)."
+ else
+ echo "Performing full archive update."
+ TARBALL=$PKGROOT/emacs-packages-latest.tgz
+ TARBALL_ROOT="emacs-24.1-packages-`/bin/date +'%F'`"
+ ADMINROOT=$DEST_FULL/admin
+ REPO_ADMIN=admin
+ fi
else
- echo "Sorry but $ROOT is not a directory, aborting."
+ echo "Sorry but $DEST is not a directory, aborting."
exit 1
fi
+## Change to the bzr root directory
+REPO_ROOT_DIR=`$BZR root`;
+if [ -z $REPO_ROOT_DIR ]; then
+ "This script should be run from a bzr repository, aborting."
+ exit 1
+else
+ cd $REPO_ROOT_DIR;
+fi
+
+## Create the working directory that will be the world-facing copy of
+## the package archive base.
+echo "Exporting packages to temporary working directory $TMP_PKGROOT"
+rm -rf $TMP_PKGROOT
+$BZR export $TMP_PKGROOT $REPO_PACKAGES
+
+## If second arg is provided, copy in the admin directory.
+if [ -z $FULL ]; then
+ echo "Skipping admin directory"
+else
+ echo "Exporting admin scripts to $ADMINROOT"
+ rm -rf $ADMINROOT
+ $BZR export $ADMINROOT $REPO_ADMIN
+fi
-## Create emacs-packages-latest.tgz
-echo "Exporting packages into $TARBALL (root = $TARBALL_ROOT)" >> $LOG
-/usr/bin/bzr export --format=tgz --root=$TARBALL_ROOT $TARBALL $REPO_PACKAGES
-## Create the world-facing copy
-echo "[$TMPROOT -> $PKGROOT] Creating the world-facing package repository copy in $PKGROOT" >> $LOG
-TMPROOT=$PKGROOT-new
-rm -rf $TMPROOT
-/usr/bin/bzr export $TMPROOT $REPO_PACKAGES
+cd $TMP_PKGROOT
-echo "[$TMPROOT -> $PKGROOT] Running the post-export fetchers in $ADMINROOT against $TMPROOT" >> $LOG
-rm -rf $ADMINROOT
-bzr export $ADMINROOT $REPO_ADMIN
-# Copy the org daily package from orgmode.org
-echo "[$TMPROOT -> $PKGROOT] Running the post-export org-mode fetcher as '$ADMINROOT/org-synch.sh $TMPROOT $ADMINROOT'" >> $LOG
-$ADMINROOT/org-synch.sh $TMPROOT $ADMINROOT >> $LOG 2>&1
+## If second arg is provided, grab the Org daily
+if [ -z $FULL ]; then
+ echo "Not fetching Org daily from orgmode.org"
+else
+ echo "Fetching Org daily from orgmode.org"
+ pkgname=`curl -s http://orgmode.org/elpa/|perl -ne 'push @f, $1 if m/(org-\d{8})\.tar/; END { @f = sort @f; print "$f[-1]\n"}'`
+ wget -q http://orgmode.org/elpa/${pkgname}.tar -O ${pkgname}.tar
+ if [ -f ${pkgname}.tar ]; then
+ tar xf ${pkgname}.tar
+ rm -f ${pkgname}.tar
+ mv ${pkgname} org
+ fi
+fi
-echo "[$TMPROOT -> $PKGROOT] Moving $TMPROOT to $PKGROOT" >> $LOG
-/bin/mv $PKGROOT $PKGROOT-old
-/bin/mv $TMPROOT $PKGROOT
-/bin/rm -rf $PKGROOT-old
+## Call `batch-make-archive' to generate archive-contents, the readme
+## files, etc.
+$EMACS -batch -l $REPO_ROOT_DIR/admin/archive-contents.el -f batch-make-archive
-/bin/chmod -R a+rX $PKGROOT
+## Tar up the multi-file packages.
+echo "Creating multi-file package tarballs in $TMP_PKGROOT"
+for pt in *; do
+ if [ -d $pt ]; then
+ echo "Creating tarball $TMP_PKGROOT/$pt.tar"
+ tar -cf $pt.tar $pt --remove-files
+ fi
+done
+
+## Move the working directory to its final location
+cd ..
+rm -rf $PKGROOT-old
+if [ -d $PKGROOT ]; then
+ mv $PKGROOT $PKGROOT-old
+fi
+mv $TMP_PKGROOT $PKGROOT
+rm -rf $PKGROOT-old
+
+## If doing a full update, make a tarball of the entire archive.
+if [ -z $FULL ]; then
+ echo "Skipping archive tarball"
+else
+ echo "Exporting packages into $TARBALL (root = $TARBALL_ROOT)"
+ cd $REPO_ROOT_DIR
+ $BZR export --format=tgz --root=$TARBALL_ROOT $TARBALL $REPO_PACKAGES
+fi
-echo "Update complete at" `/bin/date` >> $LOG
+chmod -R a+rX $PKGROOT
+echo "Update complete at" `/bin/date`