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