2002-05-24 04:06:03 +00:00
|
|
|
#! /bin/sh
|
|
|
|
#
|
2012-02-07 14:06:30 +00:00
|
|
|
# Copyright (c) 2002 Gordon Tetlow. All rights reserved.
|
2012-01-31 15:32:05 +00:00
|
|
|
# Copyright (c) 2012 Sandvine Incorporated. All rights reserved.
|
2002-05-24 04:06:03 +00:00
|
|
|
#
|
2012-02-07 14:06:30 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2002-05-24 04:06:03 +00:00
|
|
|
# $FreeBSD$
|
|
|
|
|
2016-04-10 01:25:12 +00:00
|
|
|
append="NO"
|
2002-05-24 04:06:03 +00:00
|
|
|
delete="NO"
|
2012-01-31 15:32:05 +00:00
|
|
|
kenv=
|
2002-05-24 04:06:03 +00:00
|
|
|
force="NO"
|
|
|
|
nextboot_file="/boot/nextboot.conf"
|
|
|
|
|
2012-01-31 15:32:05 +00:00
|
|
|
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}\""
|
|
|
|
}
|
|
|
|
|
2002-05-24 04:06:03 +00:00
|
|
|
display_usage() {
|
2016-04-10 01:25:12 +00:00
|
|
|
cat <<-EOF
|
2016-04-14 18:03:55 +00:00
|
|
|
Usage: nextboot [-af] [-e variable=value] [-k kernel] [-o options]
|
2016-04-10 01:25:12 +00:00
|
|
|
nextboot -D
|
|
|
|
EOF
|
2002-05-24 04:06:03 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 01:25:12 +00:00
|
|
|
while getopts "aDe:fk:o:" argument ; do
|
2006-01-18 04:48:45 +00:00
|
|
|
case "${argument}" in
|
2016-04-10 01:25:12 +00:00
|
|
|
a)
|
|
|
|
append="YES"
|
|
|
|
;;
|
2006-01-18 04:48:45 +00:00
|
|
|
D)
|
2002-05-24 04:06:03 +00:00
|
|
|
delete="YES"
|
|
|
|
;;
|
2012-01-31 15:32:05 +00:00
|
|
|
e)
|
|
|
|
var=${OPTARG%%=*}
|
|
|
|
value=${OPTARG#*=}
|
|
|
|
if [ -z "$var" -o -z "$value" ]; then
|
|
|
|
display_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
add_kenv "$var" "$value"
|
|
|
|
;;
|
2006-01-18 04:48:45 +00:00
|
|
|
f)
|
2002-05-24 04:06:03 +00:00
|
|
|
force="YES"
|
|
|
|
;;
|
2006-01-18 04:48:45 +00:00
|
|
|
k)
|
|
|
|
kernel="${OPTARG}"
|
2012-01-31 15:32:05 +00:00
|
|
|
add_kenv kernel "$kernel"
|
2002-05-24 04:06:03 +00:00
|
|
|
;;
|
2006-01-18 04:48:45 +00:00
|
|
|
o)
|
2012-01-31 15:32:05 +00:00
|
|
|
add_kenv kernel_options "${OPTARG}"
|
2002-05-24 04:06:03 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
display_usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ ${delete} = "YES" ]; then
|
|
|
|
rm -f ${nextboot_file}
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2012-01-31 15:32:05 +00:00
|
|
|
if [ -z "${kenv}" ]; then
|
2002-05-24 04:06:03 +00:00
|
|
|
display_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-01-31 15:32:05 +00:00
|
|
|
if [ -n "${kernel}" -a ${force} = "NO" -a ! -d /boot/${kernel} ]; then
|
2002-05-24 04:06:03 +00:00
|
|
|
echo "Error: /boot/${kernel} doesn't exist. Use -f to override."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2010-09-17 09:50:36 +00:00
|
|
|
df -Tn "/boot/" 2>/dev/null | while read _fs _type _other ; do
|
|
|
|
[ "zfs" = "${_type}" ] || continue
|
|
|
|
cat 1>&2 <<-EOF
|
|
|
|
WARNING: loader(8) has only R/O support for ZFS
|
|
|
|
nextboot.conf will NOT be reset in case of kernel boot failure
|
|
|
|
EOF
|
|
|
|
done
|
|
|
|
|
2016-04-10 01:25:12 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
nextboot_tmp=$(mktemp $(dirname ${nextboot_file})/nextboot.XXXXXX)
|
|
|
|
|
|
|
|
if [ ${append} = "YES" -a -f ${nextboot_file} ]; then
|
|
|
|
cp -f ${nextboot_file} ${nextboot_tmp}
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat >> ${nextboot_tmp} << EOF
|
2002-05-24 04:06:03 +00:00
|
|
|
nextboot_enable="YES"
|
2012-01-31 15:32:05 +00:00
|
|
|
$kenv
|
2002-05-24 04:06:03 +00:00
|
|
|
EOF
|
2016-04-10 01:25:12 +00:00
|
|
|
|
|
|
|
fsync ${nextboot_tmp}
|
|
|
|
|
|
|
|
mv ${nextboot_tmp} ${nextboot_file}
|