diff options
author | Daniel Burrows <dburrows@debian.org> | 2007-07-08 10:26:59 -0700 |
---|---|---|
committer | Daniel Burrows <dburrows@debian.org> | 2007-07-08 10:26:59 -0700 |
commit | 3e7c190b7a1cc393980ae77e9aa7881e83c4723c (patch) | |
tree | c6c8a95830b80424838a0f7692cea1b89c3153d6 /aptitude-run-state-bundle | |
parent | 435233b9835c7e8986bd16c6c4d598c3df97ecc0 (diff) | |
download | aptitude-3e7c190b7a1cc393980ae77e9aa7881e83c4723c.tar.gz |
Add two utility scripts to the package that codify the process of snapshotting the state and running with a state snapshot.
Diffstat (limited to 'aptitude-run-state-bundle')
-rwxr-xr-x | aptitude-run-state-bundle | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/aptitude-run-state-bundle b/aptitude-run-state-bundle new file mode 100755 index 00000000..07b1247e --- /dev/null +++ b/aptitude-run-state-bundle @@ -0,0 +1,111 @@ +#!/bin/bash + +NO_CLEAN=0 +STATEDIR=0 +UNPACK_ONLY=0 +HELP=0 + +DONE=0 +while [ $DONE = 0 ] +do + case "$1" in + --no-clean ) + NO_CLEAN=1 + shift + ;; + --really-clean ) + NO_CLEAN=0 + shift + ;; + --statedir ) + STATEDIR=1 + NO_CLEAN=1 + shift + ;; + --unpack ) + UNPACK_ONLY=1 + shift + ;; + --help ) + HELP=1 + shift + ;; + * ) + DONE=1 + ;; + esac +done + +if ( [ $UNPACK_ONLY = 0 ] && [ "$#" -lt 1 ] ) || + ( [ $UNPACK_ONLY = 1 ] && [ "$#" -ne 1 ] ) || + [ $HELP = 1 ] +then + echo "Usage: $0 [options] <input-file> [<program> [arguments ...]]" + echo + echo "This command will unpack the given archive of aptitude state" + echo "information, then invoke the given program with the given" + echo "list of arguments, passing appropriate -o options to cause" + echo "aptitude to use the contents of that archive as its global" + echo "data store." + echo + echo "Options:" + echo " --help Display this message and exit." + echo " --no-clean Do not remove the temporary directory after" + echo " invoking aptitude." + echo " --really-clean Remove the state directory, even if --statedir" + echo " was passed as an argument." + echo " --statedir The <input-file> is an unpacked aptitude bundle," + echo " not a bundle file; implicitly sets --no-clean." + echo " --unpack Just unpack the <input-file>, don't run aptitude." + exit 1 +fi + +INPUTFILE="$1" +shift + +if [ "$#" -lt 1 ] +then + PROGRAM=aptitude +else + PROGRAM="$2" + shift +fi + +if [ $STATEDIR = 0 ] +then + tempdir=$(mktemp -p ${TMPDIR:-/tmp} -d aptitudebug.XXXXXXXXX) || exit 1 + if [ -z "$tempdir" ] + then + exit 1 + fi +else + tempdir=$INPUTFILE +fi + +trap ' +if [ $NO_CLEAN = 1 ] +then echo "Leaving final state in $tempdir" +else echo "Removing $tempdir"; rm -fr $tempdir +fi' 0 + +if [ $STATEDIR = 0 ] +then + if [ -d "$INPUTFILE" ] + then + echo "Can't use $INPUTFILE as the input bundle: it's a directory." + exit 1 + fi + if ! [ -f "$INPUTFILE" ] + then + echo "Can't use $INPUTFILE as the input bundle: file not found." + exit 1 + fi + (gunzip -c < "$INPUTFILE") | (cd "$tempdir" && tar x) || exit 1 +fi + +if [ $UNPACK_ONLY = 1 ] +then + exit 0 +fi + +"$PROGRAM" -o "Dir=$tempdir" -o "Dir::State::status=$tempdir/var/lib/dpkg/status" "$@" |