diff options
author | dteske <dteske@FreeBSD.org> | 2013-07-05 20:13:00 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-07-05 20:13:00 +0000 |
commit | 1122138bea1ef696aced661063bcd826ae614b5b (patch) | |
tree | 3805171dbbfe2fac5edde1642a65919543ebb07a /usr.sbin/bsdconfig | |
parent | 66ac1c6e6758a9e0f1bdc441dc60c0ce17fbcb40 (diff) | |
download | FreeBSD-src-1122138bea1ef696aced661063bcd826ae614b5b.zip FreeBSD-src-1122138bea1ef696aced661063bcd826ae614b5b.tar.gz |
Add support for processing add-on modules from /usr/local/libexec/bsdconfig
(this is designed to allow new modules to be installed via ports/packages).
To prevent conflict with itself (sysutils/bsdconfig) as a port (which
installs its base modules to the above directory, it was long-ago decided
that so-called `base' modules would look different than now-defined `add-on'
modules. The structure of the contents for each is the same, but the naming
convention for the module directory must be different.
Base modules are named `[0-9][0-9][0-9].*' to allow SysV-style organization
while add-on modules must avoid this naming style and are simply listed in
alphabetical order by their module directory.
For example, a hypothetical port named `bsdconfig-jails' could install
/usr/local/libexec/bsdconfig/jails and provide `bsdconfig jails' as well as
a new menu entry in the main-menu.
Add-on modules are listed in the main-menu (when bsdconfig is executed with-
out arguments) below a separator after the last base-module.
In `bsdconfig -h' output, add-on modules are listed right alongside base
modules (sorted alphabetically in columnar fashion; left-to-right).
If a base module declares a keyword used by an add-on module, the base
module will always win when given `bsdconfig keyword' syntax.
Add-on modules should avoid declaring any keyword found in `script.subr' as
a reserved-word (`Resword') since bsdconfig also supports `bsdconfig resword'
as a fall-back if no keyword is found to be declared by any module.
Diffstat (limited to 'usr.sbin/bsdconfig')
-rwxr-xr-x | usr.sbin/bsdconfig/bsdconfig | 74 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/common.subr | 16 |
2 files changed, 87 insertions, 3 deletions
diff --git a/usr.sbin/bsdconfig/bsdconfig b/usr.sbin/bsdconfig/bsdconfig index b637961..57d9928 100755 --- a/usr.sbin/bsdconfig/bsdconfig +++ b/usr.sbin/bsdconfig/bsdconfig @@ -57,6 +57,13 @@ f_include_lang $BSDCFG_LIBE/include/messages.subr BSDCONFIG_HELPFILE=$BSDCFG_LIBE/include/bsdconfig.hlp USAGE_HELPFILE=$BSDCFG_LIBE/include/usage.hlp +############################################################ CONFIGURATION + +# +# Alternate `local' libexec directory for add-on modules (e.g., from ports) +# +BSDCFG_LOCAL_LIBE="/usr/local/libexec/bsdconfig" + ############################################################ FUNCTIONS # usage @@ -83,6 +90,27 @@ usage() }' */$index | sort ) + local alt_cmd_list # Calculated below (if $BSDCFG_LOCAL_LIBE exists) + if f_quietly cd $BSDCFG_LOCAL_LIBE; then + # No need to preserve CWD (headed toward exit) + + # Test for language-specific indices + f_quietly ls */"$index.${LANG:-$LC_ALL}" && + index="$index.${LANG:-$LC_ALL}" + + alt_cmd_list=$( + awk '/^menu_selection="/ { + sub(/\|.*/, "") + sub(/^menu_selection="/, "") + print + }' */$index 2> /dev/null | sort + ) + + # Conflate lists, removing duplicates + cmd_list=$( printf "%s\n%s\n" \ + "$cmd_list" "$alt_cmd_list" | sort -u ) + fi + # # Determine the longest command-length (in characters) # @@ -167,6 +195,9 @@ dialog_menu_main() local defaultitem= # Calculated below local hline= + # + # Pick up the base modules (directories named `[0-9][0-9][0-9].*') + # local menuitem menu_title menu_help menu_selection index=2 for menuitem in $( cd $BSDCFG_LIBE && ls -d [0-9][0-9][0-9].* ); do [ $index -lt ${#DIALOG_MENU_TAGS} ] || break @@ -190,6 +221,49 @@ dialog_menu_main() index=$(( $index + 1 )) done + # + # Process the `local' libexec sources. + # + # Whereas modules in $BSDCFG_LIBE must be named [0-9][0-9][0-9].* + # modules in $BSDCFG_LOCAL_LIBE should NOT be named this way (making it + # more practical for port-maintainers). + # + # This also has the fortunate side-effect of making the de-duplication + # effort rather simple (because so-called `base' modules must be named + # differently than add-on modules). + # + local separator_added= + for menuitem in $( cd "$BSDCFG_LOCAL_LIBE" 2> /dev/null && ls -d * ) + do + [ $index -lt ${#DIALOG_MENU_TAGS} ] || break + + # Skip the module if it looks like a `base' module + case "$menuitem" in [0-9][0-9][0-9].*) continue;; esac + + menu_program= menu_title= menu_help= + f_include_lang $BSDCFG_LOCAL_LIBE/$menuitem/INDEX || continue + [ "$menu_program" ] || continue + + if [ ! "$separator_added" ]; then + menu_list="$menu_list '-' '-' ''" + separator_added=1 + fi + + case "$menu_program" in + /*) : already fully qualified ;; + *) menu_program="$BSDCFG_LOCAL_LIBE/$menuitem/$menu_program" + esac + + tag=$( f_substr "$DIALOG_MENU_TAGS" $index 1 ) + setvar "menu_program$tag" "$menu_program" + + f_shell_escape "$menu_title" menu_title + f_shell_escape "$menu_help" menu_help + menu_list="$menu_list '$tag' '$menu_title' '$menu_help'" + + index=$(( $index + 1 )) + done + local height width rows eval f_dialog_menu_with_help_size height width rows \ \"\$title\" \ diff --git a/usr.sbin/bsdconfig/share/common.subr b/usr.sbin/bsdconfig/share/common.subr index 32d6aba..6c0400a 100644 --- a/usr.sbin/bsdconfig/share/common.subr +++ b/usr.sbin/bsdconfig/share/common.subr @@ -531,12 +531,22 @@ f_index_file() if [ "$lang" ]; then awk -v keyword="$keyword" "$f_index_file_awk" \ - $BSDCFG_LIBE${BSDCFG_LIBE:+/}*/INDEX.$lang && - return + $BSDCFG_LIBE${BSDCFG_LIBE:+/}*/INDEX.$lang && return # No match, fall-thru to non-i18n sources fi awk -v keyword="$keyword" "$f_index_file_awk" \ - $BSDCFG_LIBE${BSDCFG_LIBE:+/}*/INDEX + $BSDCFG_LIBE${BSDCFG_LIBE:+/}*/INDEX && return + + # No match? Fall-thru to `local' libexec sources (add-on modules) + + [ "$BSDCFG_LOCAL_LIBE" ] || return $FAILURE + if [ "$lang" ]; then + awk -v keyword="$keyword" "$f_index_file_awk" \ + $BSDCFG_LOCAL_LIBE/*/INDEX.$lang && return + # No match, fall-thru to non-i18n sources + fi + awk -v keyword="$keyword" "$f_index_file_awk" \ + $BSDCFG_LOCAL_LIBE/*/INDEX } # f_index_menusel_keyword $indexfile $pgm |