|
| 1 | +#!/bin/bash |
| 2 | +# vim: softtabstop=2 shiftwidth=2 expandtab |
| 3 | +WIDTH="$( tput cols )" |
| 4 | +PREVIEW_SIZE=$(( WIDTH - 26 )) |
| 5 | +[ ${PREVIEW_SIZE} -lt 10 ] && PREVIEW_SIZE=10 |
| 6 | + |
| 7 | +[ -z "${FUZZYSEL}" ] && FUZZYSEL="fzf" |
| 8 | + |
| 9 | +center() { |
| 10 | + printf "%*s" $(( (${#1} + WIDTH ) / 2)) "${1}" |
| 11 | +} |
| 12 | + |
| 13 | +colorize() { |
| 14 | + color="${1}" |
| 15 | + shift |
| 16 | + case "${color}" in |
| 17 | + black) echo -e -n '\033[0;30m' ;; |
| 18 | + red) echo -e -n '\033[0;31m' ;; |
| 19 | + green) echo -e -n '\033[0;32m' ;; |
| 20 | + orange) echo -e -n '\033[0;33m' ;; |
| 21 | + blue) echo -e -n '\033[0;34m' ;; |
| 22 | + magenta) echo -e -n '\033[0;35m' ;; |
| 23 | + cyan) echo -e -n '\033[0;36m' ;; |
| 24 | + lightgray) echo -e -n '\033[0;37m' ;; |
| 25 | + darkgray) echo -e -n '\033[1;30m' ;; |
| 26 | + lightred) echo -e -n '\033[1;31m' ;; |
| 27 | + lightgreen) echo -e -n '\033[1;32m' ;; |
| 28 | + yellow) echo -e -n '\033[1;33m' ;; |
| 29 | + lightblue) echo -e -n '\033[1;34m' ;; |
| 30 | + lightmagenta) echo -e -n '\033[1;35m' ;; |
| 31 | + lightcyan) echo -e -n '\033[1;36m' ;; |
| 32 | + white) echo -e -n '\033[1;37m' ;; |
| 33 | + *) echo -e -n '\033[0m' ;; |
| 34 | + esac |
| 35 | + echo -e -n "$@" |
| 36 | + echo -e -n '\033[0m' |
| 37 | +} |
| 38 | + |
| 39 | +help_pager() { |
| 40 | + WANTED="${1}" |
| 41 | + |
| 42 | + SORTED=() |
| 43 | + for SECTION in "${SECTIONS[@]}"; do |
| 44 | + if ! [[ $SECTION =~ ${WANTED} ]]; then |
| 45 | + SORTED+=("${SECTION}") |
| 46 | + else |
| 47 | + FINAL="${SECTION}" |
| 48 | + fi |
| 49 | + done |
| 50 | + SORTED+=("${FINAL}") |
| 51 | + |
| 52 | + printf '%s\n' "${SORTED[@]}" | ${FUZZYSEL} \ |
| 53 | + --prompt 'Topic >' \ |
| 54 | + --with-nth=2.. \ |
| 55 | + --bind pgup:preview-up,pgdn:preview-down \ |
| 56 | + --preview="$0 -s {1}" \ |
| 57 | + --preview-window="right:${PREVIEW_SIZE}:sharp:wrap" \ |
| 58 | + --tac \ |
| 59 | + --color='border:6' |
| 60 | +} |
| 61 | + |
| 62 | +# shellcheck disable=SC2034 |
| 63 | +read -r -d '' MAIN <<EOF |
| 64 | +$( colorize magenta "$( center "Main Menu")" ) |
| 65 | +$( colorize lightblue "[ENTER] boot" ) |
| 66 | +Boot the selected boot environment, with the listed kernel and kernel command line visible at the top of the screen. |
| 67 | +
|
| 68 | +$( colorize lightblue "[ALT+K] kernel" ) |
| 69 | +Access a list of kernels available in the boot environment. |
| 70 | +
|
| 71 | +$( colorize lightblue "[ALT+D] set bootfs" ) |
| 72 | +Set the selected boot environment as the default for the pool. |
| 73 | +
|
| 74 | +The operation will fail gracefully if the pool can not be set $( colorize red "read/write" ). |
| 75 | +
|
| 76 | +$( colorize lightblue "[ALT+S] snapshots" ) |
| 77 | +Access a list of snapshots of the selected boot environment. New boot environments can be created here. |
| 78 | +
|
| 79 | +$( colorize lightblue "[ALT+C] cmdline" ) |
| 80 | +Temporarily edit the kernel command line that will be used to boot the chosen kernel in the selected boot environment. This change does not persist across reboots. |
| 81 | +
|
| 82 | +$( colorize lightblue "[ALT+P] Pool status" ) |
| 83 | +View the health and status of each imported pool. |
| 84 | +EOF |
| 85 | +SECTIONS+=("MAIN Main Menu") |
| 86 | + |
| 87 | +# shellcheck disable=SC2034 |
| 88 | +read -r -d '' SNAPSHOT <<EOF |
| 89 | +$( colorize magenta "$( center "Snapshot Management")" ) |
| 90 | +$( colorize lightblue "[ENTER] duplicate" ) |
| 91 | +Creation method: $( colorize red "zfs send | zfs recv" ) |
| 92 | +
|
| 93 | +This creates a boot environment that does not depend on any other snapshots, allowing it to be destroyed at will. The new boot environment will immediately consume space on the pool equal to the $( colorize lightgray "REFER" ) value of the snapshot. |
| 94 | +
|
| 95 | +A duplicated boot environment is commonly used if you need a new boot environment without any associated snapshots. |
| 96 | +
|
| 97 | +The operation will fail gracefully if the pool can not be set $( colorize red "read/write" ). |
| 98 | +
|
| 99 | +If $( colorize red "mbuffer" ) is available, it is used to provide feedback. |
| 100 | +
|
| 101 | +$( colorize lightblue "[ALT+X] clone and promote" ) |
| 102 | +Creation method: $( colorize red "zfs clone" ) , $( colorize red "zfs promote" ) |
| 103 | +
|
| 104 | +This creates a boot environment that is not dependent on the origin snapshot, allowing you to destroy the file system that the clone was created from. A cloned and promoted boot environment is commonly used when you've done an upgrade but want to preserve historical snapshots. |
| 105 | +
|
| 106 | +The operation will fail gracefully if the pool can not be set $( colorize red "read/write" ). |
| 107 | +
|
| 108 | +$( colorize lightblue "[ALT+C] clone" ) |
| 109 | +Creation method: $( colorize red "zfs clone" ) |
| 110 | +
|
| 111 | +This creates a boot environment from a snapshot with out modifying snapshot inheritence. A cloned boot environment is commonly used if you need to boot a previous system state for a short time and then discard the environment. |
| 112 | +
|
| 113 | +The operation will fail gracefully if the pool can not be set $( colorize red "read/write" ). |
| 114 | +
|
| 115 | +$( colorize lightblue "[ALT+D] diff" ) |
| 116 | +Compare the differences between the selected snapshot and the current state of the boot environment. |
| 117 | +
|
| 118 | +The operation will fail gracefully if the pool can not be set $( colorize red "read/write" ). |
| 119 | +EOF |
| 120 | +SECTIONS+=("SNAPSHOT Snapshot Management") |
| 121 | + |
| 122 | +# shellcheck disable=SC2034 |
| 123 | +read -r -d '' KERNEL <<EOF |
| 124 | +$( colorize magenta "$( center "Kernel Management")" ) |
| 125 | +$( colorize lightblue "[ENTER] boot" ) |
| 126 | +Immediately boot the chosen kernel in the selected boot environment, with the kernel command line shown at the top of the screen. |
| 127 | +
|
| 128 | +$( colorize lightblue "[ALT+D] set default" ) |
| 129 | +Set the selected kernel as the default for the boot environment. |
| 130 | +
|
| 131 | +The ZFS property $( colorize green "org.zfsbootmenu:kernel" ) is used to store the default kernel for the boot environment. |
| 132 | +
|
| 133 | +The operation will fail gracefully if the pool can not be set $( colorize red "read/write" ). |
| 134 | +
|
| 135 | +EOF |
| 136 | +SECTIONS+=("KERNEL Kernel Management") |
| 137 | + |
| 138 | +# shellcheck disable=SC2034 |
| 139 | +read -r -d '' DIFF <<EOF |
| 140 | +$( colorize magenta "$( center "Diff Viewer")" ) |
| 141 | +$( colorize lightblue "Column 1 descriptions" ) |
| 142 | + $( colorize orange "-") The path has been removed |
| 143 | + $( colorize orange "+") The path has been created |
| 144 | + $( colorize orange "M") The path has been modified |
| 145 | + $( colorize orange "R") The path has been renamed |
| 146 | +
|
| 147 | +$( colorize lightblue "Column 2 descriptions" ) |
| 148 | + $( colorize orange "B") Block device |
| 149 | + $( colorize orange "C") Character device |
| 150 | + $( colorize orange "/") Directory |
| 151 | + $( colorize orange ">") Door |
| 152 | + $( colorize orange "|") Named pipe |
| 153 | + $( colorize orange "@") Symbolic link |
| 154 | + $( colorize orange "P") Event port |
| 155 | + $( colorize orange "=") Socket |
| 156 | + $( colorize orange "F") Regular file |
| 157 | +
|
| 158 | +EOF |
| 159 | +SECTIONS+=("DIFF Diff Viewer") |
| 160 | + |
| 161 | +# shellcheck disable=SC2034 |
| 162 | +read -r -d '' POOL <<EOF |
| 163 | +$( colorize magenta "$( center "zpool Health")" ) |
| 164 | +$( colorize lightblue "[ALT+R] Rewind checkpoint" ) |
| 165 | +If a pool checkpoint is available, the selected pool is exported and then imported with the $( colorize red "--rewind-to-checkpoint" ) flag set. |
| 166 | +
|
| 167 | +The operation will fail gracefully if the pool can not be set $( colorize red "read/write" ). |
| 168 | +EOF |
| 169 | +SECTIONS+=("POOL ZPOOL Health") |
| 170 | + |
| 171 | +while getopts "lL:s:" opt; do |
| 172 | + case "${opt}" in |
| 173 | + l) |
| 174 | + printf '%s\n' "${SECTIONS[@]}" |
| 175 | + exit |
| 176 | + ;; |
| 177 | + L) |
| 178 | + help_pager "${OPTARG}" |
| 179 | + exit |
| 180 | + ;; |
| 181 | + s) |
| 182 | + section="${OPTARG}" |
| 183 | + echo "${!section}" | fold -s -w "${FZF_PREVIEW_COLUMNS}" |
| 184 | + exit |
| 185 | + ;; |
| 186 | + ?) |
| 187 | + exit |
| 188 | + ;; |
| 189 | + *) |
| 190 | + exit |
| 191 | + ;; |
| 192 | + esac |
| 193 | +done |
| 194 | + |
| 195 | +# No options detected, show the main help section |
| 196 | +help_pager "MAIN" |
0 commit comments