xref: /freebsd/usr.sbin/bsdinstall/scripts/fetchmissingdists (revision 12b92f3ed82aa71c0eba246ce3053ef225724570)
140923b0cSNathan Whitehorn#!/bin/sh
240923b0cSNathan Whitehorn#-
340923b0cSNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn
440923b0cSNathan Whitehorn# Copyright (c) 2013-2018 Devin Teske
540923b0cSNathan Whitehorn# All rights reserved.
640923b0cSNathan Whitehorn#
740923b0cSNathan Whitehorn# Redistribution and use in source and binary forms, with or without
840923b0cSNathan Whitehorn# modification, are permitted provided that the following conditions
940923b0cSNathan Whitehorn# are met:
1040923b0cSNathan Whitehorn# 1. Redistributions of source code must retain the above copyright
1140923b0cSNathan Whitehorn#    notice, this list of conditions and the following disclaimer.
1240923b0cSNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright
1340923b0cSNathan Whitehorn#    notice, this list of conditions and the following disclaimer in the
1440923b0cSNathan Whitehorn#    documentation and/or other materials provided with the distribution.
1540923b0cSNathan Whitehorn#
1640923b0cSNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1740923b0cSNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1840923b0cSNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1940923b0cSNathan Whitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2040923b0cSNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2140923b0cSNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2240923b0cSNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2340923b0cSNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2440923b0cSNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2540923b0cSNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2640923b0cSNathan Whitehorn# SUCH DAMAGE.
2740923b0cSNathan Whitehorn#
2840923b0cSNathan Whitehorn# $FreeBSD$
2940923b0cSNathan Whitehorn#
3040923b0cSNathan Whitehorn
312913e785SBrad DavisBSDCFG_SHARE="/usr/share/bsdconfig"
322913e785SBrad Davis. $BSDCFG_SHARE/common.subr || exit 1
332913e785SBrad Davis
3440923b0cSNathan Whitehornerror()
3540923b0cSNathan Whitehorn{
362913e785SBrad Davis	bsddialog --backtitle "$OSNAME Installer" --title "Error" --msgbox "$1" 0 0
3740923b0cSNathan Whitehorn	exit 1
3840923b0cSNathan Whitehorn}
3940923b0cSNathan Whitehorn
4040923b0cSNathan WhitehornFETCH_DISTRIBUTIONS=""
4140923b0cSNathan WhitehornLOCAL_DISTRIBUTIONS=""
4240923b0cSNathan Whitehornfor dist in $DISTRIBUTIONS; do
4340923b0cSNathan Whitehorn	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
4440923b0cSNathan Whitehorn		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
4540923b0cSNathan Whitehorn	else
4640923b0cSNathan Whitehorn		LOCAL_DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS $dist"
4740923b0cSNathan Whitehorn	fi
4840923b0cSNathan Whitehorndone
4940923b0cSNathan WhitehornLOCAL_DISTRIBUTIONS=`echo $LOCAL_DISTRIBUTIONS`	# Trim white space
5040923b0cSNathan WhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
5140923b0cSNathan Whitehorn
5240923b0cSNathan Whitehornif [ -z "$FETCH_DISTRIBUTIONS" ]; then
5340923b0cSNathan Whitehorn	echo $BSDINSTALL_DISTDIR >&2
5440923b0cSNathan Whitehorn	exit 0
5540923b0cSNathan Whitehornfi
5640923b0cSNathan Whitehorn
5740923b0cSNathan WhitehornALL_DISTRIBUTIONS="$DISTRIBUTIONS"
5840923b0cSNathan WhitehornWANT_DEBUG=
5940923b0cSNathan Whitehorn
6040923b0cSNathan Whitehorn# Download to a directory in the new system as scratch space
6140923b0cSNathan WhitehornBSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
6240923b0cSNathan Whitehornmkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST"
6340923b0cSNathan Whitehorn
6440923b0cSNathan Whitehornif [ -z "$BSDINSTALL_DISTSITE" ]; then
6540923b0cSNathan Whitehorn	exec 3>&1
6640923b0cSNathan Whitehorn	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
6740923b0cSNathan Whitehorn	MIRROR_BUTTON=$?
6840923b0cSNathan Whitehorn	exec 3>&-
6940923b0cSNathan Whitehorn	test $MIRROR_BUTTON -eq 0 || error "No mirror selected"
7040923b0cSNathan Whitehorn	export BSDINSTALL_DISTSITE
7140923b0cSNathan Whitehornfi
7240923b0cSNathan Whitehorn
7340923b0cSNathan WhitehornBSDINSTALL_DISTDIR_ORIG="$BSDINSTALL_DISTDIR"
7440923b0cSNathan Whitehornexport BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
7540923b0cSNathan Whitehornexport FTP_PASSIVE_MODE=YES
7640923b0cSNathan Whitehorn
7740923b0cSNathan Whitehornif [ -f "$BSDINSTALL_DISTDIR_ORIG/MANIFEST" ]; then
7840923b0cSNathan Whitehorn	cp "$BSDINSTALL_DISTDIR_ORIG/MANIFEST" "$BSDINSTALL_DISTDIR/MANIFEST"
7940923b0cSNathan Whitehorn	VERIFY_MANIFEST_SIG=0
8040923b0cSNathan Whitehornelse
8140923b0cSNathan Whitehorn	FETCH_DISTRIBUTIONS="MANIFEST $FETCH_DISTRIBUTIONS"
8240923b0cSNathan Whitehorn	VERIFY_MANIFEST_SIG=1
8340923b0cSNathan Whitehorn
8440923b0cSNathan Whitehorn	# XXX actually verify signature on manifest
85cc42ef53SBrad Davis	bsddialog --backtitle "$OSNAME Installer" --title "Warning" --msgbox "Manifest not found on local disk and will be fetched from an unverified source. This is a potential security risk. If you do not wish to proceed, press control-C now." 0 0
8640923b0cSNathan Whitehornfi
8740923b0cSNathan Whitehorn
8840923b0cSNathan Whitehornif [ ! -z "$LOCAL_DISTRIBUTIONS" ]; then
8940923b0cSNathan Whitehorn	# Copy local stuff first
9040923b0cSNathan Whitehorn	env DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS" \
91*12b92f3eSKyle Evans		BSDINSTALL_DISTSITE="file://$BSDINSTALL_DISTDIR_ORIG" \
9240923b0cSNathan Whitehorn		bsdinstall distfetch || \
9340923b0cSNathan Whitehorn		error "Failed to fetch distribution from local media"
9440923b0cSNathan Whitehornfi
9540923b0cSNathan Whitehorn
9640923b0cSNathan Whitehornexport DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
9740923b0cSNathan Whitehorn
9840923b0cSNathan Whitehorn# Iterate through the distribution list and set a flag if debugging
9940923b0cSNathan Whitehorn# distributions have been selected.
10040923b0cSNathan Whitehornfor _DISTRIBUTION in $DISTRIBUTIONS; do
10140923b0cSNathan Whitehorn	case $_DISTRIBUTION in
10240923b0cSNathan Whitehorn		*-dbg.*)
10340923b0cSNathan Whitehorn			[ -e $BSDINSTALL_DISTDIR/$_DISTRIBUTION ] \
10440923b0cSNathan Whitehorn				&& continue
10540923b0cSNathan Whitehorn			WANT_DEBUG=1
10640923b0cSNathan Whitehorn			DEBUG_LIST="\n$DEBUG_LIST\n$_DISTRIBUTION"
10740923b0cSNathan Whitehorn			;;
10840923b0cSNathan Whitehorn		*)
10940923b0cSNathan Whitehorn			;;
11040923b0cSNathan Whitehorn	esac
11140923b0cSNathan Whitehorndone
11240923b0cSNathan Whitehorn
11340923b0cSNathan Whitehorn# Fetch the distributions.
11440923b0cSNathan Whitehornbsdinstall distfetch
11540923b0cSNathan Whitehornrc=$?
11640923b0cSNathan Whitehorn
11740923b0cSNathan Whitehornif [ $rc -ne 0 ]; then
11840923b0cSNathan Whitehorn	# If unable to fetch the remote distributions, recommend
11940923b0cSNathan Whitehorn	# deselecting the debugging distributions, and retrying the
12040923b0cSNathan Whitehorn	# installation, since failure to fetch *-dbg.txz should not
12140923b0cSNathan Whitehorn	# be considered a fatal installation error.
12240923b0cSNathan Whitehorn	msg="Failed to fetch remote distribution"
12340923b0cSNathan Whitehorn	if [ ! -z "$WANT_DEBUG" ]; then
12440923b0cSNathan Whitehorn		# Trim leading and trailing newlines.
12540923b0cSNathan Whitehorn		DEBUG_LIST="${DEBUG_LIST%%\n}"
12640923b0cSNathan Whitehorn		DEBUG_LIST="${DEBUG_LIST##\n}"
12740923b0cSNathan Whitehorn		msg="$msg\n\nPlease deselect the following distributions"
12840923b0cSNathan Whitehorn		msg="$msg and retry the installation:"
12940923b0cSNathan Whitehorn		msg="$msg\n$DEBUG_LIST"
13040923b0cSNathan Whitehorn	fi
13140923b0cSNathan Whitehorn	error "$msg"
13240923b0cSNathan Whitehornfi
13340923b0cSNathan Whitehorn
13440923b0cSNathan Whitehornecho $BSDINSTALL_DISTDIR >&2
13540923b0cSNathan Whitehorn
136