2005-12-12 21:47:35 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Parameter: LISTE ACTION
|
|
|
|
# z.B. ./get_files programme download
|
|
|
|
#
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
# die Key-Server muessen wohl einzeln angegeben werden - somit einzelne Direktiven
|
|
|
|
KEY_SERVERS="x-hkp://pgp.mit.edu --keyserver hkp://subkeys.pgp.net"
|
|
|
|
|
|
|
|
function download_file()
|
|
|
|
{
|
|
|
|
local QUELLE=$(grep "^$1[[:space:]]" $URL_FILE | cut -f 2)
|
2006-12-29 16:35:05 +01:00
|
|
|
local ZIEL=$DEST_DIR/$1
|
|
|
|
# leider sind die exitcodes von wget derzeit noch nicht zuverlaessig (< v1.11)
|
|
|
|
wget --continue --output-document "$ZIEL" "$QUELLE"
|
|
|
|
# loesche die Datei, falls sie existiert jedoch leer ist
|
|
|
|
test -e "$ZIEL" -a ! -s "$ZIEL" && rm "$ZIEL"
|
2005-12-12 21:47:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function verify_file()
|
|
|
|
{
|
|
|
|
# eventuell die Datei herunterladen
|
|
|
|
[ ! -e "$DEST_DIR/$1" ] && download_file "$1"
|
|
|
|
[ ! -e "$DEST_DIR/$1" ] && return 1
|
|
|
|
# Signatur-URL ermitteln
|
|
|
|
local SIG_URL=$(grep "^$1[[:space:]]" $URL_FILE | cut -f 3)
|
|
|
|
# bei fehlender Signatur erfolgreich abbrechen
|
|
|
|
[ -z "$SIG_URL" ] && return 0
|
|
|
|
# Signatur herunterladen
|
|
|
|
local SIG_FILE=$DEST_DIR/$(basename "$SIG_URL")
|
2006-04-21 11:36:51 +02:00
|
|
|
# html-encodierte Leerzeichen wiederherstellen
|
|
|
|
SIG_FILE=${SIG_FILE//\%20/ }
|
2005-12-12 21:47:35 +01:00
|
|
|
[ ! -e "$SIG_FILE" ] && wget --output-document "$SIG_FILE" "$SIG_URL"
|
|
|
|
# pruefen - notfalls den Schluessel importieren
|
|
|
|
# erstmal Ausgabe unterdruecken
|
2006-12-29 16:35:05 +01:00
|
|
|
if gpg --quiet --keyserver $KEY_SERVERS --keyserver-options auto-key-retrieve \
|
|
|
|
--verify "$SIG_FILE" "$DEST_DIR/$1" &>/dev/null
|
2005-12-12 21:47:35 +01:00
|
|
|
then return 0
|
2006-12-29 16:35:05 +01:00
|
|
|
else # nochmal - diesmal mit Fehlerausgabe
|
|
|
|
gpg --quiet --keyserver $KEY_SERVERS --keyserver-options auto-key-retrieve \
|
|
|
|
--verify "$SIG_FILE" "$DEST_DIR/$1"
|
|
|
|
# loesche die heruntergeladene Datei und die Signatur falls die
|
|
|
|
# Verifikation fehlschlaegt
|
|
|
|
rm "$DEST_DIR/$1" "$SIG_FILE"
|
|
|
|
echo "Die heruntergeladene Datei und die Signatur-Datei wurden geloescht."
|
|
|
|
echo "Versuche es nochmal ..."
|
|
|
|
return 1
|
2005-12-12 21:47:35 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
########### main ############
|
|
|
|
|
2006-06-09 23:21:33 +02:00
|
|
|
if [ $# -lt 2 ]
|
|
|
|
then echo "wrong parameters: $@"
|
|
|
|
echo
|
|
|
|
echo "Syntax: $(basename $0) DATEI_LISTE ACTION [DESTINATION]"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
2005-12-12 21:47:35 +01:00
|
|
|
URL_FILE=$(dirname $0)/${1}.lst
|
|
|
|
DEST_DIR=$(dirname $0)/${1}
|
|
|
|
shift
|
|
|
|
[ ! -e "$URL_FILE" ] && echo "Die Datei ($URL_FILE) existiert nicht!" && exit 2
|
|
|
|
[ -e "$DEST_DIR" ] || mkdir -p "$DEST_DIR"
|
|
|
|
|
|
|
|
ACTION=help
|
|
|
|
[ $# -gt 0 ] && ACTION=$1 && shift
|
|
|
|
|
|
|
|
|
|
|
|
case "$ACTION" in
|
|
|
|
download )
|
2007-09-27 17:19:48 +02:00
|
|
|
grep -v "^#" "$URL_FILE" | cut -f 1 | while read a
|
2005-12-12 21:47:35 +01:00
|
|
|
do [ ! -e "$DEST_DIR/$a" ] && download_file "$a"
|
|
|
|
done
|
|
|
|
# ExitCode auf Null setzen
|
|
|
|
true
|
|
|
|
;;
|
|
|
|
verify )
|
2007-09-27 17:19:48 +02:00
|
|
|
grep -v "^#" "$URL_FILE" | cut -f 1 | while read a
|
2005-12-12 21:47:35 +01:00
|
|
|
do if verify_file "$a"
|
|
|
|
then true
|
|
|
|
else echo "Verification of '$a' failed ..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
clean )
|
|
|
|
# Datei loeschen
|
2007-09-27 17:19:48 +02:00
|
|
|
grep -v "^#" "$URL_FILE" | cut -f 1 | while read a; do rm -f "$DEST_DIR/$a"; done
|
2005-12-12 21:47:35 +01:00
|
|
|
# Signatur loeschen, falls vorhanden
|
2007-09-27 17:19:48 +02:00
|
|
|
grep -v "^#" "$URL_FILE" | cut -f 3 | sed /^$/d | while read a; do rm -f "$DEST_DIR/$(basename $a)"; done
|
2005-12-12 21:47:35 +01:00
|
|
|
;;
|
|
|
|
install )
|
|
|
|
[ $# -eq 0 ] && echo 'You need to specify the destination directory!' && exit 1
|
|
|
|
INST_DIR=$1
|
|
|
|
[ ! -e "$INST_DIR" ] && mkdir -p "$INST_DIR"
|
2007-09-27 17:19:48 +02:00
|
|
|
grep -v "^#" "$URL_FILE" | cut -f 1 | while read a
|
2005-12-12 21:47:35 +01:00
|
|
|
do [ -e "$DEST_DIR/$a" ] || download_file "$a"
|
|
|
|
cp "$DEST_DIR/$a" "$INST_DIR/"
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo "Syntax: $0 LIST { download | install | clean } [ZIEL_VERZEICHNIS]"
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|