4a48686ea9453560065f80bf3a5d945f37f3f525
[ipfire-2.x.git] / src / installer / downloadsource.sh
1 #!/bin/sh
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 IPFire Team <info@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 function download() {
23 wget -U "IPFire-NetInstall/2.x" "$@"
24 }
25
26 if [ $# -lt 2 ]; then
27 echo "$0: Insufficient number of arguments" >&2
28 exit 2
29 fi
30
31 OUTPUT="${1}"
32 URL="${2}"
33
34 echo "Downloading ${URL}..."
35 if ! download -O "${OUTPUT}" "${URL}"; then
36 echo "Download failed" >&2
37
38 rm -f "${OUTPUT}"
39 exit 1
40 fi
41
42 # Download went well. Checking for MD5 sum
43 if download -O "${OUTPUT}.md5" "${URL}.md5" &>/dev/null; then
44 # Read downloaded checksum
45 read -r md5sum rest < "${OUTPUT}.md5"
46 rm -f "${OUTPUT}.md5"
47
48 # Compute checkum of downloaded image file
49 read -r md5sum_image rest <<< "$(md5sum "${OUTPUT}")"
50
51 if [ "${md5sum}" != "${md5sum_image}" ]; then
52 echo "MD5 sum mismatch: ${md5sum} != ${md5sum_image}" >&2
53 exit 2
54 fi
55 fi
56
57 exit 0