xref: /freebsd/usr.sbin/bsdinstall/scripts/checksum (revision b70047d4136285ce8e5046c379143f4813228855)
1*b70047d4SNathan Whitehorn#!/bin/sh
2*b70047d4SNathan Whitehorn#-
3*b70047d4SNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn
4*b70047d4SNathan Whitehorn# All rights reserved.
5*b70047d4SNathan Whitehorn#
6*b70047d4SNathan Whitehorn# Redistribution and use in source and binary forms, with or without
7*b70047d4SNathan Whitehorn# modification, are permitted provided that the following conditions
8*b70047d4SNathan Whitehorn# are met:
9*b70047d4SNathan Whitehorn# 1. Redistributions of source code must retain the above copyright
10*b70047d4SNathan Whitehorn#    notice, this list of conditions and the following disclaimer.
11*b70047d4SNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright
12*b70047d4SNathan Whitehorn#    notice, this list of conditions and the following disclaimer in the
13*b70047d4SNathan Whitehorn#    documentation and/or other materials provided with the distribution.
14*b70047d4SNathan Whitehorn#
15*b70047d4SNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*b70047d4SNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*b70047d4SNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*b70047d4SNathan Whitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*b70047d4SNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*b70047d4SNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*b70047d4SNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*b70047d4SNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*b70047d4SNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*b70047d4SNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*b70047d4SNathan Whitehorn# SUCH DAMAGE.
26*b70047d4SNathan Whitehorn#
27*b70047d4SNathan Whitehorn# $FreeBSD$
28*b70047d4SNathan Whitehorn
29*b70047d4SNathan Whitehorntest -f $BSDINSTALL_DISTDIR/MANIFEST || exit 0
30*b70047d4SNathan Whitehorn
31*b70047d4SNathan Whitehornpercentage=0
32*b70047d4SNathan Whitehornfor dist in $DISTRIBUTIONS; do
33*b70047d4SNathan Whitehorn	distname=$(basename $dist .txz)
34*b70047d4SNathan Whitehorn	eval "status_$distname=7"
35*b70047d4SNathan Whitehorn
36*b70047d4SNathan Whitehorn	items=""
37*b70047d4SNathan Whitehorn	for i in $DISTRIBUTIONS; do
38*b70047d4SNathan Whitehorn		items="$items $i `eval echo \\\${status_$(basename $i .txz):-Pending}`"
39*b70047d4SNathan Whitehorn	done
40*b70047d4SNathan Whitehorn	dialog --backtitle "FreeBSD Installer" --title "Checksum Verification" \
41*b70047d4SNathan Whitehorn	    --mixedgauge "Verifying checksums of selected distributions." \
42*b70047d4SNathan Whitehorn	    0 0 $percentage $items
43*b70047d4SNathan Whitehorn
44*b70047d4SNathan Whitehorn	CK=`sha256 -q $BSDINSTALL_DISTDIR/$dist`
45*b70047d4SNathan Whitehorn	awk -v checksum=$CK -v dist=$dist '{
46*b70047d4SNathan Whitehorn		if (dist == $1) {
47*b70047d4SNathan Whitehorn			if (checksum == $2)
48*b70047d4SNathan Whitehorn				exit(0)
49*b70047d4SNathan Whitehorn			else
50*b70047d4SNathan Whitehorn				exit(1)
51*b70047d4SNathan Whitehorn		}
52*b70047d4SNathan Whitehorn	}' $BSDINSTALL_DISTDIR/MANIFEST
53*b70047d4SNathan Whitehorn
54*b70047d4SNathan Whitehorn	if [ $? -eq 0 ]; then
55*b70047d4SNathan Whitehorn		eval "status_$distname=2"
56*b70047d4SNathan Whitehorn		percentage=$(echo $percentage + 100/`echo $DISTRIBUTIONS | wc -w` | bc)
57*b70047d4SNathan Whitehorn	else
58*b70047d4SNathan Whitehorn		eval "status_$distname=1"
59*b70047d4SNathan Whitehorn		dialog --backtitle "FreeBSD Installer" --title "Error" \
60*b70047d4SNathan Whitehorn		    --msgbox "The checksum for $dist does not match. It may have become corrupted, and should be redownloaded." 0 0
61*b70047d4SNathan Whitehorn		exit 1
62*b70047d4SNathan Whitehorn	fi
63*b70047d4SNathan Whitehorndone
64*b70047d4SNathan Whitehorn
65*b70047d4SNathan Whitehornexit 0
66