1219615Snwhitehorn#!/bin/sh
2219615Snwhitehorn#-
3219615Snwhitehorn# Copyright (c) 2011 Nathan Whitehorn
4219615Snwhitehorn# All rights reserved.
5219615Snwhitehorn#
6219615Snwhitehorn# Redistribution and use in source and binary forms, with or without
7219615Snwhitehorn# modification, are permitted provided that the following conditions
8219615Snwhitehorn# are met:
9219615Snwhitehorn# 1. Redistributions of source code must retain the above copyright
10219615Snwhitehorn#    notice, this list of conditions and the following disclaimer.
11219615Snwhitehorn# 2. Redistributions in binary form must reproduce the above copyright
12219615Snwhitehorn#    notice, this list of conditions and the following disclaimer in the
13219615Snwhitehorn#    documentation and/or other materials provided with the distribution.
14219615Snwhitehorn#
15219615Snwhitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16219615Snwhitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17219615Snwhitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18219615Snwhitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19219615Snwhitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20219615Snwhitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21219615Snwhitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22219615Snwhitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23219615Snwhitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24219615Snwhitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25219615Snwhitehorn# SUCH DAMAGE.
26219615Snwhitehorn#
27219615Snwhitehorn# $FreeBSD$
28219615Snwhitehorn
29219615Snwhitehorntest -f $BSDINSTALL_DISTDIR/MANIFEST || exit 0
30219615Snwhitehorn
31219615Snwhitehornpercentage=0
32219615Snwhitehornfor dist in $DISTRIBUTIONS; do
33219615Snwhitehorn	distname=$(basename $dist .txz)
34219615Snwhitehorn	eval "status_$distname=7"
35219615Snwhitehorn	
36219615Snwhitehorn	items=""
37219615Snwhitehorn	for i in $DISTRIBUTIONS; do
38219615Snwhitehorn		items="$items $i `eval echo \\\${status_$(basename $i .txz):-Pending}`"
39219615Snwhitehorn	done
40219615Snwhitehorn	dialog --backtitle "FreeBSD Installer" --title "Checksum Verification" \
41219615Snwhitehorn	    --mixedgauge "Verifying checksums of selected distributions." \
42219615Snwhitehorn	    0 0 $percentage $items
43219615Snwhitehorn
44219615Snwhitehorn	CK=`sha256 -q $BSDINSTALL_DISTDIR/$dist`
45219903Snwhitehorn	awk -v checksum=$CK -v dist=$dist -v found=0 '{
46219615Snwhitehorn		if (dist == $1) {
47219903Snwhitehorn			found = 1
48219615Snwhitehorn			if (checksum == $2)
49219615Snwhitehorn				exit(0)
50219615Snwhitehorn			else
51219903Snwhitehorn				exit(2)
52219615Snwhitehorn		}
53219903Snwhitehorn	} END {if (!found) exit(1);}' $BSDINSTALL_DISTDIR/MANIFEST
54219615Snwhitehorn
55219903Snwhitehorn	CK_VALID=$?
56219903Snwhitehorn	if [ $CK_VALID -le 1 ]; then
57219903Snwhitehorn		if [ $CK_VALID -eq 0 ]; then
58219903Snwhitehorn			eval "status_$distname=2"
59219903Snwhitehorn		else
60219903Snwhitehorn			eval "status_$distname=6"
61219903Snwhitehorn		fi
62219615Snwhitehorn		percentage=$(echo $percentage + 100/`echo $DISTRIBUTIONS | wc -w` | bc)
63219615Snwhitehorn	else
64219615Snwhitehorn		eval "status_$distname=1"
65219615Snwhitehorn		dialog --backtitle "FreeBSD Installer" --title "Error" \
66219615Snwhitehorn		    --msgbox "The checksum for $dist does not match. It may have become corrupted, and should be redownloaded." 0 0
67219615Snwhitehorn		exit 1
68219615Snwhitehorn	fi
69219615Snwhitehorndone
70219615Snwhitehorn
71219615Snwhitehornexit 0
72