Add apt-zephyr hook.
authorAnders Kaseorg <andersk@mit.edu>
Thu, 21 May 2009 04:16:24 +0000 (00:16 -0400)
committerAnders Kaseorg <andersk@mit.edu>
Thu, 21 May 2009 04:16:24 +0000 (00:16 -0400)
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
apt-zephyr/90zephyr [new file with mode: 0644]
apt-zephyr/README [new file with mode: 0644]
apt-zephyr/apt-zephyr [new file with mode: 0755]

diff --git a/apt-zephyr/90zephyr b/apt-zephyr/90zephyr
new file mode 100644 (file)
index 0000000..f2aa9cb
--- /dev/null
@@ -0,0 +1,2 @@
+DPkg::Pre-Install-Pkgs {"/usr/local/sbin/apt-zephyr || :";};
+DPkg::Tools::options::/usr/local/sbin/apt-zephyr::Version "2";
diff --git a/apt-zephyr/README b/apt-zephyr/README
new file mode 100644 (file)
index 0000000..fc20d47
--- /dev/null
@@ -0,0 +1,17 @@
+apt-zephyr hook
+
+Author: Anders Kaseorg <andersk@mit.edu>
+
+Usage: install these files to
+
+/etc/apt/apt.conf.d/90zephyr
+/usr/local/sbin/apt-zephyr
+
+and configure /etc/apt-zephyr.conf, e.g.
+
+CLASS="linerva"
+INSTANCE="apt.$(hostname)"
+
+Valid options include CLASS, INSTANCE, REALM, RECIPIENTS, SIG (default 
+"$(hostname -f)"), OPCODE (default "auto"), ZAUTH (default "", set 
+nonempty to enable).
diff --git a/apt-zephyr/apt-zephyr b/apt-zephyr/apt-zephyr
new file mode 100755 (executable)
index 0000000..54300bd
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/sh
+set -e
+
+# Defaults
+CLASS=
+INSTANCE=
+REALM=
+RECIPIENTS=
+SIG="$(hostname -f)"
+OPCODE=auto
+ZAUTH=
+
+# Read configuration
+. /etc/apt-zephyr.conf
+
+package ()
+{
+    package=$1
+    oldver=$2
+    cmp=$3
+    newver=$4
+
+    if [ "$newver" = '-' ] && [ "$oldver" = '-' ]; then
+       echo "Purging $package"
+    elif [ "$newver" = '-' ]; then
+       echo "Removing $package $oldver"
+    elif [ "$oldver" = '-' ]; then
+       echo "Installing $package $newver"
+    elif [ "$cmp" = '<' ]; then
+       echo "Upgrading $package $oldver to $newver"
+    elif [ "$cmp" = '=' ]; then
+       echo "Reinstalling $package $newver"
+    elif [ "$cmp" = '>' ]; then
+       echo "Downgrading $package $oldver to $newver"
+    else
+       echo "I'm confused: $*"
+    fi
+}
+
+read -r line
+case "$line" in
+    'VERSION 2')
+       while read -r line && [ -n "$line" ]; do :; done
+       while read -r package oldver cmp newver action; do
+           case "$action" in
+               '**CONFIGURE**' | '**REMOVE**')
+                   package "$package" "$oldver" "$cmp" "$newver"
+                   ;;
+               '**ERROR**')
+                   echo "ERROR on $package $newver"
+                   ;;
+           esac
+       done
+       ;;
+    'VERSION *')
+       echo "$0: unrecognized version: $line"
+       ;;
+    '')
+       ;;
+    *)
+       oldpkgs=$(mktemp -t "apt-zephyr-old.XXXXXX") || exit $?
+       newpkgs=$(mktemp -t "apt-zephyr-new.XXXXXX") || exit $?
+       (echo "$line"; cat) | xargs -r -d '\n' dpkg-deb -W | sort -o "$newpkgs"
+       cut -f 1 "$newpkgs" | xargs -r -d '\n' dpkg-query -W | \
+           sort -o "$oldpkgs"
+       join -t '       ' -j 1 -e '-' "$oldpkgs" "$newpkgs" | \
+           while IFS=' ' read -r package oldver newver; do
+           if dpkg --compare-versions "$oldver" lt "$newver"; then
+               package "$package" "$oldver" '<' "$newver"
+           elif dpkg --compare-versions "$oldver" eq "$newver"; then
+               package "$package" "$oldver" '=' "$newver"
+           else
+               package "$package" "$oldver" '>' "$newver"
+           fi
+       done
+       rm -f "$oldpkgs" "$newpkgs"
+       ;;
+esac | \
+    zwrite ${CLASS:+-c "$CLASS"} ${INSTANCE:+-i "$INSTANCE"} ${REALM:+-r "$REALM"} ${SIG:+-s "$SIG"} ${OPCODE:+-O "$OPCODE"} ${ZAUTH:--d} ${RECIPIENTS:+$RECIPIENTS}