Index: /main/trunk/package-kits/linux/repos/ReadMe
===================================================================
--- /main/trunk/package-kits/linux/repos/ReadMe	(revision 29690)
+++ /main/trunk/package-kits/linux/repos/ReadMe	(revision 29690)
@@ -0,0 +1,43 @@
+================================================================================
+ General:
+================================================================================
+Contains scripts for generating a greenstone package repository.
+
+./repos/
+    The generated root directory for the package repository files.
+    Contains all the files, including any databases necessary to maintain the
+    repository.
+
+./conf.sh
+    Contains config variables, and functions used by multiple scripts
+
+./gpg
+    Generates a new GPG key if necessary, then copies the public GPG key to the
+    repos directory.
+    Also generates a gpg.key.id file, which allows other scripts to know the
+    GPG key-id without asking the user.
+
+================================================================================
+ Package Manager Implementations:
+================================================================================
+These scripts are used to set up the repositories for specific package-managers,
+and to maintain the repositories for those package-managers (e.g. adding new
+versions of packages)
+
+./apt
+    Generates an apt package repository under ./repos/
+    reprepro is used to manage the repository, so this script just generates the
+    reprepro config, and wraps reprepro to automate some things.
+    
+================================================================================
+ Deployment:
+================================================================================
+./sync
+    Uses rsync to copy the packages somewhere (e.g. to a webserver for
+    distribution)
+    Excludes files based on ./sync-exclude.list
+
+./sync-exclude.list
+    A list of paths (relative to ./repos/) to exclude when syncing
+    Used to stop internal database or config files from being viewable by users
+
Index: /main/trunk/package-kits/linux/repos/apt
===================================================================
--- /main/trunk/package-kits/linux/repos/apt	(revision 29690)
+++ /main/trunk/package-kits/linux/repos/apt	(revision 29690)
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+. $(dirname $0)/conf.sh
+
+reprepro_check() {
+    cd $repos/apt/ || {
+        echo "Repository not found. Have you set it up?" >&2
+        exit 1
+    }
+    test -x `which reprepro` || {
+        echo "Must install reprepro to add packages" >&2
+        exit 1
+    }
+}
+
+help="Options:
+  setup
+  add </path/to/1.deb> ..."
+
+case $1 in
+    setup)
+        mkdir -p $repos || exit 1
+        echo
+        conf=$repos/apt/conf
+        echo "Making reprepro conf dir '$conf'"
+        mkdir -p $conf || exit 1
+        echo
+        if test -f $base/gpg.key.id; then
+            keyid=$(cat $base/gpg.key.id)
+        else
+            gpg --list-keys
+            echo "Enter the keyid of the GPG key to use:"
+            while test -z $keyid; do
+                echo -n "> "
+                read keyid
+            done
+            echo
+        fi
+        echo "Making reprepro distributions file"
+        echo "\
+Origin: $origin
+Label: $label
+Codename: $codename
+Architectures: $arch
+Components: main
+Description: $description
+SignWith: $keyid" | write $conf/distributions
+        echo
+        echo "Making reprepro options file"
+        echo "\
+verbose
+ask-passphrase" | write $conf/options
+        echo
+        echo "Making sources.list file"
+        echo "deb http://$domain/repos/apt $codename main" | write "$repos/apt/sources.list"
+        ;;
+    add)
+        reprepro_check
+        shift
+        reprepro includedeb $codename $@
+        ;;
+    -h|--help|help)
+        echo "$help"
+        ;;
+    *)
+        if test -z "$*"; then
+            echo "$help"
+        else
+            reprepro_check
+            reprepro $@
+        fi
+        ;;
+esac
Index: /main/trunk/package-kits/linux/repos/conf.sh
===================================================================
--- /main/trunk/package-kits/linux/repos/conf.sh	(revision 29690)
+++ /main/trunk/package-kits/linux/repos/conf.sh	(revision 29690)
@@ -0,0 +1,36 @@
+origin="Greenstone"
+label="greenstone"
+codename="greenstone"
+domain="greenstone.org"
+arch="i386 amd64 source"
+description="Apt repository for Greenstone packages"
+base=$(dirname $0)
+repos=$base/repos
+
+y() {
+    echo "$@? [y|n]..." >&2
+    echo -n "> " >&2
+    read cho
+    test "$cho" = "y" -o "$cho" = "Y"
+    return $?
+}
+
+get() {
+    echo "$1? [$2]..." >&2
+    echo -n "> " >&2
+    read cho
+    test -z $cho && {
+        cho=$2
+        echo "Set to default '$cho'" >&2
+    }
+    echo $cho
+}
+
+write() {
+    file=$1
+    if touch $file 2>/dev/null; then
+        cat - > $file
+    else
+        cat - | sudo tee $file
+    fi
+}
Index: /main/trunk/package-kits/linux/repos/gpg
===================================================================
--- /main/trunk/package-kits/linux/repos/gpg	(revision 29690)
+++ /main/trunk/package-kits/linux/repos/gpg	(revision 29690)
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+. $(dirname $0)/conf.sh
+
+mkdir -p $repos || exit 1
+
+test -f "$repos/gpg.key" || {
+    tmpfile="/tmp/greenstone-gpg-$(date +%s)"
+    if y "GPG key missing. Generate new GPG key"; then
+        echo
+        y "Show suggested (more secure) GPG config" && echo "Append the following to ~/.gnupg/gpg.conf:
+
+        # Prioritize stronger algorithms for new keys.
+        default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 BZIP2 ZLIB ZIP Uncompressed
+        # Use a stronger digest than the default SHA1 for certifications.
+        cert-digest-algo SHA512
+        "
+        echo
+        # hack to get the output in order to get the keyid
+        gpg --gen-key | tee $tmpfile
+        keyid=$(tail -2 $tmpfile | head -1 | awk -F'[/ ]' '{print $5}')
+        rm -f $tmpfile
+    else
+        echo
+        if test -f $base/gpg.key.id && y "Existing Key-id file found. Use that"; then
+            keyid=$(cat $base/gpg.key.id)
+        else
+            gpg --list-keys
+            echo "Enter the keyid of the GPG key to use:"
+            while test -z $keyid; do
+                echo -n "> "
+                read keyid
+            done
+        fi
+    fi
+    echo "Adding gpg public key"
+    tmpfile="/tmp/greenstone-gpg-$(date +%s)"
+    gpg --armor --output $tmpfile --export $keyid || exit 1
+    cp $tmpfile $repos/gpg.key
+    rm -f $tmpfile
+    echo $keyid > $base/gpg.key.id
+}
+
Index: /main/trunk/package-kits/linux/repos/sync
===================================================================
--- /main/trunk/package-kits/linux/repos/sync	(revision 29690)
+++ /main/trunk/package-kits/linux/repos/sync	(revision 29690)
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+. $(dirname $0)/conf.sh
+
+test -z "$1" && {
+    echo "Usage: $(basename $0) <output_location>
+  Where <output_location> is any location valid for rsync"
+    exit 1
+}
+
+rsync -avz --exclude-from $(dirname $0)/sync-exclude.list repos/ $1
Index: /main/trunk/package-kits/linux/repos/sync-exclude.list
===================================================================
--- /main/trunk/package-kits/linux/repos/sync-exclude.list	(revision 29690)
+++ /main/trunk/package-kits/linux/repos/sync-exclude.list	(revision 29690)
@@ -0,0 +1,4 @@
+apt/conf
+apt/db
+apt/lists
+apt/incoming
