Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Jun 2021 19:54:21 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 6f4c1456b51d - main - bsdinstall: Allow automation in jails
Message-ID:  <202106111954.15BJsLGW076516@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=6f4c1456b51dc35c03b2c02cc06e8b4308779855

commit 6f4c1456b51dc35c03b2c02cc06e8b4308779855
Author:     eoli3n <jonathan.kirszling@runbox.com>
AuthorDate: 2021-06-07 20:49:02 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
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)"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106111954.15BJsLGW076516>