make.sh: Introduce DEFAULT_PARALLELISM
[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 # Mount a tmpfs which is big enough to hold the ISO image
35 OUTPUT_DIR="${OUTPUT%/*}"
36
37 mkdir -p "${OUTPUT_DIR}"
38 if ! mount -t tmpfs none "${OUTPUT_DIR}" -o size=512M; then
39         echo "Could not mount tmpfs to ${OUTPUT_DIR}" >&2
40         exit 1
41 fi
42
43 echo "Downloading ${URL}..."
44 if ! download -O "${OUTPUT}" "${URL}"; then
45         echo "Download failed" >&2
46
47         rm -f "${OUTPUT}"
48         exit 1
49 fi
50
51 # Download went well. Checking for MD5 sum
52 if download -O "${OUTPUT}.md5" "${URL}.md5" &>/dev/null; then
53         # Read downloaded checksum
54         read -r md5sum rest < "${OUTPUT}.md5"
55         rm -f "${OUTPUT}.md5"
56
57         # Compute checkum of downloaded image file
58         read -r md5sum_image rest <<< "$(md5sum "${OUTPUT}")"
59
60         if [ "${md5sum}" != "${md5sum_image}" ]; then
61                 echo "MD5 sum mismatch: ${md5sum} != ${md5sum_image}" >&2
62                 exit 2
63         fi
64 fi
65
66 exit 0