aboutsummaryrefslogtreecommitdiff
path: root/debian-dl
blob: 68e24aa1f35cd7c29d6a523b7bcc8760dd291502 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
#
# Simple Debian image downloader.
#

# Parameters
BASENAME="`basename $0`"

# Syntax
if [ -z "$1" ]; then
  echo "usage: $BASENAME <image-url>"
  exit 1
fi

# Arguments
URL="$1"
BASE="`dirname $URL`"
RATE="$2"
FILENAME="`basename $URL`"
SIGN="sign"
HASHES="SHA256SUMS SHA512SUMS"

# 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
  if [ -e "$hash" ]; then
    echo "Checking $FILENAME against $hash file..."
    check="`echo $hash | tr '[:upper:]' '[:lower:]' | sed -e 's/s$//'`"
    grep -e "$FILENAME$" $hash | $check -c
  else
    echo "$BASENAME: cannot check $hash: file not found, skipping"
  fi
done

# Check hash integrity
for hash in $HASHES; do
  if [ -e "$hash" ]; then
    echo "Checking $hash.$SIGN..."
    gpg --verify $hash.$SIGN
  fi
done