From owner-dev-commits-src-all@freebsd.org Fri Jun 11 19:54:21 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EE8D266394B; Fri, 11 Jun 2021 19:54:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4G1s4F6QdGz4clY; Fri, 11 Jun 2021 19:54:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C106C28E90; Fri, 11 Jun 2021 19:54:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 15BJsLHv076517; Fri, 11 Jun 2021 19:54:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15BJsLGW076516; Fri, 11 Jun 2021 19:54:21 GMT (envelope-from git) Date: Fri, 11 Jun 2021 19:54:21 GMT Message-Id: <202106111954.15BJsLGW076516@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 6f4c1456b51d - main - bsdinstall: Allow automation in jails MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6f4c1456b51dc35c03b2c02cc06e8b4308779855 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Jun 2021 19:54:22 -0000 The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=6f4c1456b51dc35c03b2c02cc06e8b4308779855 commit 6f4c1456b51dc35c03b2c02cc06e8b4308779855 Author: eoli3n AuthorDate: 2021-06-07 20:49:02 +0000 Commit: Warner Losh CommitDate: 2021-06-11 19:53:17 +0000 bsdinstall: Allow automation in jails Set SCRIPT=/path/to/script env var to be able to automate bsdinstall to a jail. Pull Request: https://github.com/freebsd/freebsd-src/pull/473 Reviewed by: allanjude --- usr.sbin/bsdinstall/scripts/jail | 58 +++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/usr.sbin/bsdinstall/scripts/jail b/usr.sbin/bsdinstall/scripts/jail index ecfbb78357d9..d9b5c8eb3cb4 100755 --- a/usr.sbin/bsdinstall/scripts/jail +++ b/usr.sbin/bsdinstall/scripts/jail @@ -52,11 +52,16 @@ error() { fi } - rm -rf $BSDINSTALL_TMPETC mkdir $BSDINSTALL_TMPETC mkdir -p $1 || error "mkdir failed for $1" +if [ -n "$SCRIPT" ] +then + split -a 2 -p '^#!.*' "$SCRIPT" $TMPDIR/bsdinstall-installscript- + . $TMPDIR/bsdinstall-installscript-aa +fi + test ! -d $BSDINSTALL_DISTDIR && mkdir -p $BSDINSTALL_DISTDIR if [ ! -f $BSDINSTALL_DISTDIR/MANIFEST -a -z "$BSDINSTALL_DISTSITE" ]; then @@ -69,20 +74,23 @@ if [ ! -f $BSDINSTALL_DISTDIR/MANIFEST -a -z "$BSDINSTALL_DISTSITE" ]; then fetch -o $BSDINSTALL_DISTDIR/MANIFEST $BSDINSTALL_DISTSITE/MANIFEST || error "Could not download $BSDINSTALL_DISTSITE/MANIFEST" fi -export DISTRIBUTIONS="base.txz" +: ${DISTRIBUTIONS="base.txz"}; export DISTRIBUTIONS if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then DISTMENU=`cut -f 4,5,6 $BSDINSTALL_DISTDIR/MANIFEST | grep -v -e ^kernel -e ^base` - exec 3>&1 - EXTRA_DISTS=$(echo $DISTMENU | xargs dialog \ - --backtitle "FreeBSD Installer" \ - --title "Distribution Select" --nocancel --separate-output \ - --checklist "Choose optional system components to install:" \ - 0 0 0 \ - 2>&1 1>&3) - for dist in $EXTRA_DISTS; do - export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz" - done + if [ ! "$nonInteractive" == "YES" ] + then + exec 3>&1 + EXTRA_DISTS=$(echo $DISTMENU | xargs dialog \ + --backtitle "FreeBSD Installer" \ + --title "Distribution Select" --nocancel --separate-output \ + --checklist "Choose optional system components to install:" \ + 0 0 0 \ + 2>&1 1>&3) + for dist in $EXTRA_DISTS; do + export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz" + done + fi fi FETCH_DISTRIBUTIONS="" @@ -108,20 +116,38 @@ fi bsdinstall checksum || error "Distribution checksum failed" bsdinstall distextract || error "Distribution extract failed" -bsdinstall rootpass || error "Could not set root password" + +if [ ! "$nonInteractive" == "YES" ] +then + bsdinstall rootpass || error "Could not set root password" +fi trap true SIGINT # This section is optional + +if [ ! "$nonInteractive" == "YES" ] +then bsdinstall services -dialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \ - "Would you like to add users to the installed system now?" 0 0 && \ - bsdinstall adduser + dialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \ + "Would you like to add users to the installed system now?" 0 0 && \ + bsdinstall adduser +fi trap error SIGINT # SIGINT is bad again bsdinstall config || error "Failed to save config" cp /etc/resolv.conf $1/etc cp /etc/localtime $1/etc +# Run post-install script +if [ -f $TMPDIR/bsdinstall-installscript-ab ]; then + cp $TMPDIR/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript + chmod a+x $BSDINSTALL_CHROOT/tmp/installscript + mount -t devfs devfs "$BSDINSTALL_CHROOT/dev" + chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1 + umount "$BSDINSTALL_CHROOT/dev" + rm $BSDINSTALL_CHROOT/tmp/installscript +fi + bsdinstall entropy f_dprintf "Installation Completed at %s" "$(date)"