Skip to content

Commit

Permalink
Store options from KCL in a file for easy sourcing
Browse files Browse the repository at this point in the history
zfsbootmenu-parse-commandline.sh defines several configuration variables
based on KCL arguments; zfsbootmenu-exec.sh originally exported those to
the environment for use by zfsbootmenu-countdown.sh and zfsbootmenu.sh.
This works fine if zfsbootmenu.sh is only ever run in a local session.

When connecting via SSH and launching zfsbootmenu from the shell, these
configuration variables are not accessible. The simple solution is to
write the configuration into a file that can be sourced by both
zfsbootmenu-countdown.sh and zfsbootmenu.sh to populate their
environments regardless of the way they are called.

The boot-environment list has been renamed from "env" to "bootenvs" to
avoid confusion with the "environment" file.

Closes: #165.
  • Loading branch information
ahesford committed Apr 9, 2021
1 parent b6ef299 commit 9875115
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
7 changes: 7 additions & 0 deletions 90zfsbootmenu/zfsbootmenu-countdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ fi

mkdir -p "${BASE}"

if [ -r "${BASE}/environment" ]; then
# shellcheck disable=SC1090
source "${BASE}/environment"
else
zwarn "failed to source ZBM environment"
fi

# Write out a default or overridden hostid
if [ -n "${spl_hostid}" ] ; then
zinfo "writing /etc/hostid from command line: ${spl_hostid}"
Expand Down
21 changes: 12 additions & 9 deletions 90zfsbootmenu/zfsbootmenu-exec.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#!/bin/bash
# vim: softtabstop=2 shiftwidth=2 expandtab

export endian
export spl_hostid
export import_policy
export menu_timeout
export loglevel
export root
export zbm_sort
export zbm_set_hostid

# Disable all kernel messages to the console
echo 0 > /proc/sys/kernel/printk

Expand All @@ -30,6 +21,18 @@ echo "Loading ZFSBootMenu ..."
export BASE="/zfsbootmenu"
mkdir -p "${BASE}"

# shellcheck disable=SC2154
cat > "${BASE}/environment" <<EOF
export endian="${endian}"
export spl_hostid="${spl_hostid}"
export import_policy="${import_policy}"
export menu_timeout="${menu_timeout}"
export loglevel="${loglevel}"
export root="${root}"
export zbm_sort="${zbm_sort}"
export zbm_set_hostid="${zbm_set_hostid}"
EOF

getcmdline > "${BASE}/zbm.cmdline"

modprobe zfs 2>/dev/null
Expand Down
11 changes: 9 additions & 2 deletions 90zfsbootmenu/zfsbootmenu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ if [ -z "${BASE}" ]; then
export BASE="/zfsbootmenu"
fi

if [ -r "${BASE}/environment" ]; then
# shellcheck disable=SC1090
source "${BASE}/environment"
else
zwarn "failed to source ZBM environment"
fi

while [ ! -e "${BASE}/initialized" ]; do
if ! delay=5 prompt="Press [ESC] to cancel" timed_prompt "Waiting for ZFSBootMenu initialization"; then
zdebug "exited while waiting for initialization"
Expand Down Expand Up @@ -107,9 +114,9 @@ while true; do
if [ "${BE_SELECTED}" -eq 0 ]; then
# Populate the BE list, load any keys as necessary
# If no BEs were found, remove the empty environment file
populate_be_list "${BASE}/env" || rm -f "${BASE}/env"
populate_be_list "${BASE}/bootenvs" || rm -f "${BASE}/bootenvs"

bootenv="$( draw_be "${BASE}/env" )"
bootenv="$( draw_be "${BASE}/bootenvs" )"
ret=$?

if [ "${ret}" -eq 130 ]; then
Expand Down

0 comments on commit 9875115

Please sign in to comment.