From owner-svn-src-all@FreeBSD.ORG Mon Nov 19 15:03:20 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7D92054E; Mon, 19 Nov 2012 15:03:20 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 607728FC12; Mon, 19 Nov 2012 15:03:20 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qAJF3Kcx077722; Mon, 19 Nov 2012 15:03:20 GMT (envelope-from emaste@svn.freebsd.org) Received: (from emaste@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qAJF3K2I077720; Mon, 19 Nov 2012 15:03:20 GMT (envelope-from emaste@svn.freebsd.org) Message-Id: <201211191503.qAJF3K2I077720@svn.freebsd.org> From: Ed Maste Date: Mon, 19 Nov 2012 15:03:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r243279 - stable/9/sbin/reboot X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Nov 2012 15:03:20 -0000 Author: emaste Date: Mon Nov 19 15:03:19 2012 New Revision: 243279 URL: http://svnweb.freebsd.org/changeset/base/243279 Log: MFC r230812: Add -e to set arbitrary kernel environment variables. Nextboot(8) can now set any combination of kernel name (-k), kernel options (-o), and environment strings (-e). As a result of this change -k also becomes optional. Modified: stable/9/sbin/reboot/nextboot.8 stable/9/sbin/reboot/nextboot.sh Directory Properties: stable/9/sbin/reboot/ (props changed) Modified: stable/9/sbin/reboot/nextboot.8 ============================================================================== --- stable/9/sbin/reboot/nextboot.8 Mon Nov 19 12:10:36 2012 (r243278) +++ stable/9/sbin/reboot/nextboot.8 Mon Nov 19 15:03:19 2012 (r243279) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 4, 2002 +.Dd November 19, 2012 .Dt NEXTBOOT 8 .Os .Sh NAME @@ -32,15 +32,17 @@ .Nd "specify an alternate kernel and boot flags for the next reboot" .Sh SYNOPSIS .Nm +.Op Fl e Ar variable=value .Op Fl f +.Op Fl k Ar kernel .Op Fl o Ar options -.Fl k Ar kernel .Nm .Fl D .Sh DESCRIPTION The .Nm -utility allows specifying an alternate kernel and/or boot flags for the +utility allows specifying some combination of an alternate kernel, boot flags +and kernel environment for the next time the machine is booted. Once the .Xr loader 8 @@ -58,6 +60,11 @@ with this option removes an existing .Nm configuration. +.It Fl e Ar variable=value +This option adds the provided variable and value to the kernel environment. +The value is quoted when written to the +.Nm +configuration. .It Fl f This option disables the sanity checking which checks if the kernel really exists Modified: stable/9/sbin/reboot/nextboot.sh ============================================================================== --- stable/9/sbin/reboot/nextboot.sh Mon Nov 19 12:10:36 2012 (r243278) +++ stable/9/sbin/reboot/nextboot.sh Mon Nov 19 15:03:19 2012 (r243279) @@ -2,31 +2,59 @@ # # Copyright 2002. Gordon Tetlow. # gordon@FreeBSD.org +# Copyright (c) 2012 Sandvine Incorporated. All rights reserved. # # $FreeBSD$ delete="NO" +kenv= force="NO" nextboot_file="/boot/nextboot.conf" +add_kenv() +{ + local var value + + var=$1 + # strip literal quotes if passed in + value=${2%\"*} + value=${value#*\"} + + if [ -n "${kenv}" ]; then + kenv="${kenv} +" + fi + kenv="${kenv}${var}=\"${value}\"" +} + display_usage() { - echo "Usage: nextboot [-f] [-o options] -k kernel" + echo "Usage: nextboot [-e variable=value] [-f] [-k kernel] [-o options]" echo " nextboot -D" } -while getopts "Dfk:o:" argument ; do +while getopts "De:fk:o:" argument ; do case "${argument}" in D) delete="YES" ;; + e) + var=${OPTARG%%=*} + value=${OPTARG#*=} + if [ -z "$var" -o -z "$value" ]; then + display_usage + exit 1 + fi + add_kenv "$var" "$value" + ;; f) force="YES" ;; k) kernel="${OPTARG}" + add_kenv kernel "$kernel" ;; o) - kernel_options="${OPTARG}" + add_kenv kernel_options "${OPTARG}" ;; *) display_usage @@ -40,12 +68,12 @@ if [ ${delete} = "YES" ]; then exit 0 fi -if [ "xxx${kernel}" = "xxx" ]; then +if [ -z "${kenv}" ]; then display_usage exit 1 fi -if [ ${force} = "NO" -a ! -d /boot/${kernel} ]; then +if [ -n "${kernel}" -a ${force} = "NO" -a ! -d /boot/${kernel} ]; then echo "Error: /boot/${kernel} doesn't exist. Use -f to override." exit 1 fi @@ -60,6 +88,5 @@ done cat > ${nextboot_file} << EOF nextboot_enable="YES" -kernel="${kernel}" -kernel_options="${kernel_options}" +$kenv EOF