Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/freebsd-update/freebsd-update.sh
| Show First 20 Lines • Show All 384 Lines • ▼ Show 20 Lines | *) | ||||
| return 1 | return 1 | ||||
| ;; | ;; | ||||
| esac | esac | ||||
| else | else | ||||
| return 1 | return 1 | ||||
| fi | fi | ||||
| } | } | ||||
| config_CreateBootEnv () { | |||||
| if [ -z ${BOOTENV} ]; then | |||||
| case $1 in | |||||
| [Yy][Ee][Ss]) | |||||
| BOOTENV=yes | |||||
| ;; | |||||
| [Nn][Oo]) | |||||
| BOOTENV=no | |||||
| ;; | |||||
| *) | |||||
| return 1 | |||||
| ;; | |||||
| esac | |||||
| else | |||||
| return 1 | |||||
| fi | |||||
| } | |||||
| # Handle one line of configuration | # Handle one line of configuration | ||||
| configline () { | configline () { | ||||
| if [ $# -eq 0 ]; then | if [ $# -eq 0 ]; then | ||||
| return | return | ||||
| fi | fi | ||||
| OPT=$1 | OPT=$1 | ||||
| shift | shift | ||||
| ▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | default_params () { | ||||
| config_AllowDelete yes | config_AllowDelete yes | ||||
| config_KeepModifiedMetadata yes | config_KeepModifiedMetadata yes | ||||
| config_BaseDir / | config_BaseDir / | ||||
| config_VerboseLevel stats | config_VerboseLevel stats | ||||
| config_StrictComponents no | config_StrictComponents no | ||||
| config_BackupKernel yes | config_BackupKernel yes | ||||
| config_BackupKernelDir /boot/kernel.old | config_BackupKernelDir /boot/kernel.old | ||||
| config_BackupKernelSymbolFiles no | config_BackupKernelSymbolFiles no | ||||
| config_CreateBootEnv yes | |||||
| # Merge these defaults into the earlier-configured settings | # Merge these defaults into the earlier-configured settings | ||||
| mergeconfig | mergeconfig | ||||
| } | } | ||||
| # Set utility output filtering options, based on ${VERBOSELEVEL} | # Set utility output filtering options, based on ${VERBOSELEVEL} | ||||
| fetch_setup_verboselevel () { | fetch_setup_verboselevel () { | ||||
| case ${VERBOSELEVEL} in | case ${VERBOSELEVEL} in | ||||
| ▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | install_check_params () { | ||||
| BOOTFILE=`sysctl -n kern.bootfile` | BOOTFILE=`sysctl -n kern.bootfile` | ||||
| KERNELDIR=${BOOTFILE%/kernel} | KERNELDIR=${BOOTFILE%/kernel} | ||||
| if ! [ -d ${KERNELDIR} ]; then | if ! [ -d ${KERNELDIR} ]; then | ||||
| echo "Cannot identify running kernel" | echo "Cannot identify running kernel" | ||||
| exit 1 | exit 1 | ||||
| fi | fi | ||||
| } | } | ||||
| # Creates a new boot environment | |||||
| install_create_be () { | |||||
| # Figure out if we're running in a jail and return if we are | |||||
| if [ `sysctl -n security.jail.jailed` = 1 ]; then | |||||
| return 1 | |||||
| fi | |||||
| # Create a boot environment if enabled | |||||
| if [ ${BOOTENV} = yes ]; then | |||||
| bectl check 2>/dev/null | |||||
| case $? in | |||||
| 0) | |||||
| # Boot environment are supported | |||||
| CREATEBE=yes | |||||
| ;; | |||||
| 64) | |||||
| # Bectl doesn't support check (old version?), fall back to manual checks | |||||
| CREATEBE=no | |||||
| if `kldstat | grep zfs.ko >/dev/null`; then | |||||
allanjude: `kldstat -q -m zfs` will return 0 if ZFS is loaded, and 1 otherwise, without printing anything… | |||||
kevansUnsubmitted Not Done Inline ActionsI think we can just drop this entire case and commit it otherwise as-is, at this rate. bectl check made it into 12.1, and unfortunately this stalled out for too long for 11.4 to matter (though it has check as well), I think. If one gets to a point that they have *this* version of freebsd-update that knows about bectl, they should already have a bectl check installed. kevans: I think we can just drop this entire case and commit it otherwise as-is, at this rate. `bectl… | |||||
| for BOOTFS in `zpool get -Hp -o value bootfs`; do | |||||
| if ! [ ${BOOTFS} = "-" ]; then | |||||
| MOUNTED=`zfs get -Hp -o value mounted ${BOOTFS}` | |||||
| MOUNTPOINT=`zfs get -Hp -o value mountpoint ${BOOTFS}` | |||||
| if [ ${MOUNTED} = yes ] && [ ${MOUNTPOINT} = "/" ]; then | |||||
| CREATEBE=yes | |||||
| fi | |||||
| fi | |||||
| done | |||||
| fi | |||||
| ;; | |||||
| 255) | |||||
| # Boot environments are not supported | |||||
| CREATEBE=no | |||||
| ;; | |||||
| *) | |||||
| # If bectl returns an unexpected exit code, don't create a BE | |||||
| CREATEBE=no | |||||
| ;; | |||||
| esac | |||||
| if [ ${CREATEBE} = yes ]; then | |||||
| echo -n "Creating snapshot of existing boot environment... " | |||||
| VERSION=`freebsd-version -k` | |||||
| TIMESTAMP=`date +"%Y-%m-%d_%H%M%S"` | |||||
| bectl create ${VERSION}_${TIMESTAMP} | |||||
| if [ $? -eq 0 ]; then | |||||
| echo "done."; | |||||
| else | |||||
| echo "failed." | |||||
| exit 1 | |||||
| fi | |||||
| fi | |||||
| fi | |||||
| } | |||||
| # Perform sanity checks and set some final parameters in | # Perform sanity checks and set some final parameters in | ||||
| # preparation for UNinstalling updates. | # preparation for UNinstalling updates. | ||||
| rollback_check_params () { | rollback_check_params () { | ||||
| # Check that we are root. All sorts of things won't work otherwise. | # Check that we are root. All sorts of things won't work otherwise. | ||||
| if [ `id -u` != 0 ]; then | if [ `id -u` != 0 ]; then | ||||
| echo "You must be root to run this." | echo "You must be root to run this." | ||||
| exit 1 | exit 1 | ||||
| fi | fi | ||||
| ▲ Show 20 Lines • Show All 2,453 Lines • ▼ Show 20 Lines | |||||
| cmd_upgrade () { | cmd_upgrade () { | ||||
| upgrade_check_params | upgrade_check_params | ||||
| upgrade_run || exit 1 | upgrade_run || exit 1 | ||||
| } | } | ||||
| # Install downloaded updates. | # Install downloaded updates. | ||||
| cmd_install () { | cmd_install () { | ||||
| install_check_params | install_check_params | ||||
| install_create_be | |||||
| install_run || exit 1 | install_run || exit 1 | ||||
| } | } | ||||
| # Rollback most recently installed updates. | # Rollback most recently installed updates. | ||||
| cmd_rollback () { | cmd_rollback () { | ||||
| rollback_check_params | rollback_check_params | ||||
| rollback_run || exit 1 | rollback_run || exit 1 | ||||
| } | } | ||||
| Show All 24 Lines | |||||
kldstat -q -m zfs will return 0 if ZFS is loaded, and 1 otherwise, without printing anything
Your current code has the slightly beneficial side-effect of also matching openzfs.ko for those using the sysutils/openzfs port, but I imagine that was unintentional.