aboutsummaryrefslogtreecommitdiff
path: root/debian-dl
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2014-09-18 16:36:19 -0300
committerSilvio Rhatto <user@example.org>2014-09-18 16:36:19 -0300
commitb9a596c1d2fceb73564eacdc49b1448873c8fe1f (patch)
treeb64157909c6316fb0bd71445c9688f021c7f62ab /debian-dl
downloaddownloaders-b9a596c1d2fceb73564eacdc49b1448873c8fe1f.tar.gz
downloaders-b9a596c1d2fceb73564eacdc49b1448873c8fe1f.tar.bz2
Initial import
Diffstat (limited to 'debian-dl')
-rwxr-xr-xdebian-dl87
1 files changed, 87 insertions, 0 deletions
diff --git a/debian-dl b/debian-dl
new file mode 100755
index 0000000..3558085
--- /dev/null
+++ b/debian-dl
@@ -0,0 +1,87 @@
+#!/bin/bash
+#
+# Simple Debian image downloader.
+#
+
+# Parameters
+HASHES="MD5SUMS SHA1SUMS SHA256SUMS SHA512SUMS"
+
+# Arguments
+BASENAME="`basename $0`"
+URL="$1"
+BASE="`dirname $URL`"
+RATE="$2"
+FILENAME="`basename $URL`"
+
+# Syntax
+if [ -z "$1" ]; then
+ echo "usage: $BASENAME <image-url>"
+ exit 1
+fi
+
+# Determine signature extension
+if echo $FILENAME | grep -qe '^debian-live'; then
+ SIGN="sig"
+else
+ SIGN="sign"
+fi
+
+# Fetch hashes
+for hash in $HASHES; do
+ wget -c $BASE/$hash
+ wget -c $BASE/$hash.$SIGN
+done
+
+# Determine transfer method
+if echo $FILENAME | grep -qe '.jigdo$'; then
+ # Check for jigdo
+ if ! which jigdo-lite &> /dev/null; then
+ echo "Please install jigdo-file"
+ exit 1
+ fi
+
+ # Get the image using jigdo
+ jigdo-lite $URL
+
+ # Fix filename
+ FILENAME="`basename $FILENAME .jigdo`.iso"
+elif echo $FILENAME | grep -qe '.zsync$'; then
+ # Check for zsync
+ if ! which zsync &> /dev/null; then
+ echo "Please install zsync"
+ exit 1
+ fi
+
+ # Get the image using zsync
+ zsync $URL
+
+ # Fix filename
+ FILENAME="`basename $FILENAME .zsync`"
+else
+ # Check for wget
+ if ! which wget &> /dev/null; then
+ echo "Please install wget"
+ exit 1
+ fi
+
+ # Set rate limit
+ if [ ! -z "$RATE" ]; then
+ LIMIT="--limit-rate=$RATE"
+ fi
+
+ # Get the image using wget
+ wget -c $LIMIT $URL
+fi
+
+# Check hashes
+for hash in $HASHES; do
+ echo "Checking $FILENAME against $hash file..."
+ check="`echo $hash | tr '[:upper:]' '[:lower:]' | sed -e 's/s$//'`"
+ grep -e "$FILENAME$" $hash | $check -c
+done
+
+# Check hash integrity
+for hash in $HASHES; do
+ echo "Checking $hash.$SIGN..."
+ gpg --verify $hash.$SIGN
+done