xref: /freebsd/usr.sbin/bsdinstall/scripts/checksum (revision 2913e785f057f54f7ee825fe4f9fe3c039c0f78f)
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
31cc42ef53SBrad DavisBSDCFG_SHARE="/usr/share/bsdconfig"
32cc42ef53SBrad Davis. $BSDCFG_SHARE/common.subr || exit 1
33cc42ef53SBrad Davis
34b70047d4SNathan Whitehornpercentage=0
35b70047d4SNathan Whitehornfor dist in $DISTRIBUTIONS; do
36b70047d4SNathan Whitehorn	distname=$(basename $dist .txz)
370868f621SAlfonso S. Siciliano	eval "status_$distname=-8"
38b70047d4SNathan Whitehorn
39b70047d4SNathan Whitehorn	items=""
40b70047d4SNathan Whitehorn	for i in $DISTRIBUTIONS; do
410868f621SAlfonso S. Siciliano		items="$items $i `eval echo \\\${status_$(basename $i .txz):--11}`"
42b70047d4SNathan Whitehorn	done
43cc42ef53SBrad Davis	bsddialog --backtitle "$OSNAME Installer" --title "Checksum Verification" \
440868f621SAlfonso S. Siciliano	    --mixedgauge "\nVerifying checksums of selected distributions.\n" \
450868f621SAlfonso S. Siciliano	    0 0 $percentage  -- $items
46b70047d4SNathan Whitehorn
47b70047d4SNathan Whitehorn	CK=`sha256 -q $BSDINSTALL_DISTDIR/$dist`
48c31153adSNathan Whitehorn	awk -v checksum=$CK -v dist=$dist -v found=0 '{
49b70047d4SNathan Whitehorn		if (dist == $1) {
50c31153adSNathan Whitehorn			found = 1
51b70047d4SNathan Whitehorn			if (checksum == $2)
52b70047d4SNathan Whitehorn				exit(0)
53b70047d4SNathan Whitehorn			else
54c31153adSNathan Whitehorn				exit(2)
55b70047d4SNathan Whitehorn		}
56c31153adSNathan Whitehorn	} END {if (!found) exit(1);}' $BSDINSTALL_DISTDIR/MANIFEST
57b70047d4SNathan Whitehorn
58c31153adSNathan Whitehorn	CK_VALID=$?
59c31153adSNathan Whitehorn	if [ $CK_VALID -le 1 ]; then
60c31153adSNathan Whitehorn		if [ $CK_VALID -eq 0 ]; then
610868f621SAlfonso S. Siciliano			eval "status_$distname=-3"
62c31153adSNathan Whitehorn		else
630868f621SAlfonso S. Siciliano			eval "status_$distname=-7"
64c31153adSNathan Whitehorn		fi
65b70047d4SNathan Whitehorn		percentage=$(echo $percentage + 100/`echo $DISTRIBUTIONS | wc -w` | bc)
66b70047d4SNathan Whitehorn	else
670868f621SAlfonso S. Siciliano		eval "status_$distname=-2"
682775c1d7SEd Maste		case $(/bin/freebsd-version -u) in
692775c1d7SEd Maste		*-ALPHA*|*-CURRENT|*-STABLE|*-PRERELEASE)
70cc42ef53SBrad Davis			bsddialog --backtitle "$OSNAME Installer" --title "Error" \
71*2913e785SBrad Davis			    --msgbox "The checksum for $dist does not match. It may have become corrupted, or it may be from a newer version of $OSNAME. Please check for a newer snapshot." 0 0
722775c1d7SEd Maste			;;
732775c1d7SEd Maste		*)
74cc42ef53SBrad Davis			bsddialog --backtitle "$OSNAME Installer" --title "Error" \
75b70047d4SNathan Whitehorn			    --msgbox "The checksum for $dist does not match. It may have become corrupted, and should be redownloaded." 0 0
762775c1d7SEd Maste			;;
772775c1d7SEd Maste		esac
78b70047d4SNathan Whitehorn		exit 1
79b70047d4SNathan Whitehorn	fi
80b70047d4SNathan Whitehorndone
81b70047d4SNathan Whitehorn
82b70047d4SNathan Whitehornexit 0
83