Replicate a feature from sysinstall documented in
stable/9/usr.sbin/sysinstall/help/shortcuts.hlp (reproduced below): If /usr/sbin/sysinstall is linked to another filename, say `/usr/local/bin/configPackages', then the basename will be used as an implicit command name. To get a list of modules you can link to, see `bsdconfig -h' output. Approved by: adrian (co-mentor) (implicit)
This commit is contained in:
parent
33f46cf89f
commit
71e5cb8556
@ -201,6 +201,16 @@ dialog_menu_main()
|
||||
|
||||
############################################################ MAIN
|
||||
|
||||
#
|
||||
# If $0 is not "bsdconfig", interpret it as a keyword to a menuitem
|
||||
#
|
||||
if [ "$pgm" != "bsdconfig" ] &&
|
||||
indexfile=$( f_index_file "$pgm" ) &&
|
||||
cmd=$( f_index_menusel_command "$indexfile" "$pgm" )
|
||||
then
|
||||
exec "$cmd" "$@" || exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Process command-line arguments
|
||||
#
|
||||
@ -244,51 +254,18 @@ if [ "$1" ]; then
|
||||
esac
|
||||
|
||||
#
|
||||
# Find the INDEX (possibly i18n) claiming this keyword
|
||||
# Find the INDEX (possibly i18n) claiming this keyword and get the
|
||||
# command to execute from the menu_selection line.
|
||||
#
|
||||
lang="${LANG:-$LC_ALL}"
|
||||
if [ "$lang" ]; then
|
||||
sel=$( grep "^menu_selection=\"$1|" */INDEX.$lang \
|
||||
2> /dev/null | tail -1 )
|
||||
|
||||
# Fall-back to non-i18n sources if nothing was found
|
||||
[ "$sel" ] ||
|
||||
sel=$( grep "^menu_selection=\"$1|" */INDEX | tail -1 )
|
||||
else
|
||||
sel=$( grep "^menu_selection=\"$1|" */INDEX | tail -1 )
|
||||
fi
|
||||
|
||||
#
|
||||
# If no matches, display usage (which shows valid keywords)
|
||||
#
|
||||
if [ ! "$sel" ]; then
|
||||
if ! { indexfile=$( f_index_file "$1" ) &&
|
||||
cmd=$( f_index_menusel_command "$indexfile" "$1" )
|
||||
}; then
|
||||
# no matches, display usage (which shows valid keywords)
|
||||
f_err "%s: %s: $msg_not_found\n" "$pgm" "$1"
|
||||
usage
|
||||
fi
|
||||
|
||||
#
|
||||
# The command to execute is after the pipe-character (|) in the
|
||||
# menu_selection property of the INDEX file for the menuitem.
|
||||
#
|
||||
cmd="${sel#*|}"
|
||||
cmd="${cmd%\"}"
|
||||
if [ ! "$cmd" ]; then
|
||||
echo "$pgm: $1: $msg_not_found"
|
||||
usage
|
||||
fi
|
||||
shift
|
||||
|
||||
#
|
||||
# If the command pathname is not fully qualified fix-up/force to be
|
||||
# relative to the menuitem directory.
|
||||
#
|
||||
case "$cmd" in
|
||||
/*) : already fully qualified ;;
|
||||
*)
|
||||
dir="${sel%%/*}"
|
||||
cmd="$dir/$cmd"
|
||||
esac
|
||||
|
||||
exec $cmd ${USE_XDIALOG:+-X} "$@" || exit 1
|
||||
fi
|
||||
|
||||
|
@ -36,7 +36,7 @@ f_include $BSDCFG_SHARE/mustberoot.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -36,7 +36,7 @@ f_include $BSDCFG_SHARE/mustberoot.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="050.diskmgmt"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -36,7 +36,7 @@ f_include $BSDCFG_SHARE/mustberoot.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="020.docsinstall"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -35,7 +35,7 @@ BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="dot"
|
||||
f_include_lang $BSDCFG_LIBE/include/messages.subr
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="110.mouse"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="110.mouse"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="110.mouse"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -36,7 +36,7 @@ f_include $BSDCFG_SHARE/mustberoot.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="110.mouse"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="110.mouse"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="110.mouse"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/networking/routing.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -41,7 +41,7 @@ f_include $BSDCFG_SHARE/networking/netmask.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/networking/hostname.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/networking/resolv.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -36,7 +36,7 @@ f_include $BSDCFG_SHARE/mustberoot.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -36,7 +36,7 @@ f_include $BSDCFG_SHARE/password/password.subr
|
||||
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="040.password"
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -39,7 +39,7 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
SECURELEVEL_HELPFILE=$BSDCFG_LIBE/$APP_DIR/include/securelevel.hlp
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="130.security"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -271,50 +271,186 @@ f_usage()
|
||||
exit $FAILURE
|
||||
}
|
||||
|
||||
# f_index_menu_selection $file $pgm
|
||||
# f_index_file $keyword
|
||||
#
|
||||
# Process $file looking for $menu_selection values that correspond to $pgm.
|
||||
# This function is for internationalization (i18n) mapping of the on-disk
|
||||
# scriptname ($pgm) into the localized language (given language-specific
|
||||
# $file). If $LANG or $LC_ALL (in orderder of preference, respectively) is set,
|
||||
# ".encoding" will automatically be appended as a suffix to the provided $file
|
||||
# pathname.
|
||||
# Process all INDEX files known to bsdconfig and return the path to first file
|
||||
# containing a menu_selection line with a keyword portion matching $keyword.
|
||||
#
|
||||
# If, within $file, multiple $menu_selection values map to $pgm, only the first
|
||||
# one will be returned. If no mapping can be made, the NULL string is returned.
|
||||
# If $LANG or $LC_ALL (in order of preference, respectively) is set,
|
||||
# "INDEX.encoding" files will be searched first.
|
||||
#
|
||||
# If $file does not exist, error status is returned along with the NULL string.
|
||||
# If no file is found, error status is returned along with the NULL string.
|
||||
#
|
||||
# This function is a two-parter. Below is the awk(1) portion of the function,
|
||||
# afterward is the sh(1) function which utilizes the below awk script.
|
||||
#
|
||||
f_index_menusel_awk='
|
||||
f_index_file_awk='
|
||||
# Variables that should be defined on the invocation line:
|
||||
# -v pgm="program_name"
|
||||
#
|
||||
( $0 ~ "^menu_selection=.*\\|" pgm "\"" ) {
|
||||
sub(/\|.*/, "")
|
||||
sub(/^menu_selection="/, "")
|
||||
print
|
||||
# -v keyword="keyword"
|
||||
BEGIN { found = 0 }
|
||||
( $0 ~ "^menu_selection=\"" keyword "\\|" ) {
|
||||
print FILENAME
|
||||
found++
|
||||
exit
|
||||
}
|
||||
END { exit ! found }
|
||||
'
|
||||
f_index_menu_selection()
|
||||
f_index_file()
|
||||
{
|
||||
local file="$1" pgm="$2"
|
||||
local keyword="$1"
|
||||
local lang="${LANG:-$LC_ALL}"
|
||||
|
||||
f_dprintf "lang=[$lang]"
|
||||
|
||||
if [ -f "$file.$lang" ]; then
|
||||
awk -v pgm="$pgm" "$f_index_menusel_awk" "$file.$lang" ||
|
||||
exit $FAILURE
|
||||
elif [ -f "$file" ]; then
|
||||
awk -v pgm="$pgm" "$f_index_menusel_awk" "$file" ||
|
||||
exit $FAILURE
|
||||
if [ "$lang" ]; then
|
||||
awk -v keyword="$keyword" "$f_index_file_awk" \
|
||||
$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
|
||||
}
|
||||
|
||||
# f_index_menusel_keyword $indexfile $pgm
|
||||
#
|
||||
# Process $indexfile and return only the keyword portion of the menu_selection
|
||||
# line with a command portion matching $pgm.
|
||||
#
|
||||
# This function is for internationalization (i18n) mapping of the on-disk
|
||||
# scriptname ($pgm) into the localized language (given language-specific
|
||||
# $indexfile). If $LANG or $LC_ALL (in orderder of preference, respectively) is
|
||||
# set, ".encoding" will automatically be appended as a suffix to the provided
|
||||
# $indexfile pathname.
|
||||
#
|
||||
# If, within $indexfile, multiple $menu_selection values map to $pgm, only the
|
||||
# first one will be returned. If no mapping can be made, the NULL string is
|
||||
# returned.
|
||||
#
|
||||
# If $indexfile does not exist, error status is returned with NULL.
|
||||
#
|
||||
# This function is a two-parter. Below is the awk(1) portion of the function,
|
||||
# afterward is the sh(1) function which utilizes the below awk script.
|
||||
#
|
||||
f_index_menusel_keyword_awk='
|
||||
# Variables that should be defined on the invocation line:
|
||||
# -v pgm="program_name"
|
||||
#
|
||||
BEGIN {
|
||||
prefix = "menu_selection=\""
|
||||
plen = length(prefix)
|
||||
found = 0
|
||||
}
|
||||
{
|
||||
if (!match($0, "^" prefix ".*\\|.*\"")) next
|
||||
|
||||
keyword = command = substr($0, plen + 1, RLENGTH - plen - 1)
|
||||
sub(/^.*\|/, "", command)
|
||||
sub(/\|.*$/, "", keyword)
|
||||
|
||||
if ( command == pgm )
|
||||
{
|
||||
print keyword
|
||||
found++
|
||||
exit
|
||||
}
|
||||
}
|
||||
END { exit ! found }
|
||||
'
|
||||
f_index_menusel_keyword()
|
||||
{
|
||||
local indexfile="$1" pgm="$2"
|
||||
local lang="${LANG:-$LC_ALL}"
|
||||
|
||||
f_dprintf "lang=[$lang]"
|
||||
|
||||
if [ -f "$indexfile.$lang" ]; then
|
||||
awk -v pgm="$pgm" \
|
||||
"$f_index_menusel_keyword_awk" \
|
||||
"$indexfile.$lang"
|
||||
elif [ -f "$indexfile" ]; then
|
||||
awk -v pgm="$pgm" \
|
||||
"$f_index_menusel_keyword_awk" \
|
||||
"$indexfile"
|
||||
fi
|
||||
}
|
||||
|
||||
# f_index_menusel_command $indexfile $keyword
|
||||
#
|
||||
# Process $indexfile and return only the command portion of the menu_selection
|
||||
# line with a keyword portion matching $keyword.
|
||||
#
|
||||
# This function is for mapping [possibly international] keywords into the
|
||||
# command to be executed. If $LANG or $LC_ALL (order of preference) is set,
|
||||
# ".encoding" will automatically be appended as a suffix to the provided
|
||||
# $indexfile pathname.
|
||||
#
|
||||
# If, within $indexfile, multiple $menu_selection values map to $keyword, only
|
||||
# the first one will be returned. If no mapping can be made, the NULL string is
|
||||
# returned.
|
||||
#
|
||||
# If $indexfile doesn't exist, error status is returned with NULL.
|
||||
#
|
||||
# This function is a two-parter. Below is the awk(1) portion of the function,
|
||||
# afterward is the sh(1) function which utilizes the below awk script.
|
||||
#
|
||||
f_index_menusel_command_awk='
|
||||
# Variables that should be defined on the invocation line:
|
||||
# -v key="keyword"
|
||||
#
|
||||
BEGIN {
|
||||
prefix = "menu_selection=\""
|
||||
plen = length(prefix)
|
||||
found = 0
|
||||
}
|
||||
{
|
||||
if (!match($0, "^" prefix ".*\\|.*\"")) next
|
||||
|
||||
keyword = command = substr($0, plen + 1, RLENGTH - plen - 1)
|
||||
sub(/^.*\|/, "", command)
|
||||
sub(/\|.*$/, "", keyword)
|
||||
|
||||
if ( keyword == key )
|
||||
{
|
||||
print command
|
||||
found++
|
||||
exit
|
||||
}
|
||||
}
|
||||
END { exit ! found }
|
||||
'
|
||||
f_index_menusel_command()
|
||||
{
|
||||
local indexfile="$1" keyword="$2" command
|
||||
local lang="${LANG:-$LC_ALL}"
|
||||
|
||||
f_dprintf "lang=[$lang]"
|
||||
|
||||
if [ -f "$indexfile.$lang" ]; then
|
||||
command=$( awk -v key="$keyword" \
|
||||
"$f_index_menusel_command_awk" \
|
||||
"$indexfile.$lang" ) || return $FAILURE
|
||||
elif [ -f "$indexfile" ]; then
|
||||
command=$( awk -v key="$keyword" \
|
||||
"$f_index_menusel_command_awk" \
|
||||
"$indexfile" ) || return $FAILURE
|
||||
else
|
||||
return $FAILURE
|
||||
fi
|
||||
|
||||
#
|
||||
# If the command pathname is not fully qualified fix-up/force to be
|
||||
# relative to the $indexfile directory.
|
||||
#
|
||||
case "$command" in
|
||||
/*) : already fully qualified ;;
|
||||
*)
|
||||
local indexdir="${indexfile%/*}"
|
||||
[ "$indexdir" != "$indexfile" ] || indexdir="."
|
||||
command="$indexdir/$command"
|
||||
esac
|
||||
|
||||
echo "$command"
|
||||
}
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/sysrc.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ GLOBALS
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/startup/rcconf.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ GLOBALS
|
||||
|
@ -38,7 +38,7 @@ f_include $BSDCFG_SHARE/startup/rcconf.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ GLOBALS
|
||||
|
@ -38,7 +38,7 @@ f_include $BSDCFG_SHARE/startup/rcconf.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ GLOBALS
|
||||
|
@ -37,7 +37,7 @@ f_include $BSDCFG_SHARE/startup/rcedit.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -38,7 +38,7 @@ f_include $BSDCFG_SHARE/startup/rcvar.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ GLOBALS
|
||||
|
@ -36,7 +36,7 @@ f_include $BSDCFG_SHARE/mustberoot.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
@ -42,7 +42,7 @@ f_include $BSDCFG_SHARE/timezone/zones.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="090.timezone"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -36,7 +36,7 @@ f_include $BSDCFG_SHARE/mustberoot.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="150.ttys"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -35,7 +35,7 @@ f_include $BSDCFG_SHARE/dialog.subr
|
||||
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -38,7 +38,7 @@ f_include $BSDCFG_SHARE/usermgmt/group_input.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -38,7 +38,7 @@ f_include $BSDCFG_SHARE/usermgmt/group_input.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -38,7 +38,7 @@ f_include $BSDCFG_SHARE/usermgmt/group_input.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -35,7 +35,7 @@ f_include $BSDCFG_SHARE/dialog.subr
|
||||
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -38,7 +38,7 @@ f_include $BSDCFG_SHARE/usermgmt/user_input.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -38,7 +38,7 @@ f_include $BSDCFG_SHARE/usermgmt/user_input.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ MAIN
|
||||
|
@ -38,7 +38,7 @@ f_include $BSDCFG_SHARE/usermgmt/user_input.subr
|
||||
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
|
||||
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ CONFIGURATION
|
||||
|
@ -39,7 +39,7 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
||||
|
||||
USERMGMT_HELPFILE=$BSDCFG_LIBE/$APP_DIR/include/usermgmt.hlp
|
||||
|
||||
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
|
||||
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
|
||||
|
||||
############################################################ FUNCTIONS
|
||||
|
Loading…
x
Reference in New Issue
Block a user