diff --git a/util/add_tar.sh b/util/add_tar.sh deleted file mode 100755 index 5843a71..0000000 --- a/util/add_tar.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -# Usage: add_tar.sh -# Requires a recent GNU tar for compression autodetect and xz support. - - -TMP=`mktemp -d manned.XXXXXXX` - -# TODO: tar throws an error if there are no man pages. This isn't really an error, though. -tar --warning=no-unknown-keyword -C "$TMP" $3 -xf "$1" --wildcards '*/man/*'\ - && ./add_dir.pl "$TMP" "$2" -RET=$? - -rm -rf "$TMP" -exit $RET - diff --git a/util/arch.sh b/util/arch.sh index 96733ca..1b0d8e6 100755 --- a/util/arch.sh +++ b/util/arch.sh @@ -9,10 +9,7 @@ REPOS="core extra community" DEBUG=false SYSID=1 -CURL="curl -fSs -A manual-page-crawler,info@manned.org" -PSQL="psql -U manned -Awtq" -TMP=`mktemp -d manned.arch.XXXXXX` - +. ./common.sh # Returns 0 if the package is already in the database or if an error occured. # Otherwise adds the package, sets PKGID to the new ID, and returns 1. @@ -67,7 +64,7 @@ checkpkg() { echo "===> $FN" F="$TMP/$REPO/$FILENAME" $CURL "$MIRROR/$REPO/os/i686/$FILENAME" -o "$F" || return - ./add_tar.sh "$F" "$PKGID" + add_tar "$F" "$PKGID" rm -f "$F" } @@ -91,5 +88,3 @@ for r in $REPOS; do rm -rf "$TMP/$r" done -rm -rf "$TMP" - diff --git a/util/common.sh b/util/common.sh new file mode 100644 index 0000000..0c16f3d --- /dev/null +++ b/util/common.sh @@ -0,0 +1,24 @@ + +CURL="curl -fSs -A manual-page-crawler,info@manned.org --limit-rate 500k" +PSQL="psql -U manned -Awtq" + +TMP=`mktemp -d manned.XXXXXX` + +# bash-ism, remove the working directory when we're done. +trap "rm -rf $TMP" EXIT + + + +# Usage: add_tar +# Requires a recent GNU tar for compression autodetect and xz support. +# TODO: tar throws an error if there are no man pages, but this isn't really an +# error. +add_tar() { + DIR=`mktemp -d "$TMP/tar.XXXXXXX"` + tar --warning=no-unknown-keyword -C "$DIR" $3 -xf "$1" --wildcards '*/man/*'\ + && ./add_dir.pl "$DIR" "$2" + RET=$? + rm -rf "$DIR" + return $RET +} + diff --git a/util/cron.sh b/util/cron.sh index 9b6b53b..872c380 100755 --- a/util/cron.sh +++ b/util/cron.sh @@ -1,6 +1,6 @@ #!/bin/sh -PSQL="psql -U manned -Awtq" +. ./common.sh ./arch.sh ./deb.sh ubuntu_active diff --git a/util/deb.sh b/util/deb.sh index 39d8e92..9a2b007 100755 --- a/util/deb.sh +++ b/util/deb.sh @@ -2,10 +2,7 @@ # A fetcher for debian-style repositories. -CURL="curl -fSs -A manual-page-crawler,info@manned.org --limit-rate 500k" -PSQL="psql -U manned -Awtq" -TMP=`mktemp -d manned.deb.XXXXXX` - +. ./common.sh checkpkg() { SYSID=$1 @@ -41,7 +38,7 @@ checkpkg() { if [ "$?" -eq 0 -a -n "$PKGID" ]; then # Old format if [ "`head -c8 \"$FN\"`" = "0.939000" ]; then - tail -n+3 "$FN" | tail -c+"`head -n2 \"$FN\" | tail -n1`" | tail -c+2 | ./add_tar.sh - $PKGID -z + tail -n+3 "$FN" | tail -c+"`head -n2 \"$FN\" | tail -n1`" | tail -c+2 | add_tar - $PKGID -z # New format else @@ -54,7 +51,7 @@ checkpkg() { *) echo "No data.tar found, or unknown compression format."; DATAZ="ERR" ;; esac - [ "$DATAZ" != "ERR" ] && ar p "$FN" "$DATAFN" | ./add_tar.sh - $PKGID $DATAZ + [ "$DATAZ" != "ERR" ] && ar p "$FN" "$DATAFN" | add_tar - $PKGID $DATAZ fi fi @@ -139,7 +136,6 @@ EOP -# TODO: Index stuff from snapshot.debian.org # TODO: backports? # TODO: Debian testing? @@ -377,5 +373,3 @@ debian_snapshot_month() { "$@" -rm -rf "$TMP" -