1*40923b0cSNathan Whitehorn#!/bin/sh 2*40923b0cSNathan Whitehorn#- 3*40923b0cSNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn 4*40923b0cSNathan Whitehorn# Copyright (c) 2013-2018 Devin Teske 5*40923b0cSNathan Whitehorn# All rights reserved. 6*40923b0cSNathan Whitehorn# 7*40923b0cSNathan Whitehorn# Redistribution and use in source and binary forms, with or without 8*40923b0cSNathan Whitehorn# modification, are permitted provided that the following conditions 9*40923b0cSNathan Whitehorn# are met: 10*40923b0cSNathan Whitehorn# 1. Redistributions of source code must retain the above copyright 11*40923b0cSNathan Whitehorn# notice, this list of conditions and the following disclaimer. 12*40923b0cSNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright 13*40923b0cSNathan Whitehorn# notice, this list of conditions and the following disclaimer in the 14*40923b0cSNathan Whitehorn# documentation and/or other materials provided with the distribution. 15*40923b0cSNathan Whitehorn# 16*40923b0cSNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*40923b0cSNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*40923b0cSNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*40923b0cSNathan Whitehorn# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*40923b0cSNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*40923b0cSNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*40923b0cSNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*40923b0cSNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*40923b0cSNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*40923b0cSNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*40923b0cSNathan Whitehorn# SUCH DAMAGE. 27*40923b0cSNathan Whitehorn# 28*40923b0cSNathan Whitehorn# $FreeBSD$ 29*40923b0cSNathan Whitehorn# 30*40923b0cSNathan Whitehorn 31*40923b0cSNathan Whitehornerror() 32*40923b0cSNathan Whitehorn{ 33*40923b0cSNathan Whitehorn dialog --backtitle "FreeBSD Installer" --title "Error" --msgbox $1 0 0 34*40923b0cSNathan Whitehorn exit 1 35*40923b0cSNathan Whitehorn} 36*40923b0cSNathan Whitehorn 37*40923b0cSNathan WhitehornFETCH_DISTRIBUTIONS="" 38*40923b0cSNathan WhitehornLOCAL_DISTRIBUTIONS="" 39*40923b0cSNathan Whitehornfor dist in $DISTRIBUTIONS; do 40*40923b0cSNathan Whitehorn if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then 41*40923b0cSNathan Whitehorn FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" 42*40923b0cSNathan Whitehorn else 43*40923b0cSNathan Whitehorn LOCAL_DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS $dist" 44*40923b0cSNathan Whitehorn fi 45*40923b0cSNathan Whitehorndone 46*40923b0cSNathan WhitehornLOCAL_DISTRIBUTIONS=`echo $LOCAL_DISTRIBUTIONS` # Trim white space 47*40923b0cSNathan WhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS` # Trim white space 48*40923b0cSNathan Whitehorn 49*40923b0cSNathan Whitehornif [ -z "$FETCH_DISTRIBUTIONS" ]; then 50*40923b0cSNathan Whitehorn echo $BSDINSTALL_DISTDIR >&2 51*40923b0cSNathan Whitehorn exit 0 52*40923b0cSNathan Whitehornfi 53*40923b0cSNathan Whitehorn 54*40923b0cSNathan WhitehornALL_DISTRIBUTIONS="$DISTRIBUTIONS" 55*40923b0cSNathan WhitehornWANT_DEBUG= 56*40923b0cSNathan Whitehorn 57*40923b0cSNathan Whitehorn# Download to a directory in the new system as scratch space 58*40923b0cSNathan WhitehornBSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist" 59*40923b0cSNathan Whitehornmkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST" 60*40923b0cSNathan Whitehorn 61*40923b0cSNathan Whitehornif [ -z "$BSDINSTALL_DISTSITE" ]; then 62*40923b0cSNathan Whitehorn exec 3>&1 63*40923b0cSNathan Whitehorn BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3) 64*40923b0cSNathan Whitehorn MIRROR_BUTTON=$? 65*40923b0cSNathan Whitehorn exec 3>&- 66*40923b0cSNathan Whitehorn test $MIRROR_BUTTON -eq 0 || error "No mirror selected" 67*40923b0cSNathan Whitehorn export BSDINSTALL_DISTSITE 68*40923b0cSNathan Whitehornfi 69*40923b0cSNathan Whitehorn 70*40923b0cSNathan WhitehornBSDINSTALL_DISTDIR_ORIG="$BSDINSTALL_DISTDIR" 71*40923b0cSNathan Whitehornexport BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST" 72*40923b0cSNathan Whitehornexport FTP_PASSIVE_MODE=YES 73*40923b0cSNathan Whitehorn 74*40923b0cSNathan Whitehornif [ -f "$BSDINSTALL_DISTDIR_ORIG/MANIFEST" ]; then 75*40923b0cSNathan Whitehorn cp "$BSDINSTALL_DISTDIR_ORIG/MANIFEST" "$BSDINSTALL_DISTDIR/MANIFEST" 76*40923b0cSNathan Whitehorn VERIFY_MANIFEST_SIG=0 77*40923b0cSNathan Whitehornelse 78*40923b0cSNathan Whitehorn FETCH_DISTRIBUTIONS="MANIFEST $FETCH_DISTRIBUTIONS" 79*40923b0cSNathan Whitehorn VERIFY_MANIFEST_SIG=1 80*40923b0cSNathan Whitehorn 81*40923b0cSNathan Whitehorn # XXX actually verify signature on manifest 82*40923b0cSNathan Whitehorn dialog --backtitle "FreeBSD 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 83*40923b0cSNathan Whitehornfi 84*40923b0cSNathan Whitehorn 85*40923b0cSNathan Whitehornif [ ! -z "$LOCAL_DISTRIBUTIONS" ]; then 86*40923b0cSNathan Whitehorn # Copy local stuff first 87*40923b0cSNathan Whitehorn env DISTRIBUTIONS="$LOCAL_DISTRIBUTIONS" \ 88*40923b0cSNathan Whitehorn BSDINSTALL_DISTSITE="file://$BSDINSTALL_DISTDIR" \ 89*40923b0cSNathan Whitehorn bsdinstall distfetch || \ 90*40923b0cSNathan Whitehorn error "Failed to fetch distribution from local media" 91*40923b0cSNathan Whitehornfi 92*40923b0cSNathan Whitehorn 93*40923b0cSNathan Whitehornexport DISTRIBUTIONS="$FETCH_DISTRIBUTIONS" 94*40923b0cSNathan Whitehorn 95*40923b0cSNathan Whitehorn# Iterate through the distribution list and set a flag if debugging 96*40923b0cSNathan Whitehorn# distributions have been selected. 97*40923b0cSNathan Whitehornfor _DISTRIBUTION in $DISTRIBUTIONS; do 98*40923b0cSNathan Whitehorn case $_DISTRIBUTION in 99*40923b0cSNathan Whitehorn *-dbg.*) 100*40923b0cSNathan Whitehorn [ -e $BSDINSTALL_DISTDIR/$_DISTRIBUTION ] \ 101*40923b0cSNathan Whitehorn && continue 102*40923b0cSNathan Whitehorn WANT_DEBUG=1 103*40923b0cSNathan Whitehorn DEBUG_LIST="\n$DEBUG_LIST\n$_DISTRIBUTION" 104*40923b0cSNathan Whitehorn ;; 105*40923b0cSNathan Whitehorn *) 106*40923b0cSNathan Whitehorn ;; 107*40923b0cSNathan Whitehorn esac 108*40923b0cSNathan Whitehorndone 109*40923b0cSNathan Whitehorn 110*40923b0cSNathan Whitehorn# Fetch the distributions. 111*40923b0cSNathan Whitehornbsdinstall distfetch 112*40923b0cSNathan Whitehornrc=$? 113*40923b0cSNathan Whitehorn 114*40923b0cSNathan Whitehornif [ $rc -ne 0 ]; then 115*40923b0cSNathan Whitehorn # If unable to fetch the remote distributions, recommend 116*40923b0cSNathan Whitehorn # deselecting the debugging distributions, and retrying the 117*40923b0cSNathan Whitehorn # installation, since failure to fetch *-dbg.txz should not 118*40923b0cSNathan Whitehorn # be considered a fatal installation error. 119*40923b0cSNathan Whitehorn msg="Failed to fetch remote distribution" 120*40923b0cSNathan Whitehorn if [ ! -z "$WANT_DEBUG" ]; then 121*40923b0cSNathan Whitehorn # Trim leading and trailing newlines. 122*40923b0cSNathan Whitehorn DEBUG_LIST="${DEBUG_LIST%%\n}" 123*40923b0cSNathan Whitehorn DEBUG_LIST="${DEBUG_LIST##\n}" 124*40923b0cSNathan Whitehorn msg="$msg\n\nPlease deselect the following distributions" 125*40923b0cSNathan Whitehorn msg="$msg and retry the installation:" 126*40923b0cSNathan Whitehorn msg="$msg\n$DEBUG_LIST" 127*40923b0cSNathan Whitehorn fi 128*40923b0cSNathan Whitehorn error "$msg" 129*40923b0cSNathan Whitehornfi 130*40923b0cSNathan Whitehorn 131*40923b0cSNathan Whitehornecho $BSDINSTALL_DISTDIR >&2 132*40923b0cSNathan Whitehorn 133