X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=blobdiff_plain;f=src%2Finstaller%2Fdownloadsource.sh;h=c74f9e232d2e1dc1874152ca71508736bb903c3c;hp=1f6c432dd826b72764a5be9f39633a5736e58906;hb=ade96ba8a590df6411f7effec637609494072034;hpb=62845ec556cdc6fbd3f452c33517d6653c78441f diff --git a/src/installer/downloadsource.sh b/src/installer/downloadsource.sh index 1f6c432dd8..c74f9e232d 100644 --- a/src/installer/downloadsource.sh +++ b/src/installer/downloadsource.sh @@ -19,36 +19,48 @@ # # ############################################################################### -#lfs change the url while build! -IPFireISO=ipfire.iso -# - -#Get user defined download from boot cmdline -grep "netinstall=" /proc/cmdline > /dev/null && CMDLINE=1 -if ( [ "$CMDLINE" == "1" ]); then - read CMDLINE < /proc/cmdline - POS=${CMDLINE%%netinstall*} - POS=${#POS} - IPFireISO=`echo ${CMDLINE:POS} | cut -d"=" -f2 | cut -d" " -f1` +function download() { + wget -U "IPFire-NetInstall/2.x" "$@" +} + +if [ $# -lt 2 ]; then + echo "$0: Insufficient number of arguments" >&2 + exit 2 +fi + +OUTPUT="${1}" +URL="${2}" + +# Mount a tmpfs which is big enough to hold the ISO image +OUTPUT_DIR="${OUTPUT%/*}" + +mkdir -p "${OUTPUT_DIR}" +if ! mount -t tmpfs none "${OUTPUT_DIR}" -o size=512M; then + echo "Could not mount tmpfs to ${OUTPUT_DIR}" >&2 + exit 1 fi -echo -echo "Configure Network with DHCP..." -dhcpcd -echo -echo "Sleep 15s..." -sleep 15 -echo -echo "Download with wget..." -wget $IPFireISO -O /tmp/download.iso -t3 -U IPFire_NetInstall/2.x -wget $IPFireISO.md5 -O /tmp/download.iso.md5 -t3 -U IPFire_NetInstall/2.x -echo -echo "Checking download..." -md5_file=`md5sum /tmp/download.iso | cut -d" " -f1` -md5_down=`cat /tmp/download.iso.md5 | cut -d" " -f1` -if [ "$md5_file" == "$md5_down" ]; then - echo -n "/tmp/download.iso" > /tmp/source_device - exit 0 +echo "Downloading ${URL}..." +if ! download -O "${OUTPUT}" "${URL}"; then + echo "Download failed" >&2 + + rm -f "${OUTPUT}" + exit 1 fi -echo "Error - SKIP" -exit 10 + +# Download went well. Checking for MD5 sum +if download -O "${OUTPUT}.md5" "${URL}.md5" &>/dev/null; then + # Read downloaded checksum + read -r md5sum rest < "${OUTPUT}.md5" + rm -f "${OUTPUT}.md5" + + # Compute checkum of downloaded image file + read -r md5sum_image rest <<< "$(md5sum "${OUTPUT}")" + + if [ "${md5sum}" != "${md5sum_image}" ]; then + echo "MD5 sum mismatch: ${md5sum} != ${md5sum_image}" >&2 + exit 2 + fi +fi + +exit 0