xref: /freebsd/usr.sbin/bsdinstall/scripts/fetchmissingdists (revision cc42ef5328963ee55c3305b136e9a86145f24594)
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
3140923b0cSNathan Whitehornerror()
3240923b0cSNathan Whitehorn{
3348af6ad9SAlfonso S. Siciliano	bsddialog --backtitle "FreeBSD Installer" --title "Error" --msgbox "$1" 0 0
3440923b0cSNathan Whitehorn	exit 1
3540923b0cSNathan Whitehorn}
3640923b0cSNathan Whitehorn
3740923b0cSNathan WhitehornFETCH_DISTRIBUTIONS=""
3840923b0cSNathan WhitehornLOCAL_DISTRIBUTIONS=""
3940923b0cSNathan Whitehornfor dist in $DISTRIBUTIONS; do
4040923b0cSNathan Whitehorn	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
4140923b0cSNathan Whitehorn		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
4240923b0cSNathan Whitehorn	else
4340923b0cSNathan Whitehorn		LOCAL_DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS $dist"
4440923b0cSNathan Whitehorn	fi
4540923b0cSNathan Whitehorndone
4640923b0cSNathan WhitehornLOCAL_DISTRIBUTIONS=`echo $LOCAL_DISTRIBUTIONS`	# Trim white space
4740923b0cSNathan WhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
4840923b0cSNathan Whitehorn
4940923b0cSNathan Whitehornif [ -z "$FETCH_DISTRIBUTIONS" ]; then
5040923b0cSNathan Whitehorn	echo $BSDINSTALL_DISTDIR >&2
5140923b0cSNathan Whitehorn	exit 0
5240923b0cSNathan Whitehornfi
5340923b0cSNathan Whitehorn
5440923b0cSNathan WhitehornALL_DISTRIBUTIONS="$DISTRIBUTIONS"
5540923b0cSNathan WhitehornWANT_DEBUG=
5640923b0cSNathan Whitehorn
5740923b0cSNathan Whitehorn# Download to a directory in the new system as scratch space
5840923b0cSNathan WhitehornBSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
5940923b0cSNathan Whitehornmkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST"
6040923b0cSNathan Whitehorn
6140923b0cSNathan Whitehornif [ -z "$BSDINSTALL_DISTSITE" ]; then
6240923b0cSNathan Whitehorn	exec 3>&1
6340923b0cSNathan Whitehorn	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
6440923b0cSNathan Whitehorn	MIRROR_BUTTON=$?
6540923b0cSNathan Whitehorn	exec 3>&-
6640923b0cSNathan Whitehorn	test $MIRROR_BUTTON -eq 0 || error "No mirror selected"
6740923b0cSNathan Whitehorn	export BSDINSTALL_DISTSITE
6840923b0cSNathan Whitehornfi
6940923b0cSNathan Whitehorn
7040923b0cSNathan WhitehornBSDINSTALL_DISTDIR_ORIG="$BSDINSTALL_DISTDIR"
7140923b0cSNathan Whitehornexport BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
7240923b0cSNathan Whitehornexport FTP_PASSIVE_MODE=YES
7340923b0cSNathan Whitehorn
7440923b0cSNathan Whitehornif [ -f "$BSDINSTALL_DISTDIR_ORIG/MANIFEST" ]; then
7540923b0cSNathan Whitehorn	cp "$BSDINSTALL_DISTDIR_ORIG/MANIFEST" "$BSDINSTALL_DISTDIR/MANIFEST"
7640923b0cSNathan Whitehorn	VERIFY_MANIFEST_SIG=0
7740923b0cSNathan Whitehornelse
7840923b0cSNathan Whitehorn	FETCH_DISTRIBUTIONS="MANIFEST $FETCH_DISTRIBUTIONS"
7940923b0cSNathan Whitehorn	VERIFY_MANIFEST_SIG=1
8040923b0cSNathan Whitehorn
8140923b0cSNathan Whitehorn	# XXX actually verify signature on manifest
82*cc42ef53SBrad 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
8340923b0cSNathan Whitehornfi
8440923b0cSNathan Whitehorn
8540923b0cSNathan Whitehornif [ ! -z "$LOCAL_DISTRIBUTIONS" ]; then
8640923b0cSNathan Whitehorn	# Copy local stuff first
8740923b0cSNathan Whitehorn	env DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS" \
8840923b0cSNathan Whitehorn		BSDINSTALL_DISTSITE="file://$BSDINSTALL_DISTDIR" \
8940923b0cSNathan Whitehorn		bsdinstall distfetch || \
9040923b0cSNathan Whitehorn		error "Failed to fetch distribution from local media"
9140923b0cSNathan Whitehornfi
9240923b0cSNathan Whitehorn
9340923b0cSNathan Whitehornexport DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
9440923b0cSNathan Whitehorn
9540923b0cSNathan Whitehorn# Iterate through the distribution list and set a flag if debugging
9640923b0cSNathan Whitehorn# distributions have been selected.
9740923b0cSNathan Whitehornfor _DISTRIBUTION in $DISTRIBUTIONS; do
9840923b0cSNathan Whitehorn	case $_DISTRIBUTION in
9940923b0cSNathan Whitehorn		*-dbg.*)
10040923b0cSNathan Whitehorn			[ -e $BSDINSTALL_DISTDIR/$_DISTRIBUTION ] \
10140923b0cSNathan Whitehorn				&& continue
10240923b0cSNathan Whitehorn			WANT_DEBUG=1
10340923b0cSNathan Whitehorn			DEBUG_LIST="\n$DEBUG_LIST\n$_DISTRIBUTION"
10440923b0cSNathan Whitehorn			;;
10540923b0cSNathan Whitehorn		*)
10640923b0cSNathan Whitehorn			;;
10740923b0cSNathan Whitehorn	esac
10840923b0cSNathan Whitehorndone
10940923b0cSNathan Whitehorn
11040923b0cSNathan Whitehorn# Fetch the distributions.
11140923b0cSNathan Whitehornbsdinstall distfetch
11240923b0cSNathan Whitehornrc=$?
11340923b0cSNathan Whitehorn
11440923b0cSNathan Whitehornif [ $rc -ne 0 ]; then
11540923b0cSNathan Whitehorn	# If unable to fetch the remote distributions, recommend
11640923b0cSNathan Whitehorn	# deselecting the debugging distributions, and retrying the
11740923b0cSNathan Whitehorn	# installation, since failure to fetch *-dbg.txz should not
11840923b0cSNathan Whitehorn	# be considered a fatal installation error.
11940923b0cSNathan Whitehorn	msg="Failed to fetch remote distribution"
12040923b0cSNathan Whitehorn	if [ ! -z "$WANT_DEBUG" ]; then
12140923b0cSNathan Whitehorn		# Trim leading and trailing newlines.
12240923b0cSNathan Whitehorn		DEBUG_LIST="${DEBUG_LIST%%\n}"
12340923b0cSNathan Whitehorn		DEBUG_LIST="${DEBUG_LIST##\n}"
12440923b0cSNathan Whitehorn		msg="$msg\n\nPlease deselect the following distributions"
12540923b0cSNathan Whitehorn		msg="$msg and retry the installation:"
12640923b0cSNathan Whitehorn		msg="$msg\n$DEBUG_LIST"
12740923b0cSNathan Whitehorn	fi
12840923b0cSNathan Whitehorn	error "$msg"
12940923b0cSNathan Whitehornfi
13040923b0cSNathan Whitehorn
13140923b0cSNathan Whitehornecho $BSDINSTALL_DISTDIR >&2
13240923b0cSNathan Whitehorn
133