Page MenuHomeFreeBSD

D58966.id184563.diff
No OneTemporary

D58966.id184563.diff

diff --git a/tools/tools/nanobsd/customizations.sh b/tools/tools/nanobsd/customizations.sh
new file mode 100644
--- /dev/null
+++ b/tools/tools/nanobsd/customizations.sh
@@ -0,0 +1,202 @@
+#!/bin/sh
+#
+# Copyright (c) 2005 Poul-Henning Kamp.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+#
+
+# Poudriere-compatible package list
+NANO_PACKAGE_LIST=""
+
+# where package metadata gets placed
+NANO_PKG_META_BASE=/var/db
+
+# Path to the files directory used by cust_install_files()
+NANO_CUST_FILESDIR="${NANO_TOOLS}/defaults/Files"
+
+#
+# Path to mtree file to apply to anything copied by cust_install_files().
+# If you specify this, the mtree file *must* have an entry for every file and
+# directory located in Files
+#
+NANO_CUST_FILES_MTREE="${NANO_TOOLS}/defaults/Files.mtree"
+
+#
+# boot2 flags/options.
+# Default force serial console
+#
+NANO_BOOT2CFG="-h -S115200"
+
+#######################################################################
+# Setup serial console
+
+# Enable serial console in /etc/ttys and write NANO_BOOT2CFG to /boot.config
+cust_comconsole() {
+ # Enable getty on console
+ sed -i "" -e '/^tty[du]0/s/off/onifconsole/' ${NANO_WORLDDIR}/etc/ttys
+
+ # Disable getty on syscons or vt devices
+ sed -i "" -E '/^ttyv[0-8]/s/\ton(ifexists)?/\toff/' ${NANO_WORLDDIR}/etc/ttys
+
+ # Tell loader to use serial console early
+ echo "${NANO_BOOT2CFG}" > ${NANO_WORLDDIR}/boot.config
+ tgt_touch boot.config
+
+ if $do_precompiled && [ -z "$NANO_NOPKGBASE" ]; then
+ tgt_pkg_update_file_sha256 etc/ttys
+ tgt_pkg_update_config_files_content etc/ttys
+ fi
+}
+
+#######################################################################
+# Allow root login via ssh
+
+# Enable root login via SSH by setting PermitRootLogin yes in sshd_config
+cust_allow_ssh_root() {
+ sed -i "" -E 's/^#?PermitRootLogin.*/PermitRootLogin yes/' \
+ ${NANO_WORLDDIR}/etc/ssh/sshd_config
+
+ if $do_precompiled && [ -z "$NANO_NOPKGBASE" ]; then
+ tgt_pkg_update_file_sha256 etc/ssh/sshd_config
+ tgt_pkg_update_config_files_content etc/ssh/sshd_config
+ fi
+}
+
+#######################################################################
+# Install the stuff under NANO_CUST_FILESDIR
+
+# Copy all files from NANO_CUST_FILESDIR into NANO_WORLDDIR
+cust_install_files() {
+ (
+ cd "$NANO_CUST_FILESDIR"
+ find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)/' |
+ cpio ${CPIO_SYMLINK} -Ldumpv "$NANO_WORLDDIR"
+
+ if [ -n "$NANO_CUST_FILES_MTREE" ] && [ -f "$NANO_CUST_FILES_MTREE" ]; then
+ if [ -n "$NANO_NOPRIV_BUILD" ]; then
+ # Entries in NANO_CUST_FILES_MTREE must precede NANO_METALOG
+ cat "$NANO_CUST_FILES_MTREE" "$NANO_METALOG" > "${NANO_METALOG}.tmp"
+ mv "${NANO_METALOG}.tmp" "$NANO_METALOG"
+ else
+ CR "mtree -eiU -p /" <"$NANO_CUST_FILES_MTREE"
+ fi
+ else
+ tgt_touch $(find * -type f)
+ fi
+ )
+}
+
+#######################################################################
+# Install packages from ${NANO_PACKAGE_DIR}
+
+# Install packages listed in NANO_PACKAGE_LIST from NANO_PACKAGE_DIR
+cust_pkgng() {
+ if ! $do_root && [ -n "$NANO_NOPRIV_BUILD" ]; then
+ pprint 2 'Skipping "cust_pkgng" (unprivileged builds not supported yet)'
+ return 0
+ fi
+
+ mkdir -p "${NANO_WORLDDIR}/var/cache/pkg"
+
+ if [ -z "$NANO_PACKAGE_LIST" ]; then
+ err "NANO_PACKAGE_LIST not set."
+ fi
+ NANO_PACKAGE_LIST="ports-mgmt/pkg ${NANO_PACKAGE_LIST}"
+
+ if [ -d "$NANO_PACKAGE_DIR" ]; then
+ mount -t nullfs -o noatime -o ro "$NANO_PACKAGE_DIR" "${NANO_WORLDDIR}/var/cache/pkg"
+ trap "nano_umount ${NANO_WORLDDIR}/var/cache/pkg" 1 2 15 EXIT
+ else
+ # Download precompiled into nano_pkg_cachedir
+ if $do_clean; then
+ tgt_pkg install -F $NANO_PACKAGE_LIST
+ fi
+ mount -t nullfs -o noatime -o ro "$(nano_pkg_cachedir)" "${NANO_WORLDDIR}/var/cache/pkg"
+ trap "nano_umount ${NANO_WORLDDIR}/var/cache/pkg" 1 2 15 EXIT
+ fi
+
+ cp /etc/resolv.conf "${NANO_WORLDDIR}/etc/resolv.conf"
+ tgt_pkg_chroot install $NANO_PACKAGE_LIST
+ rm -f "${NANO_WORLDDIR}/etc/resolv.conf"
+ rm -rf "${NANO_WORLDDIR}/var/db/pkg/repos/"*
+
+ if [ -d "$NANO_PACKAGE_DIR" ]; then
+ trap - 1 2 15 EXIT
+ nano_umount "${NANO_WORLDDIR}/var/cache/pkg"
+ fi
+}
+
+#######################################################################
+# Patch adduser(8)
+
+# Patch adduser script
+cust_adduser() {
+ (
+ cd "$NANO_WORLDDIR"
+
+ [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 0666 usr/sbin/adduser
+ if ! patch -s -V none usr/sbin/adduser <<\EOF
+--- usr/sbin/adduser
++++ usr/sbin/adduser
+@@ -197,6 +197,9 @@ add_user() {
+ local _shell= _class= _dotdir= _expire= _pwexpire= _passwd= _upasswd=
+ local _passwdmethod= _pwcmd=
+
++ ${MOUNTCMD} -uw /
++ trap "${MOUNTCMD} -ur /" 1 2 15 EXIT
++
+ # Is this a configuration run? If so, don't modify user database.
+ #
+ if [ -n "$configflag" ]; then
+@@ -322,6 +325,20 @@ add_user() {
+ info "Sent welcome message to ($username)."
+ fi
+ fi
++
++ ${MOUNTCMD} -ur /
++ trap - 1 2 15 EXIT
++
++ touch "/etc/ssh/authorized_keys/${username}"
++ chown "${username}:${ulogingroup:-$username}" "/etc/ssh/authorized_keys/${username}"
++ chmod 0600 "/etc/ssh/authorized_keys/${username}"
++
++ ${MOUNTCMD} /cfg
++ trap "${UMOUNTCMD} /cfg" 1 2 15 EXIT
++ cp -p /etc/master.passwd /etc/passwd /etc/pwd.db /etc/spwd.db /etc/group /cfg
++ cp -p "/etc/ssh/authorized_keys/${username}" "/cfg/ssh/authorized_keys/${username}"
++ ${UMOUNTCMD} /cfg
++ trap - 1 2 15 EXIT
+ }
+
+ # get_user
+EOF
+ then
+ err "Patching /usr/sbin/adduser failed!"
+ fi
+ [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 0555 usr/sbin/adduser
+ if [ -z "$NANO_NOPKGBASE" ]; then
+ tgt_pkg_update_file_sha256 usr/sbin/adduser
+ fi
+ )
+}
diff --git a/tools/tools/nanobsd/defaults.sh b/tools/tools/nanobsd/defaults.sh
--- a/tools/tools/nanobsd/defaults.sh
+++ b/tools/tools/nanobsd/defaults.sh
@@ -44,20 +44,6 @@
# Where nanobsd additional files live under the source tree
NANO_TOOLS=tools/tools/nanobsd
-# Where cust_pkgng() finds packages to install
-NANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg
-NANO_PACKAGE_LIST="*"
-
-# where package metadata gets placed
-NANO_PKG_META_BASE=/var/db
-
-# Path to the files directory used by cust_install_files()
-NANO_CUST_FILESDIR="${NANO_TOOLS}/Files"
-# Path to mtree file to apply to anything copied by cust_install_files().
-# If you specify this, the mtree file *must* have an entry for every file and
-# directory located in Files.
-#NANO_CUST_FILES_MTREE=""
-
# Use the time of the last commit as a timestamp when doing a NO_PRIV build.
NANO_TIMESTAMP=$(git log -1 --format=%ct || true)
@@ -163,10 +149,6 @@
# Swap partition encryption
NANO_SWAP_ENCRYPTION=""
-# boot2 flags/options
-# default force serial console
-NANO_BOOT2CFG="-h -S115200"
-
# EFI System Partition size in bytes
NANO_EFI_BOOTPART_SIZE="260Mi"
@@ -1174,7 +1156,6 @@
# and tweaked them in the standard way.
#
run_customize() {
-
pprint 2 "run customize scripts"
for c in $NANO_CUSTOMIZE; do
pprint 2 "customize \"$c\""
@@ -1625,122 +1606,6 @@
printf "%s" "$(printf 'scale=0; %s\n' "$result" | tr 'x' '*' | bc)"
}
-#######################################################################
-# Setup serial console
-
-#######################################################################
-# Allow root login via ssh
-
-# Enable root login via SSH by setting PermitRootLogin yes in sshd_config
-cust_allow_ssh_root() {
- sed -i "" -E 's/^#?PermitRootLogin.*/PermitRootLogin yes/' \
- ${NANO_WORLDDIR}/etc/ssh/sshd_config
-
- if $do_precompiled && [ -z "$NANO_NOPKGBASE" ]; then
- tgt_pkg_update_file_sha256 etc/ssh/sshd_config
- tgt_pkg_update_config_files_content etc/ssh/sshd_config
- fi
-}
-
-#######################################################################
-# Install the stuff under ./Files
-
-# Copy all files from NANO_TOOLS/Files into NANO_WORLDDIR
-cust_install_files() {
- (
- cd "$NANO_CUST_FILESDIR"
- find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)/' |
- cpio ${CPIO_SYMLINK} -Ldumpv "$NANO_WORLDDIR"
-
- if [ -n "$NANO_CUST_FILES_MTREE" ] && [ -f "$NANO_CUST_FILES_MTREE" ]; then
- if [ -n "$NANO_NOPRIV_BUILD" ]; then
- # Entries in NANO_CUST_FILES_MTREE must precede NANO_METALOG
- cat "$NANO_CUST_FILES_MTREE" "$NANO_METALOG" > "${NANO_METALOG}.tmp"
- mv "${NANO_METALOG}.tmp" "$NANO_METALOG"
- else
- CR "mtree -eiU -p /" <"$NANO_CUST_FILES_MTREE"
- fi
- else
- tgt_touch $(find * -type f)
- fi
- )
-}
-
-#######################################################################
-# Install packages from ${NANO_PACKAGE_DIR}
-
-#
-# Bootstrap pkg and install all packages from NANO_PACKAGE_DIR
-# into NANO_WORLDDIR via a nullfs-mounted chroot
-#
-cust_pkgng() {
- if ! $do_root && [ -n "$NANO_NOPRIV_BUILD" ]; then
- pprint 2 'Skipping "cust_pkgng" (unprivileged builds not supported yet)'
- return 0
- fi
-
- mkdir -p ${NANO_WORLDDIR}/usr/local/etc
- local PKG_CONF="${NANO_WORLDDIR}/usr/local/etc/pkg.conf"
- local PKGCMD="env BATCH=YES ASSUME_ALWAYS_YES=YES PKG_DBDIR=${NANO_PKG_META_BASE}/pkg SIGNATURE_TYPE=none /usr/sbin/pkg"
-
- # Ensure pkg.conf points pkg to where the package meta data lives.
- touch ${PKG_CONF}
- if grep -Eiq '^PKG_DBDIR:.*' ${PKG_CONF}; then
- sed -i -e "\|^PKG_DBDIR:.*|Is||PKG_DBDIR: "\"${NANO_PKG_META_BASE}/pkg\""|" ${PKG_CONF}
- else
- echo "PKG_DBDIR: \"${NANO_PKG_META_BASE}/pkg\"" >> ${PKG_CONF}
- fi
-
- # If the package directory doesn't exist, we're done.
- NANO_PACKAGE_DIR="$(realpath $NANO_PACKAGE_DIR)"
- if [ ! -d ${NANO_PACKAGE_DIR} ]; then
- echo "DONE 0 packages"
- return 0
- fi
-
- # Find a pkg-* package
- for x in $(find -s ${NANO_PACKAGE_DIR} -iname 'pkg-*'); do
- _NANO_PKG_PACKAGE=$(basename "$x")
- done
- if [ -z "${_NANO_PKG_PACKAGE}" -o ! -f "${NANO_PACKAGE_DIR}/${_NANO_PKG_PACKAGE}" ]; then
- err "FAILED: need a pkg/ package for bootstrapping"
- fi
-
- # Mount packages into chroot
- mkdir -p ${NANO_WORLDDIR}/_.p
- mount -t nullfs -o noatime -o ro ${NANO_PACKAGE_DIR} ${NANO_WORLDDIR}/_.p
- mount -t devfs devfs ${NANO_WORLDDIR}/dev
-
- trap "nano_umount ${NANO_WORLDDIR}/dev; nano_umount ${NANO_WORLDDIR}/_.p ; rm -xrf ${NANO_WORLDDIR}/_.p" 1 2 15 EXIT
-
- # Install pkg-* package
- CR "${PKGCMD} add /_.p/${_NANO_PKG_PACKAGE}"
-
- (
- # Expand any glob characters in package list
- cd "${NANO_PACKAGE_DIR}"
- _PKGS=$(find ${NANO_PACKAGE_LIST} -not -name "${_NANO_PKG_PACKAGE}" -print | sort -u)
-
- # Show todo
- todo=$(echo "$_PKGS" | wc -l)
- echo "=== TODO: $todo"
- echo "$_PKGS"
- echo "==="
-
- # Install packages
- for _PKG in $_PKGS; do
- CR "${PKGCMD} add /_.p/${_PKG}"
- done
- )
-
- CR0 "${PKGCMD} info"
-
- trap - 1 2 15 EXIT
- nano_umount ${NANO_WORLDDIR}/dev
- nano_umount ${NANO_WORLDDIR}/_.p
- rm -xrf ${NANO_WORLDDIR}/_.p
-}
-
#######################################################################
# Convenience function:
# Register all args as early customize function to run just before
diff --git a/tools/tools/nanobsd/nanobsd.sh b/tools/tools/nanobsd/nanobsd.sh
--- a/tools/tools/nanobsd/nanobsd.sh
+++ b/tools/tools/nanobsd/nanobsd.sh
@@ -28,6 +28,19 @@
set -e
+nanobsd_sh=$(realpath $0)
+topdir=$(dirname ${nanobsd_sh})
+. "${topdir}/defaults.sh"
+. "${topdir}/customizations.sh"
+. "${topdir}/_xxx_includes.subr" # XXX ideally, this file should not exist
+
+is_defined() {
+ case $(type $1 2>/dev/null) in
+ *function) return 0 ;;
+ *) return 1 ;;
+ esac
+}
+
legacy() {
# Pull in legacy stuff on demand
. "${topdir}/legacy.sh"
@@ -38,18 +51,6 @@
. "${topdir}/gpt.sh"
}
-is_defined() {
- case $(type $1 2>/dev/null) in
- *function) return 0 ;;
- *) return 1 ;;
- esac
-}
-
-nanobsd_sh=$(realpath $0)
-topdir=$(dirname ${nanobsd_sh})
-. "${topdir}/_xxx_includes.subr"
-. "${topdir}/defaults.sh"
-
#######################################################################
# Parse arguments

File Metadata

Mime Type
text/plain
Expires
Fri, Aug 28, 2:05 PM (17 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37458093
Default Alt Text
D58966.id184563.diff (12 KB)

Event Timeline