]>
Commit | Line | Data |
---|---|---|
0f680bcc AF |
1 | #!/bin/sh |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
b8764ff2 | 5 | # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> # |
0f680bcc AF |
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 | ||
c0511f3a MT |
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 | ||
3e1145e1 MT |
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 | ||
c0511f3a MT |
43 | echo "Downloading ${URL}..." |
44 | if ! download -O "${OUTPUT}" "${URL}"; then | |
45 | echo "Download failed" >&2 | |
46 | ||
47 | rm -f "${OUTPUT}" | |
48 | exit 1 | |
0f680bcc AF |
49 | fi |
50 | ||
b8764ff2 PM |
51 | # Download went well. Checking for BLAKE2 sum |
52 | if download -O "${OUTPUT}.b2" "${URL}.b2" &>/dev/null; then | |
c0511f3a | 53 | # Read downloaded checksum |
b8764ff2 PM |
54 | read -r b2sum rest < "${OUTPUT}.b2" |
55 | rm -f "${OUTPUT}.b2" | |
c0511f3a MT |
56 | |
57 | # Compute checkum of downloaded image file | |
b8764ff2 | 58 | read -r b2sum_image rest <<< "$(b2sum "${OUTPUT}")" |
c0511f3a | 59 | |
b8764ff2 PM |
60 | if [ "${b2sum}" != "${b2sum_image}" ]; then |
61 | echo "BLAKE2 checksum mismatch: ${b2sum} != ${b2sum_image}" >&2 | |
c0511f3a MT |
62 | exit 2 |
63 | fi | |
0f680bcc | 64 | fi |
c0511f3a MT |
65 | |
66 | exit 0 |