diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2021-12-06 10:35:28 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2021-12-06 10:35:28 +0000 |
commit | 1b308d0631e5d0d21b631a688cdef1afe378e086 (patch) | |
tree | 29376e960cd070b8a1642a30963497d9e673423d | |
parent | 857c66bb5f3c5651b012beb1b5ea6ba39354ea94 (diff) | |
download | src-1b308d0631e5d0d21b631a688cdef1afe378e086.tar.gz src-1b308d0631e5d0d21b631a688cdef1afe378e086.zip |
bsddialog: vendor import 2021-12-05
345 files changed, 50464 insertions, 2247 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000000..bc53650512de --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +bsddialog +*.o +*~ +examples_library/buildlist +examples_library/checklist +examples_library/datebox +examples_library/form +examples_library/menu +examples_library/mixedlist +examples_library/radiolist +examples_library/theme +examples_library/treeview +examples_library/infobox +examples_library/msgbox +examples_library/pause +examples_library/rangebox +examples_library/sade +examples_library/timebox +examples_library/yesno +*.gz +lib/libbsddialog.so* +BSDDIALOG.geany +BSDDIALOG.tags +*.core +bsdinstall/partedit/sade diff --git a/README.md b/README.md index 1d34f3b51099..112d8934f432 100644 --- a/README.md +++ b/README.md @@ -55,19 +55,43 @@ Examples utility: % ./bsddialog --backtitle "TITLE" --title yesno --hline "bsddialog" --yesno "Hello World!" 5 25 % ./bsddialog --extra-button --help-button --defaultno --yesno "Hello World!" 0 0 ``` +and +``` +% sh ./examples_utility/buildlist.sh +% sh ./examples_utility/checklist.sh +% sh ./examples_utility/form.sh +% sh ./examples_utility/gauge.sh +% sh ./examples_utility/infobox.sh +% sh ./examples_utility/inputbox.sh +% sh ./examples_utility/menu.sh +% sh ./examples_utility/mixedform.sh +% sh ./examples_utility/mixedgauge.sh +% sh ./examples_utility/msgbox.sh +% sh ./examples_utility/passwordbox.sh +% sh ./examples_utility/passwordform.sh +% sh ./examples_utility/radiolist.sh +% sh ./examples_utility/treeview.sh +% sh ./examples_utility/yesno.sh +``` Examples library: ``` -% cd library_examples +% cd examples_library % sh compile % ./buildlist +% ./compile +% ./datebox +% ./form % ./infobox % ./menu % ./mixedlist % ./msgbox -% ./ports +% ./pause % ./radiolist +% ./rangebox +% ./sade % ./theme +% ./timebox % ./treeview % ./yesno ``` @@ -87,74 +111,63 @@ Use Cases: --colors, --date-format *format*, --default-button *string*, --defaultno, --default-item *string*, --exit-label *string*, --extra-button, --extra-label *string*, ---hfile *filename* (for completed widgets), n--help-button, +--hfile *filename* (for completed widgets), --help, --help-button, --help-label *string*, --help-status, --help-tags, --hline *string*, --ignore, ---item-help, --no-cancel, --nocancel, --no-label *string*, --no-items, ---no-lines, --no-ok, +--insecure, --item-help, --max-input *size*, --no-cancel, --nocancel, +--no-label *string*, --no-items, --no-lines, --no-ok, --nook, --no-shadow, --no-tags, --ok-label *string*, --output-fd *fd*, --output-separator *string*, --print-version, --print-size (todo move lib -> utility), --quoted (quotes all != dialog), --print-maxsize, --shadow, --single-quoted (add --quote-with *ch*?), --separator *string* (alias --output-separator *string*), --separate-output (rename --separate-output-withnl?), --sleep *secs*, --stderr, ---stdout, --theme *string* ("bsddialog", "dialog", "blackwhite" and "magenta"), +--stdout, --theme *string* ("bsddialog", "dialog", "blackwhite"), --time-format *format*, --title *title*, --version, --yes-label *string*. **Widgets:** infobox (do not clear the screen), msgbox, yesno (dialog renames "yes/no" -> "ok/cancel" with --extra-button --help-button). - checklist, radiolist, menu, mixedlist, treeview and textbox. + checklist, radiolist, menu, mixedlist, treeview, textbox, mixedgauge, datebox, + timebox, gauge, rangebox, pause. + + + Without resize: + + form, inputbox, mixedform, passwordbox, passwordform. + + + Without autosize, resize, F1: + + buildlist + + ## TODO + **Common Options:** | Option | Status | Note | | ---------------------------- | ----------- | ------------------------------- | -| --cr-wrap | Coding | | -| --help | In progress | | -| --input-fd *fd* | | | -| --insecure | | | -| --keep-tite | | | -| --keep-window | | | -| --last-key | | | -| --max-input *size* | | | -| --no-collapse | Coding | | -| --no-kill | | | -| --no-nl-expand | Coding | | -| --tab-correct | | | -| --tab-len *n* | | | -| --trim | Coding | | - - -To evaluate / Not planned in the short term: --column-separator *string*, +| --cr-wrap | In progress | text | +| --no-collapse | In progress | text | +| --no-nl-expand | In progress | text | +| --trim | In progress | text | + + +To evaluate / Not planned in the short term / not in bsdinstall: + --create-rc *file*, --iso-week, --no-mouse, --print-text-only *str h w*, --print-text-size *str h w*, --reorder, -scrollbar, --separate-widget *string*, --size-err, --timeout *secs*,--trace *filename*, --visit-items, ---week-start *day*. +--week-start *day*, --keep-tite, --keep-window, --last-key, --no-kill, +--column-separator *string*, --input-fd *fd*, --tab-correct, --tab-len *n* **Widgets:** -| Widget | Status | Note | -|--------------- | ----------- | ----------------------------------------------| -| --buildlist | In progress | todo autosize, resize, F1 | -| --calendar | In progress | todo autosize, resize, F1, leap year, year <=0, month days | -| --editbox | | | -| --form | In progress | implemented via --mixedform | -| --gauge | In progress | | -| --inputbox | In progress | implemented via --mixedform, todo \<init\> | -| --mixedform | In progress | todo autosize, resize, F1 | -| --mixedgauge | In progress | todo autosize, resize, F1 | -| --passwordbox | In progress | implemented via --mixedform, todo \<init\> | -| --passwordform | In progress | implemented via --mixedform | -| --pause | In progress | todo autosize, resize, F1 | -| --prgbox | In progress | add command opts | -| --programbox | Coding | | -| --progressbox | | | -| --rangebox | In progress | todo autosize, resize, F1, PAGE-UP/PAGE-DOWN/HOME/END keys | -| --timebox | In progress | todo autosize, resize, F1 | - -To evaluate / Not planned in the short term: tailbox (textbox/fseek), tailboxbg, -dselect, fselect, inputmenu. +To evaluate / Not planned in the short term: + +tailbox (textbox/fseek), tailboxbg, dselect, fselect, inputmenu, editbox, +calendar (use datebox), prgbox, programbox, progressbox. diff --git a/bsdconfig/Makefile b/bsdconfig/Makefile new file mode 100644 index 000000000000..a203c9aab328 --- /dev/null +++ b/bsdconfig/Makefile @@ -0,0 +1,33 @@ +# $FreeBSD$ + +.include <src.opts.mk> + +SUBDIR= console \ + diskmgmt \ + docsinstall \ + dot \ + include \ + includes \ + mouse \ + networking \ + packages \ + password \ + security \ + share \ + startup \ + timezone \ + ttys \ + usermgmt + +.if ${MK_EXAMPLES} != "no" +SUBDIR+= examples +.endif + +FILESDIR= ${LIBEXECDIR}/bsdconfig +FILES= USAGE + +SCRIPTS= bsdconfig + +MAN= bsdconfig.8 + +.include <bsd.prog.mk> diff --git a/bsdconfig/Makefile.depend b/bsdconfig/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/USAGE b/bsdconfig/USAGE new file mode 100644 index 000000000000..6b70bd6450c8 --- /dev/null +++ b/bsdconfig/USAGE @@ -0,0 +1,47 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +Usage: + @PROGRAM_NAME@ [-h] + @PROGRAM_NAME@ command [-h] + @PROGRAM_NAME@ [OPTIONS] [command [OPTIONS]] + +OPTIONS: + -d Provide lots of debugging info on standard-out when running. + -D file Send debugging info to file. If file begins with a plus-sign + debug info is sent to both standard-out and file (minus the + leading plus). + -f file Load file as script and then exit. If multiple occurrences, + program will only exit after last occurrence. If file is a + single dash (`-'), @PROGRAM_NAME@ reads from standard input. + -h Print this usage statement and exit. + -S Secure X11 mode (implies `-X'). As root, always prompt-for + and validate sudo(8) username/password before starting. + -X Use Xdialog(1) in place of dialog(1). + +COMMANDS: +@COMMAND_LIST@ diff --git a/bsdconfig/bsdconfig b/bsdconfig/bsdconfig new file mode 100755 index 000000000000..f132c0370264 --- /dev/null +++ b/bsdconfig/bsdconfig @@ -0,0 +1,428 @@ +#!/bin/sh +#- +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012-2021 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +# When common.subr is included, it automatically scans "$@" for `-d' and/or +# `-D file' arguments to conditionally enable debugging. Similarly, when +# dialog.subr is included, it automatically scans "$@" for `-X' and/or `-S'. +# To prevent this scanning from becoming confused by extra options, define +# any/all extra arguments to use in the optstring to getopts when scanning +# for dedicated options such as those described. +# +# NOTE: This needs to be declared before including `common.subr'. +# NOTE: You really only need to list flags that require an argument as unknown +# flags are silently accepted unless they take an argument (in which case +# the following argument will terminate option processing unless it looks +# like a flag). +# +GETOPTS_EXTRA="f:" + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +f_include $BSDCFG_SHARE/strings.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" +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 +# +# display usage and exit +# +usage() +{ + local index="INDEX" + local cmd_list # Calculated below + + cd $BSDCFG_LIBE + # 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}" + + cmd_list=$( + awk '/^menu_selection="/ { + sub(/\|.*/, "") + sub(/^menu_selection="/, "") + print + }' */$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) + # + local longest_cmd + longest_cmd=$( echo "$cmd_list" | f_longest_line_length ) + f_dprintf "longest_cmd=[%s]" "$longest_cmd" + + # + # Determine the maximum width of terminal/console + # + local max_size="$( stty size 2> /dev/null )" + : ${max_size:="24 80"} + local max_width="${max_size#*[$IFS]}" + f_dprintf "max_width=[%s]" "$max_width" + + # + # Using the longest command-length as the width of a single column, + # determine if we can use more than one column to display commands. + # + local x=$longest_cmd ncols=1 + x=$(( $x + 8 )) # Accommodate leading tab character + x=$(( $x + 3 + $longest_cmd )) # Pre-load end of next column + while [ $x -lt $max_width ]; do + ncols=$(( $ncols + 1 )) + x=$(( $x + 3 + $longest_cmd )) + done + f_dprintf "ncols=[%u] x=[%u]" $ncols $x + + # + # Re-format the command-list into multiple columns + # + cmd_list=$( eval "$( echo "$cmd_list" | + awk -v ncols=$ncols -v size=$longest_cmd ' + BEGIN { + n = 0 + row_item[1] = "" + } + function print_row() + { + fmt = "printf \"\\t%-" size "s" + for (i = 1; i < cur_col; i++) + fmt = fmt " %-" size "s" + fmt = fmt "\\n\"" + printf "%s", fmt + for (i = 1; i <= cur_col; i++) + printf " \"%s\"", row_item[i] + print "" + } + { + n++ + cur_col = (( n - 1 ) % ncols ) + 1 + printf "f_dprintf \"row_item[%u]=[%%s]\" \"%s\"\n", + cur_col, $0 + row_item[cur_col] = $0 + if ( cur_col == ncols ) print_row() + } + END { + if ( cur_col < ncols ) print_row() + }' )" + ) + + f_usage $BSDCFG_LIBE/USAGE \ + "PROGRAM_NAME" "$pgm" \ + "COMMAND_LIST" "$cmd_list" + + # NOTREACHED +} + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local title="$DIALOG_TITLE" + local btitle="$DIALOG_BACKTITLE" + local prompt="$msg_menu_text" + local menu_list=" + 'X' '$msg_exit' '$msg_exit_bsdconfig' + '1' '$msg_usage' '$msg_quick_start_how_to_use_this_menu_system' + " # END-QUOTE + 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 + [ -f "$BSDCFG_LIBE/$menuitem/INDEX" ] || continue + [ $index -lt ${#DIALOG_MENU_TAGS} ] || break + + menu_program= menu_title= menu_help= + f_include_lang $BSDCFG_LIBE/$menuitem/INDEX + [ "$menu_program" ] || continue + + case "$menu_program" in + /*) : already fully qualified ;; + *) menu_program="$menuitem/$menu_program" + esac + + f_substr -v tag "$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 + + # + # 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 + # Skip the module if it looks like a `base' module + case "$menuitem" in [0-9][0-9][0-9].*) continue;; esac + + [ -f "$BSDCFG_LOCAL_LIBE/$menuitem/INDEX" ] || continue + [ $index -lt ${#DIALOG_MENU_TAGS} ] || break + + 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 + + f_substr -v tag "$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\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + + local menu_choice + menu_choice=$( eval $DIALOG \ + --clear \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --hline \"\$hline\" \ + --item-help \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_exit_bsdconfig\" \ + --help-button \ + --help-label \"\$msg_help\" \ + ${USE_XDIALOG:+--help \"\"} \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_data_sanitize menu_choice + f_dialog_menutag_store "$menu_choice" + + # Only update default-item on success + [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice" + + return $retval +} + +############################################################ MAIN + +# +# If $0 is not "bsdconfig", interpret it either as a keyword to a menuitem or +# as a valid resword (see script.subr for additional details about reswords). +# +if [ "$pgm" != "bsdconfig" ]; then + if indexfile=$( f_index_file "$pgm" ) && + cmd=$( f_index_menusel_command "$indexfile" "$pgm" ) + then + f_dprintf "pgm=[%s] cmd=[%s] *=[%s]" "$pgm" "$cmd" "$*" + exec "$cmd" "$@" || exit 1 + else + f_include $BSDCFG_SHARE/script.subr + for resword in $RESWORDS; do + [ "$pgm" = "$resword" ] || continue + # Found a match + f_dprintf "pgm=[%s] A valid resWord!" "$pgm" + f_dispatch $resword $resword "$@" + exit $? + done + fi +fi + +# +# Process command-line arguments +# +scripts_loaded=0 +while getopts f:h$GETOPTS_STDARGS flag; do + case "$flag" in + f) [ $scripts_loaded -eq 0 ] && f_include $BSDCFG_SHARE/script.subr + f_script_load "$OPTARG" + scripts_loaded=$(( $scripts_loaded + 1 )) ;; + h|\?) usage ;; + esac +done +shift $(( $OPTIND - 1 )) + +# If we've loaded any scripts, do not continue any further +[ $scripts_loaded -gt 0 ] && exit + +# +# Initialize +# +f_dialog_title "$msg_main_menu" + +[ "$SECURE" ] && f_mustberoot_init + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# If a non-option argument was passed, process it as a menuitem selection... +# +if [ "$1" ]; then + # + # ...unless it's a long-option for usage. + # + case "$1" in -help|--help|-\?) + usage + # NOTREACHED + esac + + # + # Find the INDEX (possibly i18n) claiming this keyword and get the + # command to execute from the menu_selection line. + # + 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 + # NOTREACHED + fi + + f_dprintf "cmd=[%s] *=[%s]" "$cmd" "$*" + shift + exec $cmd ${USE_XDIALOG:+-X} "$@" || exit 1 + # NOTREACHED +fi + +# +# Launch application main menu +# +while :; do + dialog_menu_main + retval=$? + f_dialog_menutag_fetch mtag + f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" + + if [ $retval -eq $DIALOG_HELP ]; then + f_show_help "$BSDCONFIG_HELPFILE" + continue + elif [ $retval -ne $DIALOG_OK ]; then + f_die + fi + + case "$mtag" in + X) break ;; + 1) # Usage + f_show_help "$USAGE_HELPFILE" + continue + esac + + # Anything else is a dynamically loaded menuitem + + f_getvar menu_program$mtag menu_program + case "$menu_program" in + /*) cmd="$menu_program" ;; + *) cmd="$BSDCFG_LIBE/$menu_program" + esac + f_dprintf "cmd=[%s]" "$cmd" + $cmd ${USE_XDIALOG:+-X} +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/bsdconfig.8 b/bsdconfig/bsdconfig.8 new file mode 100644 index 000000000000..9f5481cac65d --- /dev/null +++ b/bsdconfig/bsdconfig.8 @@ -0,0 +1,256 @@ +.\" Copyright (c) 2012 Ron McDowell +.\" Copyright (c) 2012-2013 Devin Teske +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd April 12, 2020 +.Dt BSDCONFIG 8 +.Os +.Sh NAME +.Nm bsdconfig +.Nd system configuration utility +.Sh SYNOPSIS +.Nm +.Op Fl h +.Nm +.Ar command +.Op Fl h +.Nm +.Op OPTIONS +.Op command Op OPTIONS +.Sh DESCRIPTION +.Nm +is used to set up many system configuration settings, both for new systems, as +well as changing configuration settings of existing systems. +.Pp +.Nm +optionally takes a command as an argument. +If invoked with no arguments, it will bring up an interactive menu listing the +available modules. +.Pp +The following options are available: +.Bl -tag -width indent+ +.It Fl d +Provide lots of debugging info on standard-out when running. +.It Fl D Ar file +Send debugging info to file. +If file begins with a plus-sign debug info is sent to both standard-out and +file (minus the leading plus). +.It Fl f Ar file +Load +.Ar file +as script and then exit. +If multiple occurrences, program will only exit after last occurrence. +If +.Ar file +is a single dash +.Pq Sq Fl , +.Nm +reads from standard input. +.It Fl h +Print usage statement and exit. +.It Fl S +Secure X11 mode +.Pq implies Fl X . +As root, always prompt-for and validate +.Xr sudo 8 +username/password before starting. +.It Fl X +Use +.Xr Xdialog 1 +in place of +.Xr dialog 1 . +.El +.Sh COMMANDS +The following commands +.Pq sorted alphabetically +are currently included in the base +.Nm +program, with more to be added soon. +Other commands can be added, as detailed below in the +.Cm ADDING COMMANDS +section, and once added, will appear in the master menu as well as in the +.Cm -h +listing. +.Bl -tag -width ".Cm syscons_screenmap" +.It Cm console +Utilities to customize the behavior of the system console. +.It Cm defaultrouter +Shortcut to the Default Router/Gateway menu under networking. +.It Cm diskmgmt +Manage disk partitions and/or labels. +Executes +.Xr sade 8 . +.It Cm docsinstall +Executes the +.Cm bsdinstall docsinstall +sub-utility to allow installation/re-installation of the FreeBSD Documentation +set(s). +.It Cm dot +Generate a graphviz +.Xr dot 1 +language file +.Pq printed on stdout +visualizing the +.Nm +menu, include, and shortcut structure relationships. +See +.Dq bsdconfig dot -h +for more details. +.It Cm groupadd +Shortcut to the Add Groups menu under groupmgmt. +.It Cm groupdel +Shortcut to the Delete Groups menu under groupmgmt. +.It Cm groupedit +Shortcut to the Edit/View Groups menu under groupmgmt. +.It Cm groupmgmt +Utilities to Add/Change/View/Delete Group Accounts. +.It Cm hostname +Shortcut to the Hostname/Domain menu under networking. +.It Cm kern_securelevel +Shortcut to the kern.securelevel menu under security. +.It Cm mouse +Utilities for configuring, exploring, and enabling console mouse support. +.It Cm mouse_disable +Shortcut to the Disable menu under mouse. +.It Cm mouse_enable +Shortcut to the Enable menu under mouse. +.It Cm mouse_flags +Shortcut to the Flags menu under mouse. +.It Cm mouse_port +Shortcut to the Port menu under mouse. +.It Cm mouse_type +Shortcut to the Type menu under mouse. +.It Cm nameservers +Shortcut to the DNS Nameservers menu under networking. +.It Cm netdev +Shortcut to the Network Interfaces menu under networking. +.It Cm networking +Utilities to set/change Hostname/Domain, Network Interfaces, Wireless +Network, Default Router/Gateway, and DNS Nameservers. +.It Cm packages +Browse, install, uninstall, or re-install packaged software. +.It Cm password +Set the system administrator +.Pq root +password. +.It Cm security +Configure various system security settings. +.It Cm startup +Configure various aspects of system startup. +.It Cm startup_misc +Shortcut to the Miscellaneous Startup Services menu under startup. +.It Cm startup_rcadd +Shortcut to the Add New menu under the View/Edit Startup Configuration menu +(startup_rcconf) of startup. +.It Cm startup_rcconf +Shortcut to the View/Edit Startup Configuration menu under startup. +.It Cm startup_rcdelete +Shortcut to the Delete menu under the View/Edit Startup Configuration menu +(startup_rcconf) of startup. +.It Cm startup_rcvar +Shortcut to the Toggle Startup Services menu under startup. +.\" use neutral name, e.g. console_keymap instead of syscons_keymap? +.\" font (encoding) selection not applicable to vt(4)! +.It Cm syscons_font +Shortcut to the Font menu under console. +.\" .It Cm console_keymap +.\" Shortcut to the Keymap menu under console. +.It Cm syscons_keymap +Shortcut to the Keymap menu under console. +.\" .It Cm vt_repeat +.\" Shortcut to the Repeat menu under console. +.It Cm syscons_repeat +Shortcut to the Repeat menu under console. +.\" .It Cm vt_saver +.\" Shortcut to the Saver menu under console. +.It Cm syscons_saver +Shortcut to the Saver menu under console. +.\" screenmap (encoding) selection not applicable to vt(4)! +.It Cm syscons_screenmap +Shortcut to the Screenmap menu under console. +.\" .It Cm vt_syscons_ttys +.\" Shortcut to the Ttys menu under console. +.It Cm syscons_ttys +Shortcut to the Ttys menu under console. +.It Cm timezone +Set the regional timezone of the local machine. +.It Cm ttys +Edit the +.Xr ttys 5 +database with your favorite editor. +.It Cm useradd +Shortcut to the Add Users menu under usermgmt. +.It Cm userdel +Shortcut to the Delete Users menu under usermgmt. +.It Cm useredit +Shortcut to the Edit/View Users menu under usermgmt. +.It Cm usermgmt +Utilities to Add/Edit/View/Delete User Accounts. +.It Cm wireless +Shortcut to the Wireless Networks menu under networking. +.El +.Sh INTERNATIONALIZATION +i18n features are built into +.Nm +and language-specific translation files will be added as they become available. +In the absence of language-specific translation files, the default +.Pq en_US.ISO8859-1 +files will be used. +.Sh ADDING COMMANDS +To be documented later. +Document menu_selection="command|*" syntax of INDEX files. +.Sh ENVIRONMENT VARIABLES +The following environment variables affect the execution of +.Nm : +.Bl -tag -width ".Ev LC_ALL" +.It Ev LANG +If LANG is set, messages and index information will be read from files named +messages.$LANG and INDEX.$LANG and fall back to files named messages and INDEX +if messages.$LANG and INDEX.$LANG do not exist. +LANG takes precedence over LC_ALL. +.It Ev LC_ALL +If LC_ALL is set, messages and index information will be read from files named +messages.$LC_ALL and INDEX.$LC_ALL and fall back to files named messages and +INDEX if messages.$LC_ALL and INDEX.$LC_ALL do not exist. +.El +.Sh FILES +/usr/share/examples/bsdconfig/bsdconfigrc can be copied to $HOME/.bsdconfigrc +and customized as needed. +.Sh EXIT STATUS +.Ex -std +.Sh SEE ALSO +.Xr bsdinstall 8 +.Sh HISTORY +.Nm +first appeared in +.Fx 9.2 . +.Sh AUTHORS +.An Ron McDowell +.An Devin Teske Aq Mt dteske@FreeBSD.org +.Sh BUGS +The docsinstall and diskmgmt modules call bsdinstall. +Bugs found in these modules should be considered those of bsdinstall, not +.Nm . diff --git a/bsdconfig/console/INDEX b/bsdconfig/console/INDEX new file mode 100644 index 000000000000..e298f340e63c --- /dev/null +++ b/bsdconfig/console/INDEX @@ -0,0 +1,70 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012-2015 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# +# Title that will be shown in the bsdconfig menu. +# +menu_title="Console" + +# +# A short descriptive line shown at the bottom of the bsdconfig menu. keep it +# short because any line longer than the terminal width will be truncated. +# +menu_help="Customize system console behavior" + +# +# Two-part variable that defines an action to take when `keyword' is passed on +# a bsdconfig command line. Variable takes the form "keyword|command" and +# multiple occurrences of the variable (with different `keyword's, or different +# `keyword's AND `command's) are allowed. If `command' begins with a '/' then +# the full path to the program is needed. If `command' begins with anything +# else it is a path relative to the directory this INDEX file is in. `keyword' +# can be i18n'ed but `command' is the name of a script. +# +menu_selection="console|console" +menu_selection="vt_font|font" +menu_selection="vt_keymap|keymap" +menu_selection="vt_repeat|repeat" +menu_selection="vt_saver|saver" +menu_selection="vt_screenmap|screenmap" +menu_selection="vt_ttys|ttys" +# For backward compatibility +menu_selection="syscons_font|font" +menu_selection="syscons_keymap|keymap" +menu_selection="syscons_repeat|repeat" +menu_selection="syscons_saver|saver" +menu_selection="syscons_screenmap|screenmap" +menu_selection="syscons_ttys|ttys" + +# +# ------------ Items below this line do NOT need i18n translation ------------ +# +# Name of the program to be run when this menu choice is selected. If it begins +# with a '/' then the full path to the program is needed. If it begins with +# anything else it is a path relative to the directory this INDEX file is in. +# +menu_program="console" diff --git a/bsdconfig/console/Makefile b/bsdconfig/console/Makefile new file mode 100644 index 000000000000..bcb2ebd44185 --- /dev/null +++ b/bsdconfig/console/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +SUBDIR= include + +FILESDIR= ${LIBEXECDIR}/bsdconfig/080.console +FILES= INDEX USAGE + +SCRIPTSDIR= ${FILESDIR} +SCRIPTS= console font keymap repeat saver screenmap ttys + +.include <bsd.prog.mk> diff --git a/bsdconfig/console/Makefile.depend b/bsdconfig/console/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/console/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/console/USAGE b/bsdconfig/console/USAGE new file mode 100644 index 000000000000..a06d8af24928 --- /dev/null +++ b/bsdconfig/console/USAGE @@ -0,0 +1,37 @@ +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS] + +OPTIONS: + -d Provide lots of debugging info on standard-out when running. + -D file Send debugging info to file. If file begins with a plus-sign + debug info is sent to both standard-out and file (minus the + leading plus). + -h Print this usage statement and exit. + -S Secure X11 mode (implies `-X'). As root, always prompt-for + and validate sudo(8) username/password before starting. + -X Use Xdialog(1) in place of dialog(1). diff --git a/bsdconfig/console/console b/bsdconfig/console/console new file mode 100755 index 000000000000..cfa44bee1abc --- /dev/null +++ b/bsdconfig/console/console @@ -0,0 +1,146 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_console_menu_text" + local menu_list=" + 'X $msg_exit' '$msg_exit_this_menu' + '2 $msg_font' '$msg_choose_alternate_screen_font' + '3 $msg_keymap' '$msg_choose_alternate_keyboard_map' + '4 $msg_repeat' '$msg_set_repeat_rate' + '5 $msg_saver' '$msg_configure_screen_saver' + '6 $msg_screenmap' '$msg_choose_alternate_screenmap' + '7 $msg_ttys' '$msg_choose_console_terminal_type' + " # END-QUOTE + local defaultitem= # Calculated below + local hline="$hline_configure_system_console_settings" + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_data_sanitize menu_choice + f_dialog_menutag_store "$menu_choice" + f_dialog_default_store "$menu_choice" + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_system_console_configuration" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +while :; do + dialog_menu_main || f_die + f_dialog_menutag_fetch mtag + + command= + case "$mtag" in + "X $msg_exit") break ;; + "2 $msg_font") command=font ;; # Choose alternate screen font + "3 $msg_keymap") command=keymap ;; # Choose alt. keyboard map + "4 $msg_repeat") command=repeat ;; # Set key repeat rate + "5 $msg_saver") command=saver ;; # Configure the screen saver + "6 $msg_screenmap") command=screenmap ;; # Choose alternate screenmap + "7 $msg_ttys") command=ttys ;; # Choose console terminal type + esac + + if [ "$command" ]; then + $BSDCFG_LIBE/$APP_DIR/$command ${USE_XDIALOG:+-X} + else + f_die 1 "$msg_unknown_console_menu_selection" + fi +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/console/font b/bsdconfig/console/font new file mode 100755 index 000000000000..ce16730dd258 --- /dev/null +++ b/bsdconfig/console/font @@ -0,0 +1,193 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_font_menu_text" + local menu_list=" + '1 $msg_none' '$msg_use_hardware_default_font' + '2 $msg_ibm_437' '$msg_ibm_437_desc' + '3 $msg_ibm_850' '$msg_ibm_850_desc' + '4 $msg_ibm_865' '$msg_ibm_865_desc' + '5 $msg_ibm_866' '$msg_ibm_866_desc' + '6 $msg_ibm_866u' '$msg_ibm_866u_desc' + '7 $msg_ibm_1251' '$msg_ibm_1251_desc' + '8 $msg_iso_8859_1' '$msg_iso_8859_1_desc' + '9 $msg_iso_8859_2' '$msg_iso_8859_2_desc' + 'a $msg_iso_8859_4' '$msg_iso_8859_4_desc' + 'b $msg_iso_8859_7' '$msg_iso_8859_7_desc' + 'c $msg_iso_8859_8' '$msg_iso_8859_8_desc' + 'd $msg_iso_8859_15' '$msg_iso_8859_15_desc' + 'e $msg_swiss' '$msg_swiss_desc' + " # END-QUOTE + local defaultitem= # Calculated below + local hline="$hline_choose_a_font" + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + case "$( f_sysrc_get font8x8 )" in + [Nn][Oo]|'') defaultitem="1 $msg_none" ;; + cp437-8x8) defaultitem="2 $msg_ibm_437" ;; + cp850-8x8) defaultitem="3 $msg_ibm_850" ;; + cp865-8x8) defaultitem="4 $msg_ibm_865" ;; + cp866-8x8) defaultitem="5 $msg_ibm_866" ;; + cp866u-8x8) defaultitem="6 $msg_ibm_866u" ;; + cp1251-8x8) defaultitem="7 $msg_ibm_1251" ;; + iso-8x8) defaultitem="8 $msg_iso_8859_1" ;; + iso02-8x8) defaultitem="9 $msg_iso_8859_2" ;; + iso04-8x8) defaultitem="a $msg_iso_8859_4" ;; + iso07-8x8) defaultitem="b $msg_iso_8859_7" ;; + iso08-8x8) defaultitem="c $msg_iso_8859_8" ;; + iso15-8x8) defaultitem="d $msg_iso_8859_15" ;; + swiss-8x8) defaultitem="e $msg_swiss" ;; + esac + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_menutag_store -s "$menu_choice" + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_system_console_font" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +dialog_menu_main || f_die +f_dialog_menutag_fetch mtag + +f8= f14= f16= mc_start= +case "$mtag" in +"1 $msg_none") # Use hardware default font + f8="NO" f14="NO" f16="NO" ;; +"2 $msg_ibm_437") # English and others, VGA default + f8="cp437-8x8" f14="cp437-8x14" f16="cp437-8x16" ;; +"3 $msg_ibm_850") # Western Europe, IBM encoding + f8="cp850-8x8" f14="cp850-8x14" f16="cp850-8x16" ;; +"4 $msg_ibm_865") # Norwegian, IBM encoding + f8="cp865-8x8" f14="cp865-8x14" f16="cp865-8x16" ;; +"5 $msg_ibm_866") # Russian, IBM encoding (use with KOI8-R screenmap) + f8="cp866-8x8" f14="cp866-8x14" f16="cp866b-8x16" mc_start="3" ;; +"6 $msg_ibm_866u") # Ukrainian, IBM encoding (use w/ KOI8-U screenmap) + f8="cp866u-8x8" f14="cp866u-8x14" f16="cp866u-8x16" mc_start="3" ;; +"7 $msg_ibm_1251") # Cyrillic, MS Windows encoding + f8="cp1251-8x8" f14="cp1251-8x14" f16="cp1251-8x16" mc_start="3" ;; +"8 $msg_iso_8859_1") # Western Europe, ISO encoding + f8="iso-8x8" f14="iso-8x14" f16="iso-8x16" ;; +"9 $msg_iso_8859_2") # Eastern Europe, ISO encoding + f8="iso02-8x8" f14="iso02-8x14" f16="iso02-8x16" ;; +"a $msg_iso_8859_4") # Baltic, ISO encoding + f8="iso04-8x8" f14="iso04-8x14" f16="iso04-8x16" ;; +"b $msg_iso_8859_7") # Greek, ISO encoding + f8="iso07-8x8" f14="iso07-8x14" f16="iso07-8x16" ;; +"c $msg_iso_8859_8") # Hebrew, ISO encoding + f8="iso08-8x8" f14="iso08-8x14" f16="iso08-8x16" ;; +"d $msg_iso_8859_15") # Europe, ISO encoding + f8="iso15-8x8" f14="iso15-8x14" f16="iso15-8x16" ;; +"e $msg_swiss") # English, better resolution + f8="swiss-8x8" f14="NO" f16="swiss-8x16" ;; +esac + +[ "$f8" -a "$f14" -a "$f16" ] || f_die 1 "$msg_unknown_font_selection" + +f_eval_catch "$0" f_sysrc_set 'f_sysrc_set font8x8 "%s"' "$f8" || f_die +f_eval_catch "$0" f_sysrc_set 'f_sysrc_set font8x14 "%s"' "$f14" || f_die +f_eval_catch "$0" f_sysrc_set 'f_sysrc_set font8x16 "%s"' "$f16" || f_die + +if [ "$mc_start" ]; then + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set mousechar_start "%s"' "$mc_start" || f_die +else + f_eval_catch "$0" f_sysrc_delete \ + 'f_sysrc_delete mousechar_start' || f_die +fi + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/console/include/Makefile b/bsdconfig/console/include/Makefile new file mode 100644 index 000000000000..52cb0be9c6e8 --- /dev/null +++ b/bsdconfig/console/include/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${LIBEXECDIR}/bsdconfig/080.console/include +FILES= messages.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/console/include/Makefile.depend b/bsdconfig/console/include/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/console/include/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/console/include/messages.subr b/bsdconfig/console/include/messages.subr new file mode 100644 index 000000000000..295f3e302db8 --- /dev/null +++ b/bsdconfig/console/include/messages.subr @@ -0,0 +1,270 @@ +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +hline_choose_a_font="Choose a font" +hline_choose_a_keyboard_map="Choose a keyboard map" +hline_choose_a_keyboard_repeat_rate="Choose a keyboard repeat rate" +hline_choose_a_screen_map="Choose a screen map" +hline_choose_a_screen_saver="Choose a nifty-looking screen saver" +hline_choose_a_terminal_type="Choose a terminal type" +hline_configure_system_console_settings="Configure your system console settings" +msg_beastie="Beastie" +msg_beastie_desc="\"BSD Daemon\" animated screen saver (graphics)" +msg_belgian="Belgian" +msg_belgian_desc="Belgian ISO keymap" +msg_blank="Blank" +msg_blank_desc="Blank screen" +msg_brazil_cp850="Brazil CP850" +msg_brazil_cp850_desc="Brazil CP850 keymap" +msg_brazil_iso="Brazil ISO" +msg_brazil_iso_accent="Brazil ISO (accent)" +msg_brazil_iso_accent_desc="Brazil ISO keymap (accent keys)" +msg_brazil_iso_desc="Brazil ISO keymap" +msg_bulgarian_bds="Bulgarian BDS" +msg_bulgarian_bds_desc="Bulgarian BDS keymap" +msg_bulgarian_phonetic="Bulgarian Phonetic" +msg_bulgarian_phonetic_desc="Bulgarian Phonetic keymap" +msg_cancel="Cancel" +msg_central_european_iso="Central European ISO" +msg_central_european_iso_desc="Central European ISO keymap" +msg_choose_alternate_keyboard_map="Choose an alternate keyboard map" +msg_choose_alternate_screen_font="Choose an alternate screen font" +msg_choose_alternate_screenmap="Choose an alternate screenmap" +msg_choose_console_terminal_type="Choose console terminal type" +msg_configure_screen_saver="Configure the screen saver" +msg_console_menu_text="The system console driver for FreeBSD has a number of configuration\noptions which may be set according to your preference.\n\nWhen you are done setting configuration options, select Cancel." +msg_croatian_iso="Croation ISO" +msg_croatian_iso_desc="Croation ISO keymap" +msg_czech_iso_accent="Czech ISO (accent)" +msg_czech_iso_accent_desc="Czech ISO keymap (accent keys)" +msg_daemon="Daemon" +msg_daemon_desc="\"BSD Daemon\" animated screen saver (text)" +msg_danish_cp865="Danish CP865" +msg_danish_cp865_desc="Danish Code Page 865 keymap" +msg_danish_iso="Danish ISO" +msg_danish_iso_desc="Danish ISO keymap" +msg_default="Default" +msg_default_desc="Use default keyboard repeat rate" +msg_dragon="Dragon" +msg_dragon_desc="Dragon screensaver (graphics)" +msg_enter_timeout_period="Enter time-out period in seconds for screen saver" +msg_estonian_cp850="Estonian CP850" +msg_estonian_cp850_desc="Estonian Code Page 850 keymap" +msg_estonian_iso="Estonian ISO" +msg_estonian_iso_15="Estonian ISO 15" +msg_estonian_iso_15_desc="Estonian ISO 8859-15 keymap" +msg_estonian_iso_desc="Estonian ISO keymap" +msg_exit="Exit" +msg_exit_this_menu="Exit this menu" +msg_fade="Fade" +msg_fade_desc="Fade out effect screen saver" +msg_fast="Fast" +msg_fast_desc="Fast keyboard repeat rate" +msg_finnish_cp850="Finnish CP850" +msg_finnish_cp850_desc="Finnish Code Page 850 keymap" +msg_finnish_iso="Finnish ISO" +msg_finnish_iso_desc="Finnish ISO keymap" +msg_fire="Fire" +msg_fire_desc="Flames effect screen saver" +msg_font="Font" +msg_font_menu_text="Most PC hardware defaults to displaying characters in the\nIBM 437 character set. However, in the Unix world, this\ncharacter set is very rarely used. Most Western European\ncountries, for example, prefer ISO 8859-1.\nAmerican users won't notice the difference since the bottom half\nof all these charactersets is ANSI anyway. However, they might\nwant to load a font anyway to use the 30- or 50-line displays.\nIf your hardware is capable of downloading a new display font,\nyou can select the appropriate font below." +msg_french_iso="French ISO" +msg_french_iso_accent="French ISO (accent)" +msg_french_iso_accent_desc="French ISO keymap (accent keys)" +msg_french_iso_desc="French ISO keymap" +msg_french_iso_macbook="French ISO/Macbook" +msg_french_iso_macbook_desc="French ISO keymap on macbook" +msg_german_cp850="German CP850" +msg_german_cp850_desc="German Code Page 850 keymap" +msg_german_iso="German ISO" +msg_german_iso_desc="German ISO keymap" +msg_greek_101="Greek 101" +msg_greek_101_desc="Greek ISO keymap (101 keys)" +msg_greek_104="Greek 104" +msg_greek_104_desc="Greek ISO keymap (104 keys)" +msg_greek_elot="Greek ELOT" +msg_greek_elot_desc="Greek ISO keymap (ELOT 1000)" +msg_green="Green" +msg_green_desc="\"Green\" power saving mode (if supported by monitor)" +msg_hungarian_101="Hungarian 101" +msg_hungarian_101_desc="Hungarian ISO keymap (101 key)" +msg_hungarian_102="Hungarian 102" +msg_hungarian_102_desc="Hungarian ISO keymap (102 key)" +msg_ibm_1251="IBM 1251" +msg_ibm_1251_desc="Cyrillic, MS Windows encoding" +msg_ibm_437="IBM 437" +msg_ibm_437_desc="English and others, VGA default" +msg_ibm_437_vga_default="IBM437 (VGA default)" +msg_ibm_850="IBM 850" +msg_ibm_850_desc="Western Europe, IBM encoding" +msg_ibm_865="IBM 865" +msg_ibm_865_desc="Norwegian, IBM encoding" +msg_ibm_866="IBM 866" +msg_ibm_866_desc="Russian, IBM encoding (use with KOI8-R screenmap)" +msg_ibm_866u="IBM 866u" +msg_ibm_866u_desc="Ukrainian, IBM encoding (use with KOI8-U screenmap)" +msg_icelandic="Icelandic" +msg_icelandic_accent="Icelandic (accent)" +msg_icelandic_accent_desc="Icelandic ISO keymap (accent keys)" +msg_icelandic_desc="Icelandic ISO keymap" +msg_iso_8859_15="ISO 8859-15" +msg_iso_8859_15_desc="Europe, ISO encoding" +msg_iso_8859_1="ISO 8859-1" +msg_iso_8859_1_desc="Western Europe, ISO encoding" +msg_iso_8859_1_to_ibm437="ISO 8859-1 to IBM437" +msg_iso_8859_1_to_ibm437_desc="W-Europe ISO 8859-1 to IBM 437 screenmap" +msg_iso_8859_2="ISO 8859-2" +msg_iso_8859_2_desc="Eastern Europe, ISO encoding" +msg_iso_8859_4="ISO 8859-4" +msg_iso_8859_4_desc="Baltic, ISO encoding" +msg_iso_8859_7="ISO 8859-7" +msg_iso_8859_7_desc="Greek, ISO encoding" +msg_iso_8859_7_to_ibm437="ISO 8859-7 to IBM437" +msg_iso_8859_7_to_ibm437_desc="Greek ISO 8859-1 to IBM 437 screenmap" +msg_iso_8859_8="ISO 8859-8" +msg_iso_8859_8_desc="Hebrew, ISO encoding" +msg_italian="Italian" +msg_italian_desc="Italian ISO keymap" +msg_japanese_106="Japanese 106" +msg_japanese_106_desc="Japanese 106 keymap" +msg_keymap="Keymap" +msg_keymap_menu_text="The system console driver for FreeBSD defaults to a standard\n\"US\" keyboard map. Users may wish to choose one of the\nother keymaps below." +msg_koi8_r="KOI8-R" +msg_koi8_r_to_ibm866="KOI8-R to IBM866" +msg_koi8_r_to_ibm866_desc="Russian KOI8-R to IBM 866 screenmap" +msg_koi8_u="KOI8-U" +msg_koi8_u_to_ibm866u="KOI8-U to IBM866u" +msg_koi8_u_to_ibm866u_desc="Ukrainian KOI8-U to IBM 866u screenmap" +msg_latin_american="Latin American" +msg_latin_american_accent="Latin American (accent)" +msg_latin_american_accent_desc="Latin American ISO keymap (accent keys)" +msg_latin_american_desc="Latin American ISO keymap" +msg_logo="Logo" +msg_logo_desc="FreeBSD \"logo\" animated screen saver (graphics)" +msg_none="None" +msg_none_saver_desc="Disable the screensaver" +msg_none_screenmap_desc="No screenmap, don'\''t touch font" +msg_none_ttys_desc="Don'\''t touch anything" +msg_normal="Normal" +msg_normal_desc="\"Normal\" keyboard repeat rate" +msg_norway_iso="Norway ISO" +msg_norway_iso_desc="Norwegian ISO keymap" +msg_ok="OK" +msg_polish_iso="Polish ISO" +msg_polish_iso_desc="Polish ISO keymap" +msg_portuguese="Portuguese" +msg_portuguese_accent="Portuguese (accent)" +msg_portuguese_accent_desc="Portuguese ISO keymap (accent keys)" +msg_portuguese_desc="Portuguese ISO keymap" +msg_rain="Rain" +msg_rain_desc="Rain drops screen saver" +msg_repeat="Repeat" +msg_repeat_menu_text="This menu allows you to set the speed at which keys repeat\nwhen held down." +msg_russia_koi8_r="Russia KOI8-R" +msg_russia_koi8_r_desc="Russia KOI8-R keymap" +msg_saver="Saver" +msg_saver_menu_text="By default, the console driver will not attempt to do anything\nspecial with your screen when it's idle. If you expect to leave your\nmonitor switched on and idle for long periods of time then you should\nprobably enable one of these screen savers to prevent burn-in." +msg_screenmap="Screenmap" +msg_screenmap_menu_text="Unless you load a specific font, most PC hardware defaults to\ndisplaying characters in the IBM 437 character set. However,\nin the Unix world, this character set is very rarely used. Most\nWestern European countries, for example, prefer ISO 8859-1.\nAmerican users won't notice the difference since the bottom half\nof all these character sets is ANSI anyway.\nIf your hardware is capable of downloading a new display font,\nyou should probably choose that option. However, for hardware\nwhere this is not possible (e.g. monochrome adapters), a screen\nmap will give you the best approximation that your hardware can\ndisplay at all." +msg_set_repeat_rate="Set the rate at which keys repeat" +msg_slovak="Slovak" +msg_slovak_desc="Slovak ISO keymap" +msg_slovenian="Slovenian" +msg_slovenian_desc="Slovenian ISO keymap" +msg_slow="Slow" +msg_slow_desc="Slow keyboard repeat rate" +msg_snake="Snake" +msg_snake_desc="Draw a FreeBSD \"snake\" on your screen" +msg_spanish="Spanish" +msg_spanish_accent="Spanish (accent)" +msg_spanish_accent_desc="Spanish ISO keymap (accent keys)" +msg_spanish_desc="Spanish ISO keymap" +msg_star="Star" +msg_star_desc="A \"twinkling stars\" effect" +msg_swedish_cp850="Swedish CP850" +msg_swedish_cp850_desc="Swedish Code Page 850 keymap" +msg_swedish_iso="Swedish ISO" +msg_swedish_iso_desc="Swedish ISO keymap" +msg_swiss="SWISS" +msg_swiss_desc="English, better resolution" +msg_swiss_french_cp850="Swiss French CP850" +msg_swiss_french_cp850_desc="Swiss French Code Page 850 keymap" +msg_swiss_french_iso="Swiss French ISO" +msg_swiss_french_iso_accent="Swiss French ISO (accent)" +msg_swiss_french_iso_accent_desc="Swiss French ISO keymap (accent keys)" +msg_swiss_french_iso_desc="Swiss French ISO keymap" +msg_swiss_german_cp850="Swiss German CP850" +msg_swiss_german_cp850_desc="Swiss German Code Page 850 keymap" +msg_swiss_german_iso="Swiss German ISO" +msg_swiss_german_iso_accent="Swiss German ISO (accent)" +msg_swiss_german_iso_accent_desc="Swiss German ISO keymap (accent keys)" +msg_swiss_german_iso_desc="Swiss German ISO keymap" +msg_system_console_configuration="System Console Configuration" +msg_system_console_font="System Console Font" +msg_system_console_keyboard_repeat_rate="System Console Keyboard Repeat Rate" +msg_system_console_keymap="System Console Keymap" +msg_system_console_screen_saver="System Console Screen Saver" +msg_system_console_screenmap="System Console Screenmap" +msg_system_console_terminal_type="System Console Terminal Type" +msg_timeout="Timeout" +msg_timeout_desc="Set the screen saver timeout interval" +msg_ttys="Ttys" +msg_ttys_menu_text="For various console encodings, a corresponding terminal type\nmust be chosen in /etc/ttys.\n\nWARNING: For compatibility reasons, only entries starting with\nttyv and terminal types starting with cons[0-9] can be changed\nvia this menu." +msg_uk_cp850="UK CP850" +msg_uk_cp850_desc="UK Code Page 850 keymap" +msg_uk_iso="UK ISO" +msg_uk_iso_desc="UK ISO keymap" +msg_ukrainian_koi8_u="Ukranian KOI8-U" +msg_ukrainian_koi8_u_desc="Ukranian KOI8-U keymap" +msg_ukrainian_koi8_u_koi8_r="Ukranian KOI8-U+KOI8-R" +msg_ukrainian_koi8_u_koi8_r_desc="Ukranian KOI8-U+KOI8-R keymap (alter)" +msg_unknown_console_menu_selection="Unknown console menu selection" +msg_unknown_font_selection="Unknown font selection" +msg_unknown_keymap="Unknown keymap" +msg_unknown_repeat_rate="Unknown repeat rate" +msg_unknown_saver="Unknown saver" +msg_unknown_screenmap_selection="Unknown screenmap selection" +msg_us_ascii="US-ASCII" +msg_us_ascii_to_ibm327="US-ASCII to IBM437" +msg_us_ascii_to_ibm327_desc="US-ASCII to IBM 437 screenmap" +msg_usa_capslock_ctrl="USA CapsLock->Ctrl" +msg_usa_capslock_ctrl_desc="US standard (Caps as L-Control)" +msg_usa_dvorak="USA Dvorak" +msg_usa_dvorak_desc="US Dvorak keymap" +msg_usa_dvorak_left="USA Dvorak (left)" +msg_usa_dvorak_left_desc="US left handed Dvorak keymap" +msg_usa_dvorak_right="USA Dvorak (right)" +msg_usa_dvorak_right_desc="US right handed Dvorak keymap" +msg_usa_emacs="USA Emacs" +msg_usa_emacs_desc="US standard optimized for EMACS" +msg_usa_iso="USA ISO" +msg_usa_iso_desc="US ISO keymap" +msg_usa_unix="USA UNIX" +msg_usa_unix_desc="US traditional UNIX-workstation" +msg_use_hardware_default_font="Use hardware default font" +msg_value_required="Value Required" +msg_warp="Warp" +msg_warp_desc="A \"stars warping\" effect" diff --git a/bsdconfig/console/keymap b/bsdconfig/console/keymap new file mode 100755 index 000000000000..28c0500cf8ac --- /dev/null +++ b/bsdconfig/console/keymap @@ -0,0 +1,338 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ CONFIGURATION + +# +# List of keymap names +# +KEYMAP_NAMES=" + belgian brazil_cp850 brazil_iso + brazil_iso_accent bulgarian_bds bulgarian_phonetic + central_european_iso croatian_iso czech_iso_accent + danish_cp865 danish_iso estonian_cp850 + estonian_iso estonian_iso_15 finnish_cp850 + finnish_iso french_iso french_iso_accent + french_iso_macbook german_cp850 german_iso + greek_101 greek_104 greek_elot + hungarian_101 hungarian_102 icelandic + icelandic_accent italian japanese_106 + latin_american latin_american_accent norway_iso + polish_iso portuguese portuguese_accent + russia_koi8_r slovak slovenian + spanish spanish_accent swedish_cp850 + swedish_iso swiss_french_cp850 swiss_french_iso + swiss_french_iso_accent swiss_german_cp850 swiss_german_iso + swiss_german_iso_accent uk_cp850 uk_iso + ukrainian_koi8_u ukrainian_koi8_u_koi8_r usa_capslock_ctrl + usa_dvorak usa_dvorak_left usa_dvorak_right + usa_emacs usa_iso usa_unix +" # END-QUOTE + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_keymap_menu_text" + local menu_list defaultitem= # Calculated below + local hline="$hline_choose_a_keyboard_map" + + # + # Export variables for awk(1) ENVIRON visibility + # + local name + for name in $KEYMAP_NAMES; do + export msg_$name msg_${name}_desc + done + + # + # Generate a sorted list of keymaps. If the first letter of the keymap + # name is unique (case-insensitive) then it is used as the tag to allow + # the user to jump to that entry. + # + menu_list=$( + for name in $KEYMAP_NAMES; do + eval echo \"\$msg_$name\" msg_$name + done | sort | awk 'BEGIN { prefix = "" } + { + cur_prefix = tolower(substr(ENVIRON[$NF], 1, 1)) + printf "'\''" + if ( prefix != cur_prefix ) + prefix = cur_prefix + else + printf " " + printf "%s'\'' '\''%s'\''\n", + ENVIRON[$NF], ENVIRON[$NF"_desc"] + }' + ) + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + case "$( f_sysrc_get keymap )" in + be.iso) defaultitem="$msg_belgian" ;; + br275.cp850) defaultitem="$msg_brazil_cp850" ;; + br275.iso) defaultitem="$msg_brazil_iso" ;; + br275.iso.acc) defaultitem="$msg_brazil_iso_accent" ;; + bg.bds.ctrlcaps) defaultitem="$msg_bulgarian_bds" ;; + bg.phonetic.ctrlcaps) defaultitem="$msg_bulgarian_phonetic" ;; + ce.iso2) defaultitem="$msg_central_european_iso" ;; + hr.iso) defaultitem="$msg_croatian_iso" ;; + cs.latin2.qwertz) defaultitem="$msg_czech_iso_accent" ;; + danish.cp865) defaultitem="$msg_danish_cp865" ;; + danish.iso) defaultitem="$msg_danish_iso" ;; + estonian.cp850) defaultitem="$msg_estonian_cp850" ;; + estonian.iso) defaultitem="$msg_estonian_iso" ;; + estonian.iso15) defaultitem="$msg_estonian_iso_15" ;; + finnish.cp850) defaultitem="$msg_finnish_cp850" ;; + finnish.iso) defaultitem="$msg_finnish_iso" ;; + fr.iso) defaultitem="$msg_french_iso" ;; + fr.iso.acc) defaultitem="$msg_french_iso_accent" ;; + fr.macbook.acc) defaultitem="$msg_french_iso_macbook" ;; + german.cp850) defaultitem="$msg_german_cp850" ;; + german.iso) defaultitem="$msg_german_iso" ;; + gr.us101.acc) defaultitem="$msg_greek_101" ;; + el.iso07) defaultitem="$msg_greek_104" ;; + gr.elot.acc) defaultitem="$msg_greek_elot" ;; + hu.iso2.101keys) defaultitem="$msg_hungarian_101" ;; + hu.iso2.102keys) defaultitem="$msg_hungarian_102" ;; + icelandic.iso) defaultitem="$msg_icelandic" ;; + icelandic.iso.acc) defaultitem="$msg_icelandic_accent" ;; + it.iso) defaultitem="$msg_italian" ;; + jp.106) defaultitem="$msg_japanese_106" ;; + latinamerican) defaultitem="$msg_latin_american" ;; + latinamerican.iso.acc) defaultitem="$msg_latin_american_accent" ;; + norwegian.iso) defaultitem="$msg_norway_iso" ;; + pl_PL.ISO8859-2) defaultitem="$msg_polish_iso" ;; + pt.iso) defaultitem="$msg_portuguese" ;; + pt.iso.acc) defaultitem="$msg_portuguese_accent" ;; + ru.koi8-r) defaultitem="$msg_russia_koi8_r" ;; + sk.iso2) defaultitem="$msg_slovak" ;; + si.iso) defaultitem="$msg_slovenian" ;; + spanish.iso) defaultitem="$msg_spanish" ;; + spanish.iso.acc) defaultitem="$msg_spanish_accent" ;; + swedish.cp850) defaultitem="$msg_swedish_cp850" ;; + swedish.iso) defaultitem="$msg_swedish_iso" ;; + swissfrench.cp850) defaultitem="$msg_swiss_french_cp850" ;; + swissfrench.iso) defaultitem="$msg_swiss_french_iso" ;; + swissfrench.iso.acc) defaultitem="$msg_swiss_french_iso_accent" ;; + swissgerman.cp850) defaultitem="$msg_swiss_german_cp850" ;; + swissgerman.iso) defaultitem="$msg_swiss_german_iso" ;; + swissgerman.iso.acc) defaultitem="$msg_swiss_german_iso_accent" ;; + uk.cp850) defaultitem="$msg_uk_cp850" ;; + uk.iso) defaultitem="$msg_uk_iso" ;; + ua.koi8-u) defaultitem="$msg_ukrainian_koi8_u" ;; + ua.koi8-u.shift.alt) defaultitem="$msg_ukrainian_koi8_u_koi8_r" ;; + us.ctrl) defaultitem="$msg_usa_capslock_ctrl" ;; + us.pc-ctrl) defaultitem="$msg_usa_capslock_ctrl" ;; + us.dvorak) defaultitem="$msg_usa_dvorak" ;; + us.dvorakl) defaultitem="$msg_usa_dvorak_left" ;; + us.dvorakr) defaultitem="$msg_usa_dvorak_right" ;; + us.emacs) defaultitem="$msg_usa_emacs" ;; + us.iso) defaultitem="$msg_usa_iso" ;; + us.unix) defaultitem="$msg_usa_unix" ;; + esac + + # The defaultitem may have to be indented to match the menu_list + if [ "$defaultitem" ]; then + ( eval set -- $menu_list + while [ $# -gt 0 ]; do + [ "$defaultitem" = "$1" ] && break + [ " $defaultitem" = "$1" ] && exit 0 + shift 2 # tag/item + done + exit 1 # No modification needed + ) && defaultitem=" $defaultitem" + fi + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_menutag_store -s "$menu_choice" + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_system_console_keymap" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +while :; do + dialog_menu_main || f_die + f_dialog_menutag_fetch mtag + + # + # Reverse the users choice into the variable name + # + keymap_name= + mtag="${mtag# }" # remove single leading-space if-present + for name in $KEYMAP_NAMES; do + debug= f_getvar msg_$name msg + [ "$msg" = "$mtag" ] && keymap_name="$name" break + done + + [ "$keymap_name" ] || continue + + keymap_to_set= + case "$keymap_name" in + belgian) keymap_to_set="be.iso" ;; + brazil_cp850) keymap_to_set="br275.cp850" ;; + brazil_iso) keymap_to_set="br275.iso" ;; + brazil_iso_accent) keymap_to_set="br275.iso.acc" ;; + bulgarian_bds) keymap_to_set="bg.bds.ctrlcaps" ;; + bulgarian_phonetic) keymap_to_set="bg.phonetic.ctrlcaps" ;; + central_european_iso) keymap_to_set="ce.iso2" ;; + croatian_iso) keymap_to_set="hr.iso" ;; + czech_iso_accent) keymap_to_set="cs.latin2.qwertz" ;; + danish_cp865) keymap_to_set="danish.cp865" ;; + danish_iso) keymap_to_set="danish.iso" ;; + estonian_cp850) keymap_to_set="estonian.cp850" ;; + estonian_iso) keymap_to_set="estonian.iso" ;; + estonian_iso_15) keymap_to_set="estonian.iso15" ;; + finnish_cp850) keymap_to_set="finnish.cp850" ;; + finnish_iso) keymap_to_set="finnish.iso" ;; + french_iso) keymap_to_set="fr.iso" ;; + french_iso_accent) keymap_to_set="fr.iso.acc" ;; + french_iso_macbook) keymap_to_set="fr.macbook.acc" ;; + german_cp850) keymap_to_set="german.cp850" ;; + german_iso) keymap_to_set="german.iso" ;; + greek_101) keymap_to_set="gr.us101.acc" ;; + greek_104) keymap_to_set="el.iso07" ;; + greek_elot) keymap_to_set="gr.elot.acc" ;; + hungarian_101) keymap_to_set="hu.iso2.101keys" ;; + hungarian_102) keymap_to_set="hu.iso2.102keys" ;; + icelandic) keymap_to_set="icelandic.iso" ;; + icelandic_accent) keymap_to_set="icelandic.iso.acc" ;; + italian) keymap_to_set="it.iso" ;; + japanese_106) keymap_to_set="jp.106" ;; + latin_american) keymap_to_set="latinamerican" ;; + latin_american_accent) keymap_to_set="latinamerican.iso.acc" ;; + norway_iso) keymap_to_set="norwegian.iso" ;; + polish_iso) keymap_to_set="pl_PL.ISO8859-2" ;; + portuguese) keymap_to_set="pt.iso" ;; + portuguese_accent) keymap_to_set="pt.iso.acc" ;; + russia_koi8_r) keymap_to_set="ru.koi8-r" ;; + slovak) keymap_to_set="sk.iso2" ;; + slovenian) keymap_to_set="si.iso" ;; + spanish) keymap_to_set="spanish.iso" ;; + spanish_accent) keymap_to_set="spanish.iso.acc" ;; + swedish_cp850) keymap_to_set="swedish.cp850" ;; + swedish_iso) keymap_to_set="swedish.iso" ;; + swiss_french_cp850) keymap_to_set="swissfrench.cp850" ;; + swiss_french_iso) keymap_to_set="swissfrench.iso" ;; + swiss_french_iso_accent) keymap_to_set="swissfrench.iso.acc" ;; + swiss_german_cp850) keymap_to_set="swissgerman.cp850" ;; + swiss_german_iso) keymap_to_set="swissgerman.iso" ;; + swiss_german_iso_accent) keymap_to_set="swissgerman.iso.acc" ;; + uk_cp850) keymap_to_set="uk.cp850" ;; + uk_iso) keymap_to_set="uk.iso" ;; + ukrainian_koi8_u) keymap_to_set="ua.koi8-u" ;; + ukrainian_koi8_u_koi8_r) keymap_to_set="ua.koi8-u.shift.alt" ;; + usa_capslock_ctrl) + case "$( sysctl -n kern.vty )" in + vt) keymap_to_set="us.ctrl" ;; + *) keymap_to_set="us.pc-ctrl" ;; + esac + ;; + usa_dvorak) keymap_to_set="us.dvorak" ;; + usa_dvorak_left) keymap_to_set="us.dvorakl" ;; + usa_dvorak_right) keymap_to_set="us.dvorakr" ;; + usa_emacs) keymap_to_set="us.emacs" ;; + usa_iso) keymap_to_set="us.iso" ;; + usa_unix) keymap_to_set="us.unix" ;; + esac + + if [ "$keymap_to_set" ]; then + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set keymap "%s"' "$keymap_to_set" || f_die + break + else + f_die 1 "$msg_unknown_keymap" + fi +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/console/repeat b/bsdconfig/console/repeat new file mode 100755 index 000000000000..ff000234dc74 --- /dev/null +++ b/bsdconfig/console/repeat @@ -0,0 +1,143 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_repeat_menu_text" + local menu_list=" + '$msg_default' '$msg_default_desc' + '$msg_slow' '$msg_slow_desc' + '$msg_normal' '$msg_normal_desc' + '$msg_fast' '$msg_fast_desc' + " # END-QUOTE + local defaultitem= # Calculated below + local hline="$hline_choose_a_keyboard_repeat_rate" + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + case "$( f_sysrc_get keyrate )" in + [Nn][Oo]|'') defaultitem="$msg_default" ;; + slow) defaultitem="$msg_slow" ;; + normal) defaultitem="$msg_normal" ;; + fast) defaultitem="$msg_fast" ;; + esac + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_menutag_store -s "$menu_choice" + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_system_console_keyboard_repeat_rate" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +dialog_menu_main || f_die +f_dialog_menutag_fetch mtag + +repeat_rate_to_set= +case "$mtag" in +"$msg_default") repeat_rate_to_set="NO" ;; # Use default repeat rate +"$msg_slow") repeat_rate_to_set="slow" ;; # Slow keyboard repeat rate +"$msg_normal") repeat_rate_to_set="normal" ;; # "Normal" keyboard repeat rate +"$msg_fast") repeat_rate_to_set="fast" ;; # Fast keyboard repeat rate +esac + +if [ "$repeat_rate_to_set" ]; then + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set keyrate "%s"' "$repeat_rate_to_set" || f_die + break +else + f_die 1 "$msg_unknown_repeat_rate" +fi + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/console/saver b/bsdconfig/console/saver new file mode 100755 index 000000000000..0df487c9583d --- /dev/null +++ b/bsdconfig/console/saver @@ -0,0 +1,195 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_saver_menu_text" + local menu_list=" + '1 $msg_none' '$msg_none_saver_desc' + '2 $msg_blank' '$msg_blank_desc' + '3 $msg_beastie' '$msg_beastie_desc' + '4 $msg_daemon' '$msg_daemon_desc' + '5 $msg_dragon' '$msg_dragon_desc' + '6 $msg_fade' '$msg_fade_desc' + '7 $msg_fire' '$msg_fire_desc' + '8 $msg_green' '$msg_green_desc' + '9 $msg_logo' '$msg_logo_desc' + 'a $msg_rain' '$msg_rain_desc' + 'b $msg_snake' '$msg_snake_desc' + 'c $msg_star' '$msg_star_desc' + 'd $msg_warp' '$msg_warp_desc' + '$msg_timeout' '$msg_timeout_desc' + " # END-QUOTE + local defaultitem= # Calculated below + local hline="$hline_choose_a_screen_saver" + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + case "$( f_sysrc_get saver )" in + [Nn][Oo]|'') defaultitem="1 $msg_none" ;; + blank) defaultitem="2 $msg_blank" ;; + beastie) defaultitem="3 $msg_beastie" ;; + daemon) defaultitem="4 $msg_daemon" ;; + dragon) defaultitem="5 $msg_dragon" ;; + fade) defaultitem="6 $msg_fade" ;; + fire) defaultitem="7 $msg_fire" ;; + green) defaultitem="8 $msg_green" ;; + logo) defaultitem="9 $msg_logo" ;; + rain) defaultitem="a $msg_rain" ;; + snake) defaultitem="b $msg_snake" ;; + star) defaultitem="c $msg_star" ;; + warp) defaultitem="d $msg_warp" ;; + esac + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_menutag_store -s "$menu_choice" + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_system_console_screen_saver" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +dialog_menu_main || f_die +f_dialog_menutag_fetch mtag + +case "$mtag" in +"$msg_timeout") # Set the screen saver timeout interval + f_dialog_title "$msg_value_required" + f_dialog_input blanktime "$msg_enter_timeout_period" \ + "$( f_sysrc_get blanktime )" && + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set blanktime "%s"' "$blanktime" || f_die + f_dialog_title_restore + exit $SUCCESS +esac + +saver_to_set= +case "$mtag" in +"1 $msg_none") # Disable the screensaver + saver_to_set="NO" ;; +"2 $msg_blank") # Simply blank the screen + saver_to_set="blank" ;; +"3 $msg_beastie") # "BSD Daemon" animated screen saver (graphics) + saver_to_set="beastie" ;; +"4 $msg_daemon") # "BSD Daemon" animated screen saver (text) + saver_to_set="daemon" ;; +"5 $msg_dragon") # Dragon screensaver (graphics) + saver_to_set="dragon" ;; +"6 $msg_fade") # Fade out effect screen saver + saver_to_set="fade" ;; +"7 $msg_fire") # Flames effect screen saver + saver_to_set="fire" ;; +"8 $msg_green") # "Green" power saving mode (if supported by monitor) + saver_to_set="green" ;; +"9 $msg_logo") # FreeBSD "logo" animated screen saver (graphics) + saver_to_set="logo" ;; +"a $msg_rain") # Rain drops screen saver + saver_to_set="rain" ;; +"b $msg_snake") # Draw a FreeBSD "snake" on your screen + saver_to_set="snake" ;; +"c $msg_star") # A "twinkling stars" effect + saver_to_set="star" ;; +"d $msg_warp") # A "stars warping" effect + saver_to_set="warp" ;; +esac + +if [ "$saver_to_set" ]; then + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set saver "%s"' "$saver_to_set" || f_die + break +else + f_die 1 "$msg_unknown_saver" +fi + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/console/screenmap b/bsdconfig/console/screenmap new file mode 100755 index 000000000000..5bf5bd872da0 --- /dev/null +++ b/bsdconfig/console/screenmap @@ -0,0 +1,155 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_screenmap_menu_text" + local menu_list=" + '1 $msg_none' '$msg_none_screenmap_desc' + '2 $msg_iso_8859_1_to_ibm437' '$msg_iso_8859_1_to_ibm437_desc' + '3 $msg_iso_8859_7_to_ibm437' '$msg_iso_8859_7_to_ibm437_desc' + '4 $msg_us_ascii_to_ibm327' '$msg_us_ascii_to_ibm327_desc' + '5 $msg_koi8_r_to_ibm866' '$msg_koi8_r_to_ibm866_desc' + '6 $msg_koi8_u_to_ibm866u' '$msg_koi8_u_to_ibm866u_desc' + " # END-QUOTE + local defaultitem= # Calculated below + local hline="$hline_choose_a_screen_map" + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + case "$( f_sysrc_get scrnmap )" in + [Nn][Oo]|'') defaultitem="1 $msg_none" ;; + iso-8859-1_to_cp437) defaultitem="2 $msg_iso_8859_1_to_ibm437" ;; + iso-8859-7_to_cp437) defaultitem="3 $msg_iso_8859_7_to_ibm437" ;; + us-ascii_to_cp437) defaultitem="4 $msg_us_ascii_to_ibm327" ;; + koi8-r2cp866) defaultitem="5 $msg_koi8_r_to_ibm866" ;; + koi8-u2cp866u) defaultitem="6 $msg_koi8_u_to_ibm866u" ;; + esac + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_menutag_store -s "$menu_choice" + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_system_console_screenmap" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +dialog_menu_main || f_die +f_dialog_menutag_fetch mtag + +scrnmap_to_set= +case "$mtag" in +"1 $msg_none") # No screenmap, don't touch font + scrnmap_to_set="NO" ;; +"2 $msg_iso_8859_1_to_ibm437") # W-Europe ISO 8859-1 to IBM 437 scrnmap + scrnmap_to_set="iso-8859-1_to_cp437" ;; +"3 $msg_iso_8859_7_to_ibm437") # Greek ISO 8859-7 to IBM 437 screenmap + scrnmap_to_set="iso-8859-7_to_cp437" ;; +"4 $msg_us_ascii_to_ibm327") # US-ASCII to IBM 437 screenmap + scrnmap_to_set="us-ascii_to_cp437" ;; +"5 $msg_koi8_r_to_ibm866") # Russian KOI8-R to IBM 866 screenmap + scrnmap_to_set="koi8-r2cp866" ;; +"6 $msg_koi8_u_to_ibm866u") # Ukrainian KOI8-U to IBM 866u screenmap + scrnmap_to_set="koi8-u2cp866u" ;; +esac + +if [ "$scrnmap_to_set" ]; then + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set scrnmap "%s"' "$scrnmap_to_set" || f_die + break +else + f_die 1 "$msg_unknown_screenmap_selection" +fi + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/console/ttys b/bsdconfig/console/ttys new file mode 100755 index 000000000000..54dcb66bdd99 --- /dev/null +++ b/bsdconfig/console/ttys @@ -0,0 +1,207 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ CONFIGURATION + +# +# Location of ttys(5) +# +ETC_TTYS=/etc/ttys + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_ttys_menu_text" + local menu_list=" + '1 $msg_none' '$msg_none_ttys_desc' + '2 $msg_ibm_437_vga_default' 'cons25' + '3 $msg_iso_8859_1' 'cons25l1' + '4 $msg_iso_8859_2' 'cons25l2' + '5 $msg_iso_8859_7' 'cons25l7' + '6 $msg_koi8_r' 'cons25r' + '7 $msg_koi8_u' 'cons25u' + '8 $msg_us_ascii' 'cons25w' + " # END-QUOTE + local hline="$hline_choose_a_terminal_type" + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_menutag_store -s "$menu_choice" + + if [ $retval -eq $DIALOG_OK ]; then + local item + item=$( eval f_dialog_menutag2item \ + \"\$menu_choice\" $menu_list ) + f_dialog_menuitem_store "$item" + fi + + return $retval +} + +# ttys_set_type $consterm +# +# Set terminal type of `ttyv*' and `cons[0-9]' entries in ttys(5) to $consterm. +# +ttys_set_type() +{ + local funcname=ttys_set_type + local consterm="$1" err + + # + # Create new temporary file to write our ttys(5) update with new types. + # + local tmpfile + f_eval_catch -k tmpfile $funcname mktemp 'mktemp -t "%s"' "$pgm" || + return $FAILURE + + # + # Fixup permissions and ownership (mktemp(1) creates the temporary file + # with 0600 permissions -- change the permissions and ownership to + # match ttys(5) before we write it out and mv(1) it into place). + # + local mode owner + f_eval_catch -dk mode $funcname stat \ + 'stat -f "%%#Lp" "%s"' "$ETC_TTYS" || mode=0644 + f_eval_catch -dk owner $funcname stat \ + 'stat -f "%%u:%%g" "%s"' "$ETC_TTYS" || owner="root:wheel" + f_eval_catch -d $funcname chmod 'chmod "%s" "%s"' "$mode" "$tmpfile" + f_eval_catch -d $funcname chown 'chown "%s" "%s"' "$owner" "$tmpfile" + + # + # Operate on ttys(5), replacing only the types of `ttyv*' and + # `cons[0-9]' terminals with the new type. + # + if ! err=$( awk -v consterm="$consterm" ' + BEGIN { + } + { + # "Skip" blank-lines, lines containing only whitespace, and + # lines containing only a comment or whitespace-then-comment. + # + if ( $0 ~ /^[[:space:]]*(#|$)/ ) { print; next } + + # "Skip" terminal types other than those supported + # + if ( $1 !~ /^(ttyv.*|cons[0-9])$/ ) { print; next } + + # Change the terminal type to the new value + # + match($0, /[[:alnum:]\.\+-_]+[[:space:]]+(on|off).*$/) + if ( ! RSTART ) { print; next } + left = substr($0, 0, RSTART - 1) + match($0, /[[:space:]]+(on|off).*$/) + right = substr($0, RSTART) + printf "%s%s%s\n", left, consterm, right + } + ' "$ETC_TTYS" > "$tmpfile" 2>&1 ); then + f_dialog_msgbox "$err" + return $FAILURE + fi + f_eval_catch $funcname mv 'mv -f "%s" "%s"' "$tmpfile" "$ETC_TTYS" || + return $FAILURE + + return $SUCCESS +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_system_console_terminal_type" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +dialog_menu_main || f_die +f_dialog_menutag_fetch mtag + +[ "$mtag" = "1 $msg_none" ] && exit $SUCCESS + +f_dialog_menuitem_fetch consterm +ttys_set_type "$consterm" || f_die + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/diskmgmt/INDEX b/bsdconfig/diskmgmt/INDEX new file mode 100644 index 000000000000..e04bb79dafe2 --- /dev/null +++ b/bsdconfig/diskmgmt/INDEX @@ -0,0 +1,57 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# +# Title that will be shown in the bsdconfig menu. +# +menu_title="Disk Management" + +# +# A short descriptive line shown at the bottom of the bsdconfig menu. keep it +# short because any line longer than the terminal width will be truncated. +# +menu_help="Manage disk partitions and/or labels" + +# +# Two-part variable that defines an action to take when `keyword' is passed on +# a bsdconfig command line. Variable takes the form "keyword|command" and +# multiple occurrences of the variable (with different `keyword's, or different +# `keyword's AND `command's) are allowed. If `command' begins with a '/' then +# the full path to the program is needed. If `command' begins with anything +# else it is a path relative to the directory this INDEX file is in. `keyword' +# can be i18n'ed but `command' is the name of a script. +# +menu_selection="diskmgmt|diskmgmt" + +# +# ------------ Items below this line do NOT need i18n translation ------------ +# +# Name of the program to be run when this menu choice is selected. If it begins +# with a '/' then the full path to the program is needed. If it begins with +# anything else it is a path relative to the directory this INDEX file is in. +# +menu_program="diskmgmt" diff --git a/bsdconfig/diskmgmt/Makefile b/bsdconfig/diskmgmt/Makefile new file mode 100644 index 000000000000..16a89009bb6e --- /dev/null +++ b/bsdconfig/diskmgmt/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +SUBDIR= include + +FILESDIR= ${LIBEXECDIR}/bsdconfig/050.diskmgmt +FILES= INDEX USAGE + +SCRIPTSDIR= ${FILESDIR} +SCRIPTS= diskmgmt + +.include <bsd.prog.mk> diff --git a/bsdconfig/diskmgmt/Makefile.depend b/bsdconfig/diskmgmt/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/diskmgmt/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/diskmgmt/USAGE b/bsdconfig/diskmgmt/USAGE new file mode 100644 index 000000000000..a06d8af24928 --- /dev/null +++ b/bsdconfig/diskmgmt/USAGE @@ -0,0 +1,37 @@ +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS] + +OPTIONS: + -d Provide lots of debugging info on standard-out when running. + -D file Send debugging info to file. If file begins with a plus-sign + debug info is sent to both standard-out and file (minus the + leading plus). + -h Print this usage statement and exit. + -S Secure X11 mode (implies `-X'). As root, always prompt-for + and validate sudo(8) username/password before starting. + -X Use Xdialog(1) in place of dialog(1). diff --git a/bsdconfig/diskmgmt/diskmgmt b/bsdconfig/diskmgmt/diskmgmt new file mode 100755 index 000000000000..ec567f550e77 --- /dev/null +++ b/bsdconfig/diskmgmt/diskmgmt @@ -0,0 +1,85 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ CONFIGURATION + +# +# If X11 is requested, which terminal and what options should we use? +# +X11TERM=xterm +X11TERM_OPTS= + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_mustberoot_init + +# +# If Xdialog(1) is requested, we'll need to wrap bsdinstall(8) into xterm(1) +# +if [ "$USE_XDIALOG" ]; then + f_have "$X11TERM" || f_die 1 \ + "$msg_no_such_file_or_directory" "$pgm" "$X11TERM" + + exec $X11TERM $X11TERM_OPTS -e /usr/sbin/bsdinstall partedit +else + exec /usr/sbin/bsdinstall partedit +fi + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/diskmgmt/include/Makefile b/bsdconfig/diskmgmt/include/Makefile new file mode 100644 index 000000000000..c9271532ff8c --- /dev/null +++ b/bsdconfig/diskmgmt/include/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${LIBEXECDIR}/bsdconfig/050.diskmgmt/include +FILES= messages.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/diskmgmt/include/Makefile.depend b/bsdconfig/diskmgmt/include/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/diskmgmt/include/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/diskmgmt/include/messages.subr b/bsdconfig/diskmgmt/include/messages.subr new file mode 100644 index 000000000000..f0b563f970a8 --- /dev/null +++ b/bsdconfig/diskmgmt/include/messages.subr @@ -0,0 +1,27 @@ +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +msg_no_such_file_or_directory="%s: %s: No such file or directory" diff --git a/bsdconfig/docsinstall/INDEX b/bsdconfig/docsinstall/INDEX new file mode 100644 index 000000000000..6308f30cecf7 --- /dev/null +++ b/bsdconfig/docsinstall/INDEX @@ -0,0 +1,57 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# +# Title that will be shown in the bsdconfig menu. +# +menu_title="Documentation installation" + +# +# A short descriptive line shown at the bottom of the bsdconfig menu. keep it +# short because any line longer than the terminal width will be truncated. +# +menu_help="Install FreeBSD Documentation set" + +# +# Two-part variable that defines an action to take when `keyword' is passed on +# a bsdconfig command line. Variable takes the form "keyword|command" and +# multiple occurrences of the variable (with different `keyword's, or different +# `keyword's AND `command's) are allowed. If `command' begins with a '/' then +# the full path to the program is needed. If `command' begins with anything +# else it is a path relative to the directory this INDEX file is in. `keyword' +# can be i18n'ed but `command' is the name of a script. +# +menu_selection="docsinstall|docsinstall" + +# +# ------------ Items below this line do NOT need i18n translation ------------ +# +# Name of the program to be run when this menu choice is selected. If it begins +# with a '/' then the full path to the program is needed. If it begins with +# anything else it is a path relative to the directory this INDEX file is in. +# +menu_program="docsinstall" diff --git a/bsdconfig/docsinstall/Makefile b/bsdconfig/docsinstall/Makefile new file mode 100644 index 000000000000..2ab3a680a4eb --- /dev/null +++ b/bsdconfig/docsinstall/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +SUBDIR= include + +FILESDIR= ${LIBEXECDIR}/bsdconfig/020.docsinstall +FILES= INDEX USAGE + +SCRIPTSDIR= ${FILESDIR} +SCRIPTS= docsinstall + +.include <bsd.prog.mk> diff --git a/bsdconfig/docsinstall/Makefile.depend b/bsdconfig/docsinstall/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/docsinstall/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/docsinstall/USAGE b/bsdconfig/docsinstall/USAGE new file mode 100644 index 000000000000..a06d8af24928 --- /dev/null +++ b/bsdconfig/docsinstall/USAGE @@ -0,0 +1,37 @@ +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS] + +OPTIONS: + -d Provide lots of debugging info on standard-out when running. + -D file Send debugging info to file. If file begins with a plus-sign + debug info is sent to both standard-out and file (minus the + leading plus). + -h Print this usage statement and exit. + -S Secure X11 mode (implies `-X'). As root, always prompt-for + and validate sudo(8) username/password before starting. + -X Use Xdialog(1) in place of dialog(1). diff --git a/bsdconfig/docsinstall/docsinstall b/bsdconfig/docsinstall/docsinstall new file mode 100755 index 000000000000..19128fed6562 --- /dev/null +++ b/bsdconfig/docsinstall/docsinstall @@ -0,0 +1,97 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ CONFIGURATION + +# +# If X11 is requested, which terminal and what options should we use? +# +X11TERM=xterm +X11TERM_OPTS= + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_mustberoot_init + +# +# If Xdialog(1) is requested, we'll need to wrap bsdinstall(8) into xterm(1) +# +if [ "$USE_XDIALOG" ]; then + # + # Make sure $X11TERM exists and is executable + # + case "$X11TERM" in + */*) + [ -e "$X11TERM" ] || f_die 1 \ + "$msg_no_such_file_or_directory" "$pgm" "$X11TERM" + [ -x "$X11TERM" ] || f_die 1 \ + "$msg_permission_denied" "$pgm" "$X11TERM" + ;; + *) + f_have "$X11TERM" || f_die 1 \ + "$msg_no_such_file_or_directory" "$pgm" "$X11TERM" + esac + + exec $X11TERM $X11TERM_OPTS -e /usr/sbin/bsdinstall docsinstall +else + exec /usr/sbin/bsdinstall docsinstall +fi + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/docsinstall/include/Makefile b/bsdconfig/docsinstall/include/Makefile new file mode 100644 index 000000000000..a3ca529a7cc4 --- /dev/null +++ b/bsdconfig/docsinstall/include/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${LIBEXECDIR}/bsdconfig/020.docsinstall/include +FILES= messages.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/docsinstall/include/Makefile.depend b/bsdconfig/docsinstall/include/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/docsinstall/include/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/docsinstall/include/messages.subr b/bsdconfig/docsinstall/include/messages.subr new file mode 100644 index 000000000000..4c55f0fc078a --- /dev/null +++ b/bsdconfig/docsinstall/include/messages.subr @@ -0,0 +1,28 @@ +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +msg_no_such_file_or_directory="%s: %s: No such file or directory" +msg_permission_denied="%s: %s: permission denied" diff --git a/bsdconfig/dot/INDEX b/bsdconfig/dot/INDEX new file mode 100644 index 000000000000..fa641e01f120 --- /dev/null +++ b/bsdconfig/dot/INDEX @@ -0,0 +1,57 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# +# Title that will be shown in the bsdconfig menu. +# +menu_title="" + +# +# A short descriptive line shown at the bottom of the bsdconfig menu. keep it +# short because any line longer than the terminal width will be truncated. +# +menu_help="" + +# +# Two-part variable that defines an action to take when `keyword' is passed on +# a bsdconfig command line. Variable takes the form "keyword|command" and +# multiple occurrences of the variable (with different `keyword's, or different +# `keyword's AND `command's) are allowed. If `command' begins with a '/' then +# the full path to the program is needed. If `command' begins with anything +# else it is a path relative to the directory this INDEX file is in. `keyword' +# can be i18n'ed but `command' is the name of a script. +# +menu_selection="dot|dot" + +# +# ------------ Items below this line do NOT need i18n translation ------------ +# +# Name of the program to be run when this menu choice is selected. If it begins +# with a '/' then the full path to the program is needed. If it begins with +# anything else it is a path relative to the directory this INDEX file is in. +# +menu_program="" diff --git a/bsdconfig/dot/Makefile b/bsdconfig/dot/Makefile new file mode 100644 index 000000000000..ccd10b449cb6 --- /dev/null +++ b/bsdconfig/dot/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +SUBDIR= include + +FILESDIR= ${LIBEXECDIR}/bsdconfig/dot +FILES= INDEX USAGE + +SCRIPTSDIR= ${FILESDIR} +SCRIPTS= dot + +.include <bsd.prog.mk> diff --git a/bsdconfig/dot/Makefile.depend b/bsdconfig/dot/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/dot/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/dot/USAGE b/bsdconfig/dot/USAGE new file mode 100644 index 000000000000..5bc38cc57071 --- /dev/null +++ b/bsdconfig/dot/USAGE @@ -0,0 +1,143 @@ +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS] + +OPTIONS: + -h Print this usage statement and exit. + -c Don't show command-line shortcut relationships. + -d Don't show the date in the graph label. + -i Don't show include relationships. + +EXAMPLES: + View dot(1) language output describing bsdconfig(8) layout/make-up: + + bsdconfig @PROGRAM_NAME@ | less + + Render dot(1) output in SVG format (displays in most modern browsers): + + bsdconfig @PROGRAM_NAME@ | dot -Tsvg -o bsdconfig.svg + + NOTE: Requires `graphics/graphviz' from ports/packages. + + View the above-rendered SVG file using your favorite X11-based viewer: + + gimmage bsdconfig.svg + + NOTE: Requires `graphics/gimmage' from ports/packages. + + or + + gthumb bsdconfig.svg + + NOTE: Image is scaled to fit window on launch. + NOTE: Requires `graphics/gthumb' from ports/packages. + + or + + gqview bsdconfig.svg + + NOTE: Requires `graphics/gqview' from ports/packages. + + or + + gx bsdconfig.svg + + NOTE: Image is scaled to fit window on launch. + NOTE: Requires `graphics/gx' from ports/packages. + + or + + eog bsdconfig.svg + + NOTE: Requires `graphics/eog' from ports/packages. + + Render dot(1) output as PostScript print output consisting of multiple + US-Letter sized pages that can be assembled into a large poster (using + traditional tools such as scissors and tape): + + bsdconfig @PROGRAM_NAME@ | dot -Teps -o bsdconfig.eps + poster -v -mLet -s1 -o bsdconfig.ps bsdconfig.eps + + NOTE: Change "-s1" above to "-s0.5" to halve the size of the + poster or "-s2", for example, to double the poster size. + + NOTE: Requires both `graphics/graphviz' and `print/poster' from + ports/packages. + + Render dot(1) output as PostScript scaled to fit on a poster consisting + of 2x-wide and 4x-tall US-Letter sized pages: + + bsdconfig @PROGRAM_NAME@ | dot -Teps -o bsdconfig.eps + poster -v -mLet -p2x4Letter -o bsdconfig.ps bsdconfig.eps + + NOTE: Requires both `graphics/graphviz' and `print/poster' from + ports/packages. + + View the above-rendered PostScript poster using X11: + + gsview bsdconfig.ps + + NOTE: Requires `print/gsview' from ports/packages. + + or + + convert bsdconfig.ps bsdconfig.pdf + xpdf bsdconfig.pdf + + NOTE: Requires both `graphics/ImageMagick' and + `graphics/xdpf' from ports/packages. + + NOTE: The converted PDF file is not suitable for + printing due to loss of quality during the + conversion process. + + Print the above-rendered PostScript poster: + + lpr -h bsdconfig.ps + + NOTE: Requires configuration of a printer in `/etc/printcap'. + + Extract each page of the poster into a separate PNG file: + + gs -q -dNOPAUSE -dBATCH -sPAPERSIZE=letter \ + -dTextAlphaBits=4 -dGraphicsAlphaBits=4 \ + -sDEVICE=png16m -sOutputFile=bsdconfig%03d.png \ + bsdconfig.ps + + NOTE: Requires `print/ghostscript9' from ports/packages. + + NOTE: The converted PNG files are not suitable for printing + due to loss of quality during the conversion process. + + Extract a single page of the poster into a separate PostScript file for + printing individual pages from the command-line: + + psselect 1 bsdconfig.ps bsdconfig-page1.ps + lpr -h bsdconfig-page1.ps + + NOTE: Change "1" to "2" for the second page, ad-infinitum. + NOTE: Requires `print/psutils-letter' from ports/packages. diff --git a/bsdconfig/dot/dot b/bsdconfig/dot/dot new file mode 100755 index 000000000000..f71c0e81487f --- /dev/null +++ b/bsdconfig/dot/dot @@ -0,0 +1,678 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +# Prevent common.subr from auto initializing debugging (this is not an inter- +# active utility so does not require debugging; also `-d' has been repurposed). +# +DEBUG_SELF_INITIALIZE=NO + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" + +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ CONFIGURATION + +# +# Location of bsdconfig(8) +# +BSDCONFIG=/usr/sbin/bsdconfig + +############################################################ GLOBALS + +# +# Options +# +SHOW_GRAPH_LABEL_DATE=1 +SHOW_INCLUDES=1 +SHOW_CMDLINE=1 + +############################################################ FUNCTIONS + +# begin_nodelist $shape $color $fillcolor $style +# +# Create a new multi-node list rendering nodes in a specific style described by +# the arguments passed. +# +begin_nodelist() +{ + local shape="$1" color="$2" fillcolor="$3" style="$4" + + printf "\tnode [\n" + [ "$shape" ] && + printf '\t\tshape = "%s",\n' "$shape" + [ "$color" ] && + printf '\t\tcolor = "%s",\n' "$color" + [ "$fillcolor" ] && + printf '\t\tfillcolor = "%s",\n' "$fillcolor" + [ "$style" ] && + printf '\t\tstyle = "%s",\n' "$style" + printf "\t] {\n" +} + +# print_node $node [$attributes ...] +# +# Print a node within a multi-node list. +# +print_node() +{ + local node="$1" + + shift 1 # node + + case "$node" in + edge) printf '\t\t%s' "$node" ;; + *) printf '\t\t"%s"' "$node" ;; + esac + + if [ $# -gt 0 ]; then + echo -n ' [' + while [ $# -gt 0 ]; do + printf " %s" "$1" + shift 1 + [ $# -gt 0 ] && echo -n "," + done + echo -n " ]" + fi + + echo ";" +} + +# print_node2 $node $node [$attributes ...] +# +# Print a directed node-node connection within a multi-node list. +# +print_node2() +{ + local node1="$1" node2="$2" + + shift 2 # node1 node2 + + printf '\t\t"%s" -> "%s"' "$node1" "$node2" + + if [ $# -gt 0 ]; then + echo -n ' [' + while [ $# -gt 0 ]; do + printf " %s" "$1" + shift 1 + [ $# -gt 0 ] && echo -n "," + done + echo -n " ]" + fi + + echo ";" +} + +# end_nodelist +# +# Close a multi-node list. +# +end_nodelist() +{ + printf "\t};\n" +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts cdhi flag; do + case "$flag" in + i) SHOW_INCLUDES= ;; + d) SHOW_GRAPH_LABEL_DATE= ;; + c) SHOW_CMDLINE= ;; + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +cd $BSDCFG_LIBE || f_die # Pedantic + +# +# Get a list of menu programs +# +menu_program_list= +for file in [0-9][0-9][0-9].*/INDEX; do + menu_program_list="$menu_program_list $( + tail -r "$file" | awk -v item="${file%%/*}" ' + /^[[:space:]]*menu_program="/ { + sub(/^.*="/, "") + sub(/"$/, "") + if ( ! $0 ) next + if ( $0 !~ "^/" ) sub(/^/, item "/") + print; exit + }' + )" +done + +# +# Get a list of submenu programs +# +submenu_program_list= +for menu_program in $menu_program_list; do + case "$menu_program" in + [0-9][0-9][0-9].*/*) : fall-through ;; + *) continue # No sub-menus we can process + esac + + submenu_program_list="$submenu_program_list $( + awk -v menu_program="$menu_program" \ + -v item="${menu_program%%/*}" \ + ' + /^menu_selection="/ { + sub(/.*\|/, "") + sub(/"$/, "") + if ( ! $0 ) next + if ( $0 !~ "^/" ) + sub(/^/, item "/") + if ( $0 == menu_program ) next + print + } + ' "${menu_program%%/*}/INDEX" + )" +done + +# +# Get a list of command-line programs +# +cmd_program_list= +for file in */INDEX; do + cmd_program_list="$cmd_program_list $( + awk -v item="${file%%/*}" ' + /^menu_selection="/ { + sub(/.*\|/, "") + sub(/"$/, "") + + if ( ! $0 ) next + + if ( $0 !~ "^/" ) + sub(/^/, item "/") + + print + } + ' $file + )" +done + +# +# [Optionally] Calculate list of include files +# +if [ "$SHOW_INCLUDES" ]; then + print_includes_awk=' + BEGIN { regex = "^f_include \\$BSDCFG_SHARE/" } + ( $0 ~ regex ) { sub(regex, ""); print } + ' # END-QUOTE + + # + # Build list of files in which to search for includes + # + file_list=$( + for file in \ + $BSDCONFIG \ + $menu_program_list \ + $submenu_program_list \ + $cmd_program_list \ + $BSDCFG_SHARE/script.subr \ + ; do + [ -e "$file" ] && echo $file + done | sort -u + ) + + # + # Build list of includes used by the above files + # + include_file_list= + for file in $file_list; do + include_file_list="$include_file_list $( + awk "$print_includes_awk" $file + )" + done + + # + # Sort the list of includes and remove duplicate entries + # + include_file_list=$( + for include_file in $include_file_list; do + echo "$include_file" + done | sort -u + ) + + # + # Search previously-discovered include files for further includes + # + before="$include_file_list" + while :; do + for file in $include_file_list; do + include_file_list="$include_file_list $( + awk "$print_includes_awk" $BSDCFG_SHARE/$file + )" + done + + # + # Sort list of includes and remove duplicate entries [again] + # + include_file_list=$( + for include_file in $include_file_list; do + echo "$include_file" + done | sort -u + ) + + [ "$include_file_list" = "$before" ] && break + before="$include_file_list" + done +fi + +# +# Start the directional-graph (digraph) output +# +printf 'strict digraph "" { // Empty name to prevent SVG Auto-Tooltip\n' +label_format="$msg_graph_label_with_command" +[ "$SHOW_GRAPH_LABEL_DATE" ] && + label_format="$msg_graph_label_with_command_and_date" +lang="${LANG:-$LC_ALL}" +printf "\n\tlabel = \"$label_format\"\n" \ + "${lang:+LANG=${lang%%[$IFS]*} }bsdconfig $pgm${ARGV:+ $ARGV}" \ + "$( date +"%c %Z" )" + +# +# Print graph-specific properties +# +printf '\n\t/*\n\t * Graph setup and orientation\n\t */\n' +printf '\tlabelloc = top;\t\t// display above label at top of graph\n' +printf '\trankdir = LR;\t\t// create ranks left-to-right\n' +printf '\torientation = portrait;\t// default\n' +printf '\tratio = fill;\t\t// approximate aspect ratio\n' +printf '\tcenter = 1;\t\t// center drawing on page\n' + +# +# Perform edge-concentration when displaying a lot of information +# +# NOTE: This is disabled because dot(1) version 2.28.0 (current) and older have +# a bug that causes a crash when rankdir = LR and concentrate = true +# +# NOTE: Do not re-enable until said bug is fixed in some future revision. +# +#[ "$SHOW_INCLUDES" -a "$SHOW_CMDLINE" ] && +# printf '\tconcentrate = true;\t// enable edge concentrators\n' + +# +# Print font details for graph/cluster label(s) +# +printf '\n\t/*\n\t * Font details for graph/cluster label(s)\n\t */\n' +printf '\tfontname = "Times-Italic";\n' +printf '\tfontsize = 14;\n' + +# +# Print default node attributes +# +printf '\n\t/*\n\t * Default node attributes\n\t */\n' +printf '\tnode [\n' +printf '\t\tfontname = "Times-Roman",\n' +printf '\t\tfontsize = 12,\n' +printf '\t\twidth = 2.5, // arbitrary minimum width for all nodes\n' +printf '\t\tfixedsize = true, // turn minimum width into exact width\n' +printf '\t];\n' + +# +# Print top-level item(s) +# +printf '\n\t/*\n\t * bsdconfig(8)\n\t */\n' +shape=circle color=black fillcolor=yellow style=filled +begin_nodelist "$shape" "$color" "$fillcolor" "$style" +print_node "bsdconfig" "fontname = \"Times-Bold\"" "fontsize = 16" +end_nodelist + +# +# Print menus +# +printf '\n\t/*\n\t * Menu items\n\t */\n' +shape=box color=black fillcolor=lightblue style=filled +begin_nodelist "$shape" "$color" "$fillcolor" "$style" +for menu_program in $menu_program_list; do + print_node "$menu_program" "label = \"${menu_program#*/}\"" +done +end_nodelist + +# +# Print sub-menus +# +printf '\n\t/*\n\t * Sub-menu items\n\t */\n' +shape=box color=black fillcolor=lightblue style=filled +begin_nodelist "$shape" "$color" "$fillcolor" "$style" +for submenu_program in $submenu_program_list; do + print_node "$submenu_program" "label = \"${submenu_program#*/}\"" +done +end_nodelist + +# +# Print menu relationships +# +printf '\n\t/*\n\t * Menu item relationships\n\t */\n' +shape=box color=black fillcolor=lightblue style=filled edge_color=blue +begin_nodelist "$shape" "$color" "$fillcolor" "$style" +print_node edge "penwidth = 5.0" "style = bold" "color = $edge_color" +for menu_program in $menu_program_list; do + print_node2 "bsdconfig" "$menu_program" +done +end_nodelist + +# +# Print sub-menu relationships +# +printf '\n\t/*\n\t * Sub-menu item relationships\n\t */\n' +shape=box color=black fillcolor=lightblue style=filled edge_color=blue +begin_nodelist "$shape" "$color" "$fillcolor" "$style" +# Lock sub-menu headport to the West (unless `-c' was passed) +[ "$SHOW_CMDLINE" -o ! "$SHOW_INCLUDES" ] && print_node edge "headport = w" +print_node edge "style = bold" "color = $edge_color" +for submenu_program in $submenu_program_list; do + for menu_program in $menu_program_list; do + case "$menu_program" in + [0-9][0-9][0-9].*/*) : fall-through ;; + *) continue # Not a menu item + esac + + # Continue if program directories do not match + [ "${menu_program%%/*}" = "${submenu_program%%/*}" ] || + continue + + print_node2 "$menu_program" "$submenu_program" + break + done +done +end_nodelist + +# +# [Optionally] Print include files +# +if [ "$SHOW_INCLUDES" ]; then + printf '\n\t/*\n\t * Include files\n\t */\n' + shape=oval color=black fillcolor=white style=filled + begin_nodelist "$shape" "$color" "$fillcolor" "$style" + printf '\t\tconstraint = false;\n' + for include_file in $include_file_list; do + print_node "$include_file" \ + "label = \"${include_file##*/}\"" + done + end_nodelist +fi + +# +# [Optionally] Print f_include() usage/relationships +# +if [ "$SHOW_INCLUDES" ]; then + printf '\n\t/*\n\t * Include usage\n\t */\n' + shape=oval color=black fillcolor=white style=filled edge_color=grey + begin_nodelist "$shape" "$color" "$fillcolor" "$style" + print_node edge "style = dashed" "color = $edge_color" + #print_node edge "label = \"\\T\"" "fontsize = 9" + # NOTE: Edge labels are buggy on large graphs + file_list=$( + for file in \ + $BSDCONFIG \ + $menu_program_list \ + $submenu_program_list \ + $cmd_program_list \ + $include_file_list \ + ; do + [ -f "$BSDCFG_SHARE/$file" ] && + echo $BSDCFG_SHARE/$file + [ -e "$file" ] && echo $file + done | sort -u + ) + for file in $file_list; do + # Skip binary files and text files that don't use f_include() + grep -qlI f_include $file || continue + + awk \ + -v file="${file#$BSDCFG_SHARE/}" \ + -v bsdconfig="$BSDCONFIG" \ + ' + BEGIN { regex = "^f_include \\$BSDCFG_SHARE/" } + ( $0 ~ regex ) { + sub(regex, "") + if ( file == bsdconfig ) sub(".*/", "", file) + printf "\t\t\"%s\" -> \"%s\";\n", $0, file + } + ' $file + done | sort + end_nodelist +fi + +# +# Print command-line shortcuts +# +if [ "$SHOW_CMDLINE" ]; then + printf '\n\t/*\n\t * Command-line shortcuts\n\t */\n' + shape=parallelogram color=black fillcolor=lightseagreen style=filled + begin_nodelist "$shape" "$color" "$fillcolor" "$style" + for file in */INDEX; do + awk -v item="${file%%/*}" ' + /^menu_selection="/ { + sub(/^.*="/, "") + sub(/\|.*/, "") + printf "\t\t\"bsdconfig %s\"", $0 + printf " [ label = \"%s\" ];\n", $0 + } + ' $file + done + end_nodelist +fi + +# +# Print command-line shortcut relationships +# +if [ "$SHOW_CMDLINE" ]; then + printf '\n\t/*\n\t * Command-line shortcut relationships\n\t */\n' + shape=box color=black fillcolor=lightseagreen style=filled + begin_nodelist "$shape" "$color" "$fillcolor" "$style" + print_node edge "headport = w" "weight = 100.0" + print_node edge "style = bold" "color = $fillcolor" + for file in */INDEX; do + awk -v item="${file%%/*}" \ + -v node_fillcolor="$node_fillcolor" \ + -v edge_color="$edge_color" \ + ' + /^menu_selection="/ { + sub(/^.*="/, "") + sub(/"$/, "") + + if ( ! $0 ) next + + split($0, menusel, "|") + if ( menusel[2] !~ "^/" ) + sub(/^/, item "/", menusel[2]) + + printf "\t\t\"bsdconfig %s\" -> \"%s\";\n", + menusel[1], menusel[2] + } + ' $file + done + end_nodelist +fi + +# +# Print clusters +# +bgcolor_bsdconfig="lightyellow" +bgcolor_includes="gray98" +bgcolor_menuitem="aliceblue" +bgcolor_shortcuts="honeydew" +printf '\n\t/*\n\t * Clusters\n\t */\n' +printf '\tsubgraph "cluster_bsdconfig" {\n' +printf '\t\tbgcolor = "%s";\n' "$bgcolor_bsdconfig" +printf '\t\tlabel = "bsdconfig(8)";\n' +printf '\t\ttooltip = "bsdconfig(8)";\n' +print_node "bsdconfig" +end_nodelist +if [ "$SHOW_INCLUDES" ]; then + for include_file in $include_file_list; do + echo $include_file + done | awk \ + -v bgcolor="$bgcolor_bsdconfig" \ + -v msg_subroutines="$msg_subroutines" \ + ' + BEGIN { created = 0 } + function end_subgraph() { printf "\t};\n" } + ( $0 !~ "/" ) { + if ( ! created ) + { + printf "\tsubgraph \"%s\" {\n", + "cluster_bsdconfig_includes" + printf "\t\tbgcolor = \"%s\";\n", bgcolor + printf "\t\tlabel = \"bsdconfig %s\";\n", + msg_subroutines + created++ + } + printf "\t\t\"%s\";\n", $1 + } + END { created && end_subgraph() } + ' # END-QUOTE + + for include_file in $include_file_list; do + echo $include_file + done | awk -v msg_subroutines="$msg_subroutines" ' + BEGIN { created = 0 } + function end_subgraph() { printf "\t};\n" } + ( $0 ~ "/" ) { + include_dir_tmp = $1 + sub("/[^/]*$", "", include_dir_tmp) + gsub(/[^[:alnum:]_]/, "_", include_dir_tmp) + + if ( created && include_dir != include_dir_tmp ) + { + end_subgraph() + created = 0 + } + + if ( ! created ) + { + include_dir = include_dir_tmp + printf "\tsubgraph \"cluster_%s_includes\" {\n", + include_dir + printf "\t\tbgcolor = \"thistle\";\n" + printf "\t\tlabel = \"%s %s\";\n", include_dir, + msg_subroutines + created++ + } + + printf "\t\t\"%s\";\n", $1 + } + END { created && end_subgraph() }' +fi +for INDEX in */INDEX; do + menu_title= + menu_help= + f_include_lang "$INDEX" + + item="${INDEX%%/*}" + printf '\tsubgraph "cluster_%s" {\n' "$item" + + case "$item" in + [0-9][0-9][0-9].*) bgcolor="$bgcolor_menuitem" ;; + *) bgcolor="$bgcolor_shortcuts" + esac + printf '\t\tbgcolor = "%s";\n' "$bgcolor" + if [ "$menu_title" ]; then + printf '\t\tlabel = "%s\\n\\"%s\\"";\n' "$item" "$menu_title" + else + printf '\t\tlabel = "%s";\n' "$item" + fi + printf '\t\ttooltip = "%s";\n' "${menu_help:-$item}" + + program_list=$( + for program in \ + $menu_program_list \ + $submenu_program_list \ + $cmd_program_list \ + ; do + echo "$program" + done | sort -u + ) + for program in $program_list; do + case "$program" in "$item"/*) + print_node "$program" "label = \"${program#*/}\"" + esac + done + + if [ "$SHOW_INCLUDES" ]; then + item_include_list= + [ -d "$item/include" ] && + item_include_list=$( find "$item/include" -type f ) + item_include_list=$( + for item_include in $item_include_list; do + for include_file in $include_file_list; do + [ "$item_include" = "$include_file" ] || + continue + echo "$item_include"; break + done + done + ) + if [ "$item_include_list" ]; then + printf '\t\tsubgraph "cluster_%s_includes" {\n' "$item" + printf '\t\t\tbgcolor = "%s";\n' "$bgcolor_includes" + printf '\t\t\tlabel = "%s";\n' "$msg_includes" + fi + for item_include in $item_include_list; do + printf '\t\t\t"%s";\n' "$item_include" + done + [ "$item_include_list" ] && printf '\t\t};\n' + fi + + if [ "$SHOW_CMDLINE" ]; then + printf '\t\tsubgraph "cluster_%s_shortcuts" {\n' "$item" + printf '\t\t\tbgcolor = "%s";\n' "$bgcolor_shortcuts" + printf '\t\t\tlabel = "%s";\n' "$msg_shortcuts" + awk '/^menu_selection="/ { + sub(/^.*="/, "") + sub(/\|.*/, "") + printf "\t\t\t\"bsdconfig %s\";\n", $0 + }' "$INDEX" + printf '\t\t};\n' + fi + + end_nodelist +done + +printf '\n}\n' + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/dot/include/Makefile b/bsdconfig/dot/include/Makefile new file mode 100644 index 000000000000..b687b88cf254 --- /dev/null +++ b/bsdconfig/dot/include/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${LIBEXECDIR}/bsdconfig/dot/include +FILES= messages.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/dot/include/Makefile.depend b/bsdconfig/dot/include/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/dot/include/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/dot/include/messages.subr b/bsdconfig/dot/include/messages.subr new file mode 100644 index 000000000000..f1095f7e4995 --- /dev/null +++ b/bsdconfig/dot/include/messages.subr @@ -0,0 +1,31 @@ +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +msg_graph_label_with_command="bsdconfig(8)\\\ndot(1) output generated by \`\`%s''" +msg_graph_label_with_command_and_date="bsdconfig(8)\\\ndot(1) output generated by \`\`%s'' on\\\n%s" +msg_includes="Includes" +msg_shortcuts="Shortcuts" +msg_subroutines="Subroutines" diff --git a/bsdconfig/examples/Makefile b/bsdconfig/examples/Makefile new file mode 100644 index 000000000000..f66c2b19eff7 --- /dev/null +++ b/bsdconfig/examples/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${SHAREDIR}/examples/bsdconfig +FILES= add_some_packages.sh browse_packages_http.sh bsdconfigrc + +.include <bsd.prog.mk> diff --git a/bsdconfig/examples/Makefile.depend b/bsdconfig/examples/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/examples/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/examples/add_some_packages.sh b/bsdconfig/examples/add_some_packages.sh new file mode 100755 index 000000000000..8750908dbb2c --- /dev/null +++ b/bsdconfig/examples/add_some_packages.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# $FreeBSD$ +# +# This sample installs a short list of packages from the main HTTP site. +# +[ "$_SCRIPT_SUBR" ] || . /usr/share/bsdconfig/script.subr || exit 1 +nonInteractive=1 +_httpPath=http://pkg.freebsd.org +mediaSetHTTP +mediaOpen +for package in wget bash rsync; do + packageAdd +done diff --git a/bsdconfig/examples/browse_packages_http.sh b/bsdconfig/examples/browse_packages_http.sh new file mode 100755 index 000000000000..91b928d183bb --- /dev/null +++ b/bsdconfig/examples/browse_packages_http.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# $FreeBSD$ +# +# This sample downloads the package digests.txz and packagesite.txz files from +# HTTP to /tmp (if they don't already exist) and then displays the package +# configuration/management screen using the local files (resulting in faster +# browsing of packages from-start since digests.txz/packagesite.txz can be +# loaded from local media). +# +# NOTE: Packages cannot be installed unless staged to +# /tmp/packages/$PKG_ABI/All +# +[ "$_SCRIPT_SUBR" ] || . /usr/share/bsdconfig/script.subr || exit 1 +nonInteractive=1 +f_musthavepkg_init # Make sure we have a usable pkg(8) with $PKG_ABI +TMPDIR=/tmp +PKGDIR=$TMPDIR/packages/$PKG_ABI +[ -d "$PKGDIR" ] || mkdir -p "$PKGDIR" || exit 1 +for file in digests.txz packagesite.txz; do + [ -s "$PKGDIR/$file" ] && continue + if [ ! "$HTTP_INITIALIZED" ]; then + _httpPath=http://pkg.freebsd.org + mediaSetHTTP + mediaOpen + fi + f_show_info "Downloading %s from\n %s" "$file" "$_httpPath" + f_device_get device_media "/$PKG_ABI/latest/$file" > $PKGDIR/$file || + exit 1 +done +_directoryPath=$TMPDIR +mediaSetDirectory +configPackages diff --git a/bsdconfig/examples/bsdconfigrc b/bsdconfig/examples/bsdconfigrc new file mode 100644 index 000000000000..2e3155fda779 --- /dev/null +++ b/bsdconfig/examples/bsdconfigrc @@ -0,0 +1,42 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# This file allows you to customize the behavior of bsdconfig. +# Copy it to your $HOME/.bsdconfigrc and edit to suit. + +# Debugging aids for development +# +#debug=1 +#debugFile=$HOME/out +#debugFile=+$HOME/out # includes debug to stdout + +# Optionally override functions to be more verbose (like including the date) +# +# f_dprintf() { +# local format="$1"; shift +# printf "$(date):$pgm:$format\n" "$@" >> $HOME/out +# } diff --git a/bsdconfig/include/Makefile b/bsdconfig/include/Makefile new file mode 100644 index 000000000000..913481c856ef --- /dev/null +++ b/bsdconfig/include/Makefile @@ -0,0 +1,7 @@ +# $FreeBSD$ + +FILESDIR= ${LIBEXECDIR}/bsdconfig/include +FILES= bsdconfig.hlp media.hlp messages.subr network_device.hlp \ + options.hlp tcp.hlp usage.hlp + +.include <bsd.prog.mk> diff --git a/bsdconfig/include/Makefile.depend b/bsdconfig/include/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/include/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/include/bsdconfig.hlp b/bsdconfig/include/bsdconfig.hlp new file mode 100644 index 000000000000..b6eeaf3c45a7 --- /dev/null +++ b/bsdconfig/include/bsdconfig.hlp @@ -0,0 +1,12 @@ +This menu allows you to configure your system after the installation +process is complete. At the minimum, you should probably set the root +password and the system time zone. + +For extra goodies like bash, emacs, firefox, etc., you should look at +the Packages item in this menu. + +For setting the timezone after the system is installed, use the 'Time +Zone' item in this menu. + +For more information on the overall general system configuration, see +the /etc/rc.conf and /etc/defaults/rc.conf files. diff --git a/bsdconfig/include/media.hlp b/bsdconfig/include/media.hlp new file mode 100644 index 000000000000..6fd609473810 --- /dev/null +++ b/bsdconfig/include/media.hlp @@ -0,0 +1,54 @@ +You can install from the following types of media: + + CDROM requires one of the following supported CDROM drives: + ATAPI - Any standard ATAPI CDROM drive hooked to + a supported controller (see Hardware Guide). + SCSI - Any standard SCSI CDROM drive hooked to + a supported controller (see Hardware Guide). + + + DOS A DOS primary partition with the required FreeBSD + distribution files copied onto it (e.g. C:\FREEBSD\) + + + UFS Assuming a disk or partition with an existing + FreeBSD file system and distribution set on it, + get the distribution files from there. + + + Floppy Get distribution files from one or more DOS or UFS + formatted floppies. Such floppies are assumed to + contain the appropriate distribution pieces - see + ABOUT.TXT for more information about making floppy + distribution media. + + + FTP Get the distribution files from an anonymous ftp server + (you will be presented with a list). Please note that + you may invoke FTP in "Active"/"Passive" auto-mode, or + via an HTTP proxy. + + By default, ftp(1) will automatically use the best mode + for the server. Using an HTTP proxy is sometimes necessary + for firewalls which block all FTP connections. + + If you chose to enter your own URL in the FTP menu, please + note that all paths are *relative* to the home directory + of the user being logged in as. By default, this is the + user "ftp" (anonymous ftp) but you may change this in the + Options screen. + + + HTTP Direct + Get the distribution files directly from an HTTP server. + + If you chose to enter your own URL in the HTTP Direct menu, + please note that all paths are *relative* to the root + directory of the web server. + + + NFS Get the distribution files from an NFS server somewhere + (make sure that permissions on the server allow this!). + If this install method hangs on you or refuses to work + properly, you may need to set some special options for + your NFS server. See the Options screen for more details. diff --git a/bsdconfig/include/messages.subr b/bsdconfig/include/messages.subr new file mode 100644 index 000000000000..9d910032616d --- /dev/null +++ b/bsdconfig/include/messages.subr @@ -0,0 +1,464 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012-2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +field_password="Password:" +field_username="Username:" +hline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER" +hline_alnum_punc_tab_enter="Use alpha-numeric, punctuation, TAB or ENTER" +hline_arrows_tab_enter="Press arrows, TAB or ENTER" +hline_arrows_tab_punc_enter="Use arrows, TAB, punctuation, ENTER" +hline_choose_help_for_more_information_on_media_types="Choose Help for more information on the various media types" +msg_accept_continue="Accept/Continue" +msg_accessibility_desc="Ports to help disabled users." +msg_adding_package_as_a_dependency_from_media="Adding %s (as a dependency) from %s" +msg_adding_package_from_media="Adding %s from %s" +msg_afterstep_desc="Ports to support the AfterStep window manager." +msg_all="All" +msg_all_desc="All available packages in all categories." +msg_always_try_sudo_when_run_as="Always try sudo(8) when run as %s" +msg_an_unknown_error_occurred="An unknown error occurred" +msg_arabic_desc="Ported software for Arab countries." +msg_archivers_desc="Utilities for archiving and unarchiving data." +msg_armenia="Armenia" +msg_assume_network_is_already_configured="Running multi-user, assume that the network is already configured?" +msg_assume_yes_to_all_non_critical_dialogs="Assume \"Yes\" answers to all non-critical dialogs" +msg_astro_desc="Applications related to astronomy." +msg_attempt_automatic_dhcp_configuration="Attempt automatic DHCP configuration of interfaces" +msg_attempt_ipv6_configuration_of_interfaces="Attempt IPv6 configuration of interfaces" +msg_attempting_to_update_repository_catalogue="Attempting to update repository catalogue from selected media." +msg_audio_desc="Audio utilities - most require a supported sound card." +msg_australia="Australia" +msg_austria="Austria" +msg_back="Back" +msg_becoming_root_via_sudo="Becoming root via sudo(8)..." +msg_benchmarks_desc="Utilities for measuring system performance." +msg_biology_desc="Software related to biology." +msg_bootstrapping_pkg="Bootstrapping pkg(8)..." +msg_brazil="Brazil" +msg_building_package_menus="Building package menu(s)..." +msg_building_package_main_menu="Building package main menu..." +msg_bulgaria="Bulgaria" +msg_cad_desc="Computer Aided Design utilities." +msg_canada="Canada" +msg_cancel="Cancel" +msg_cancel_exit="Cancel/Exit" +msg_cannot_create_permission_denied="%s: cannot create %s: Permission denied" +msg_cannot_edit_wireless_ssid="Cannot edit wireless configuration; no matches for\nSSID \`%s' in wpa_supplicants.conf(5)" +msg_cannot_resolve_hostname="Cannot resolve \`%s'! Are you sure that your\nname server, gateway and network interface are correctly configured?" +msg_cant_find_distribution="Warning: Can't find the \`%s' distribution on this\nFTP server. You may need to visit a different server for\nthe release you are trying to fetch or go to the Options\nmenu and set the release name to explicitly match what's\navailable on %s (or set to \"any\").\n\nWould you like to select another FTP server?" +msg_cant_seem_to_write_out_resolv_conf="Can't seem to write out %s. Net cannot be used." +msg_cant_start_wpa_supplicant="Can't start wpa_supplicant(8). Please create a wlan(4)\ninterface from the \`wlans' option after selecting your\nfavorite wireless adapter (i.e., %s)." +msg_cd_dvd="CD/DVD" +msg_cdrom="CDROM" +msg_checking_access_to="Checking access to\n %s" +msg_china="China" +msg_chinese_desc="Ported software for the Chinese market." +msg_choose_a_cd_dvd_type="Choose a CD/DVD type" +msg_choose_a_dos_partition="Choose a DOS partition" +msg_choose_a_floppy_drive="Choose a Floppy drive" +msg_choose_a_ufs_partition="Choose a UFS partition" +msg_choose_a_usb_drive="Choose a USB drive" +msg_choose_installation_media="Choose Installation Media" +msg_choose_installation_media_description="FreeBSD can be installed from a variety of different installation\nmedia, ranging from floppies to an Internet FTP server. If you're\ninstalling FreeBSD from a supported CD/DVD drive then this is generally\nthe best media to use if you have no overriding reason for using other\nmedia." +msg_client_error="Client error, you could try an other server" +msg_command_failed_rest_of_script_aborted="Command \`%s' failed - rest of script aborted." +msg_comms_desc="Communications utilities." +msg_configuration_for_interface="Configuration for Interface" +msg_configured="Configured" +msg_configured_lc="configured" +msg_configured_ssids="Configured SSIDs" +msg_converters_desc="Format conversion utilities." +msg_could_not_unmount_the_cdrom_dvd="Could not unmount the CDROM/DVD from %s: %s" +msg_could_not_unmount_the_dos_partition="Could not unmount the DOS partition from %s: %s" +msg_could_not_unmount_the_nfs_partition="Could not unmount the NFS partition from %s: %s" +msg_could_not_unmount_the_ufs_partition="Could not unmount the UFS partition from %s: %s" +msg_couldnt_connect_to_ftp_server="Couldn't connect to FTP server" +msg_couldnt_connect_to_proxy="Couldn't connect to proxy" +msg_couldnt_connect_to_server="Couldn't connect to server" +msg_couldnt_open_ftp_connection="Couldn't open FTP connection to %s:\n %s." +msg_create_new="Create New" +msg_created_path="Created %s" +msg_czech_republic="Czech Republic" +msg_databases_desc="Database software." +msg_debugging="Debugging" +msg_denmark="Denmark" +msg_deskutils_desc="Various Desktop utilities." +msg_destroy="Destroy" +msg_details="Details" +msg_devel_desc="Software development utilities and libraries." +msg_device_is_not_configured="The %s device is not configured. You will need to do so\nin the Networking configuration menu before proceeding." +msg_dhcp="DHCP" +msg_dialog_mixedform_navigation_help="Use <up>/<down> arrows to navigate between fields, TAB to focus buttons, and Enter for OK/Cancel." +msg_directory="Directory" +msg_directory_not_found="%s: Directory not found." +msg_directory_where_package_temporary_files_go="The directory where package temporary files should go" +msg_discovered_ssids="Discovered SSIDs" +msg_dns_desc="Domain Name Service tools." +msg_docs_desc="Meta-ports for FreeBSD documentation." +msg_done="Done" +msg_dos="DOS" +msg_editor="Editor" +msg_editors_desc="Editors." +msg_elisp_desc="Things related to Emacs Lisp." +msg_emit_extra_debugging_output="Emit extra debugging output" +msg_emulators_desc="Utilities for emulating other operating systems." +msg_enlightenment_desc="Software for the Enlightenment Desktop Environment." +msg_enter_a_fully_qualified_pathname_for_the_directory="Enter a fully qualified pathname for the directory\ncontaining the FreeBSD distribution files:" +msg_enter_the_device_name_of_a_ufs_formatted_partition="Enter the device-name of a UFS formatted partition" +msg_error="Error" +msg_error_mounting_device="Error mounting %s on %s: %s" +msg_error_mounting_floppy_device="Error mounting floppy %s (%s) on %s: %s" +msg_error_mounting_usb_drive="Error mounting USB drive %s on %s: %s" +msg_error_when_requesting_url="Error when requesting %s, you could try an other server" +msg_estonia="Estonia" +msg_exit="Exit" +msg_exit_bsdconfig="Exit bsdconfig" +msg_extra_options_to_ifconfig="Extra options to ifconfig (usually empty):" +msg_failed_to_add_default_route="Failed to add a default route; please check your network configuration" +msg_failed_to_reach_wpa_supplicant="Failed to reach wpa_supplicant: %s" +msg_file_system="File System" +msg_finance_desc="Monetary, financial and related applications." +msg_finland="Finland" +msg_floppy="Floppy" +msg_forget_all="Forget All" +msg_forget_all_confirm="WARNING! Are you really sure you want to forget all known networks\nby re-initializing wpa_supplicants.conf(5)? This cannot be undone." +msg_forget_all_help="Reset wpa_supplicant(8) configuration, forgetting all known networks" +msg_found="found" +msg_france="France" +msg_french_desc="Ported software for French countries." +msg_ftp="FTP" +msg_ftp_desc="FTP client and server utilities." +msg_ftp_passive="FTP Passive" +msg_ftp_username="FTP username" +msg_generating_index_from_pkg_database="Generating INDEX from pkg(8) database\n(this can take a while)..." +msg_geography_desc="Geography-related software." +msg_german_desc="Ported software for Germanic countries." +msg_germany="Germany" +msg_gnome_desc="Components of the Gnome Desktop environment." +msg_gnustep_desc="Software for GNUstep desktop environment." +msg_graphics_desc="Graphics libraries and utilities." +msg_greece="Greece" +msg_hamradio_desc="Software for amateur radio." +msg_haskell_desc="Software related to the Haskell language." +msg_hebrew_desc="Ported software for Hebrew language." +msg_help="Help" +msg_host_name_including_domain="Host name (including domain)" +msg_hostname_variable_not_set="WARNING: hostname variable not set and is a non-optional\nparameter. Please add this to your installation script\nor set the netInteractive variable (see bsdconfig man page)" +msg_http_direct="HTTP Direct" +msg_http_proxy="HTTP Proxy" +msg_hungarian_desc="Ported software for the Hungarian market." +msg_iceland="Iceland" +msg_install_from_a_dos_partition="Install from a DOS partition" +msg_install_from_a_floppy_disk_set="Install from a floppy disk set" +msg_install_from_a_freebsd_cd_dvd="Install from a FreeBSD CD/DVD" +msg_install_from_a_ufs_partition="Install from a UFS partition" +msg_install_from_a_usb_drive="Install from a USB drive" +msg_install_from_an_ftp_server="Install from an FTP server" +msg_install_from_an_ftp_server_thru_firewall="Install from an FTP server through a firewall" +msg_install_from_an_ftp_server_thru_proxy="Install from an FTP server through an HTTP proxy" +msg_install_from_an_http_server="Install from an HTTP server" +msg_install_from_the_existing_filesystem="Install from the existing filesystem" +msg_install_over_nfs="Install over NFS" +msg_installed="Installed" +msg_installed_desc="Leave package as-is, installed" +msg_installed_lc="installed" +msg_invalid_gateway_ipv4_address_specified="Invalid gateway IPv4 address specified" +msg_invalid_hostname_value="Invalid hostname value" +msg_invalid_ipv4_address="Invalid IPv4 address" +msg_invalid_name_server_ip_address_specified="Invalid name server IP address specified" +msg_invalid_netmask_value="Invalid netmask value" +msg_invalid_nfs_path_specification="Invalid NFS path specification. Must be of the form:\nhost:/full/pathname/to/FreeBSD/distdir" +msg_io_error_while_reading_in_the_package="I/O error while reading in the %s package." +msg_io_or_format_error_on_index_file="I/O or format error on INDEX file.\nPlease verify media (or path to media) and try again." +msg_ipv4_address="IPv4 Address" +msg_ipv4_gateway="IPv4 Gateway" +msg_ipv6="IPv6" +msg_ipv6_desc="IPv6-related software." +msg_ipv6_ready="IPv6 ready" +msg_irc_desc="Internet Relay Chat utilities." +msg_ireland="Ireland" +msg_israel="Israel" +msg_japan="Japan" +msg_japanese_desc="Ported software for the Japanese market." +msg_java_desc="Java language support." +msg_kde_desc="Software for the K Desktop Environment." +msg_kld_desc="Kernel loadable modules." +msg_korea="Korea" +msg_korean_desc="Ported software for the Korean market." +msg_lang_desc="Computer languages." +msg_latvia="Latvia" +msg_length_of_specified_url_is_too_long="Length of specified URL is %u characters. Allowable maximum is %u." +msg_linux_desc="Linux programs that can run under binary compatibility." +msg_lisp_desc="Software related to the Lisp language." +msg_lithuania="Lithuania" +msg_loading_of_dependent_package_failed="Loading of dependent package %s failed" +msg_loading_wireless_menu="Loading Wireless Menu..." +msg_logging_in_to_user_at_host="Logging in to %s@%s.." +msg_looking_for_keymap_files="Looking for keymap files..." +msg_looking_up_host="Looking up host %s" +msg_mail_desc="Electronic mail packages and utilities." +msg_main_menu="Main Menu" +msg_main_site="Main Site" +msg_manually_connect="Manually Connect" +msg_manually_connect_help="Connect to a wireless network that may be unlisted" +msg_math_desc="Mathematical computation software." +msg_mbone_desc="Applications and utilities for the MBONE." +msg_media_timeout="Media Timeout" +msg_media_type="Media Type" +msg_menu_text="If you've already installed FreeBSD, you may use\nthis menu to customize it somewhat to suit your\nparticular configuration. Most importantly, you\ncan use the Packages utility to load extra '3rd\nparty' software not provided in the base\ndistributions." +msg_misc_desc="Miscellaneous utilities." +msg_missing_ftp_host_or_directory="Missing FTP host or directory specification. FTP media not initialized." +msg_multimedia_desc="Multimedia software." +msg_must_be_root_to_execute="%s: must be root to execute" +msg_must_have_pkg_to_execute="%s: must have pkg(8) to execute" +msg_must_specify_a_host_name_of_some_sort="Must specify a host name of some sort!" +msg_name_server="Name server" +msg_net_desc="Networking utilities." +msg_net_device_init_failed="Net device init failed." +msg_net_im_desc="Instant messaging software." +msg_net_mgmt_desc="Network management tools." +msg_net_p2p_desc="Peer to peer network applications." +msg_netherlands="Netherlands" +msg_netmask="Netmask" +msg_network_configuration="Network Configuration" +msg_network_interface_information_required="Network interface information required" +msg_new_zealand="New Zealand" +msg_news_desc="USENET News support software." +msg_next_page="Next page" +msg_nfailed_attempts="%u incorrect password attempts" +msg_nfs="NFS" +msg_nfs_secure="NFS Secure" +msg_nfs_server_talks_only_on_a_secure_port="NFS server talks only on a secure port" +msg_nfs_slow="NFS Slow" +msg_nfs_tcp="NFS TCP" +msg_nfs_version_3="NFS version 3" +msg_no="No" +msg_no_cd_dvd_devices_found="No CD/DVD devices found! Please check that your system's\nconfiguration is correct and that the CD/DVD drive is of a\nsupported type. For more information, consult the hardware\nguide in the Doc menu." +msg_no_description_provided="No description provided" +msg_no_dos_primary_partitions_found="No DOS primary partitions found! This installation method is unavailable" +msg_no_floppy_devices_found="No floppy devices found! Please check that your system's configuration\nis correct. For more information, consult the hardware guide in the Doc\nmenu." +msg_no_gateway_has_been_set="No gateway has been set. You will be unable to access hosts\nnot on your local network" +msg_no_network_devices="No network devices available!" +msg_no_package_name_passed_in_package_variable="No package name passed in package variable" +msg_no_packages_were_selected_for_extraction="No packages were selected for extraction." +msg_no_pkg_database_found="No pkg(8) database found!" +msg_no_such_file_or_directory="%s: %s: No such file or directory" +msg_no_usb_devices_found="No USB devices found (try Options/Re-scan Devices)" +msg_no_username="No username provided!" +msg_norway="Norway" +msg_not_a_directory="%s: %s: Not a directory" +msg_not_found="not found" +msg_not_yet_set="not yet set" +msg_ok="OK" +msg_options="Options" +msg_options_editor="Options Editor" +msg_other="other" +msg_package_is_needed_by_other_installed_packages="Warning: Package %s is needed by\n %d other installed package%s." +msg_package_not_installed_cannot_delete="Warning: package %s not installed\n No package can be deleted." +msg_package_temp="Package Temp" +msg_package_was_added_successfully="Package %s was added successfully" +msg_packages="packages" +msg_page_of_npages="(Page %s of %s)" +msg_palm_desc="Software support for the Palm(tm) series." +msg_parallel_desc="Applications dealing with parallelism in computing." +msg_pear_desc="Software related to the Pear PHP framework." +msg_perl5_desc="Utilities/modules for the PERL5 language." +msg_permission_denied="%s: %s: Permission denied" +msg_pick_an_interface_to_destroy="Pick an interface to destroy" +msg_pkg_delete_failed="Warning: pkg-delete(8) of %s failed.\n Run with debugging for details." +msg_pkg_install_apparently_did_not_like_the_package="pkg-install(8) apparently did not like the %s package." +msg_pkg_not_yet_installed_install_now="pkg(8) not yet installed. Install now?" +msg_plan9_desc="Software from the Plan9 operating system." +msg_please_check_the_url_and_try_again="No such directory: %s\nplease check the URL and try again.\n" +msg_please_enter_password="Please enter your password for sudo(8):" +msg_please_enter_the_address_of_the_http_proxy="Please enter the address of the HTTP proxy in this format:\n hostname:port (the ':port' is optional, default is 3128)" +msg_please_enter_the_full_nfs_file_specification="Please enter the full NFS file specification for the remote\nhost and directory containing the FreeBSD distribution files.\nThis should be in the format: hostname:/some/freebsd/dir" +msg_please_enter_the_password_for_this_user="Please enter the password for this user:" +msg_please_enter_the_username_you_wish_to_login_as="Please enter the username you wish to login as:" +msg_please_enter_username_password="Please enter a username and password for sudo(8):" +msg_please_insert_floppy_containing="Please insert floppy containing %s in %s" +msg_please_insert_floppy_in_drive="Please insert floppy in %s" +msg_please_select_a_category_to_display="Please select a category to display." +msg_please_select_a_cd_dvd_drive="FreeBSD can be installed directly from a CD/DVD containing a valid\nFreeBSD distribution. If you are seeing this menu it is because\nmore than one CD/DVD drive was found on your system. Please select\none of the following CD/DVD drives as your installation drive." +msg_please_select_a_floppy_drive="You have more than one floppy drive. Please choose which drive\nyou would like to use." +msg_please_select_a_freebsd_ftp_distribution_site="Please select a FreeBSD FTP distribution site" +msg_please_select_a_freebsd_http_distribution_site="Please select a FreeBSD HTTP distribution site" +msg_please_select_a_usb_drive="You have more than one USB drive. Please choose which drive\nyou would like to use." +msg_please_select_dos_partition="FreeBSD can be installed directly from a DOS partition assuming,\nof course, that you have copied the relevant distributions into\nyour DOS partition before starting this installation. If this is\nnot the case then you should reboot DOS at this time and copy the\ndistributions you wish to install into a \"FREEBSD\" subdirectory\non one of your DOS partitions. Otherwise, please select the DOS\npartition containing the FreeBSD distribution files." +msg_please_select_ethernet_device_to_configure="Please select the ethernet or PLIP device to configure." +msg_please_select_the_site_closest_to_you_or_other="Please select the site closest to you or \"other\" if you'd like to\nspecify a different choice. Also note that not every site listed here\ncarries more than the base distribution kits. Only Primary sites are\nguaranteed to carry the full range of possible distributions." +msg_please_select_ufs_partition="FreeBSD can be installed directly from another FreeBSD partition\nthat is UFS formatted assuming, of course, that you have copied\nthe relevant distributions into said partition before starting\ninstallation." +msg_please_specify_a_temporary_directory="Please specify a temporary directory with lots of free space:" +msg_please_specify_the_name_of_the_text_editor="Please specify the name of the text editor you wish to use:" +msg_please_specify_the_number_of_seconds_to_wait="Please specify the number of seconds to wait for slow media:" +msg_please_specify_the_release_you_wish_to_load="Please specify the release you wish to load or\n\"any\" for a generic release install:" +msg_please_specify_url_of_a_freebsd_distribution="Please specify the URL of a FreeBSD distribution on a\nremote ftp site. This site must accept either anonymous\nftp or you should have set an ftp username and password\nin the Options screen.\n\nA URL looks like this: ftp://<hostname>/<path>\nWhere <path> is relative to the anonymous ftp directory or the\nhome directory of the user being logged in as." +msg_please_specify_url_of_freebsd_http_distribution="Please specify the URL of a FreeBSD distribution on a\nremote http site.\nA URL looks like this: http://<hostname>/<path>" +msg_poland="Poland" +msg_polish_desc="Ported software for the Polish market." +msg_ports_mgmt_desc="Utilities for managing ports and packages." +msg_portuguese_desc="Ported software for the Portuguese market." +msg_previous_page="Previous page" +msg_previous_syntax_errors="%s: Not overwriting \`%s' due to previous syntax errors" +msg_primary="Primary" +msg_print_desc="Utilities for dealing with printing." +msg_probing_devices_please_wait_this_can_take_a_while="Probing devices, please wait (this can take a while)..." +msg_proceed="Proceed" +msg_processing_selection="Processing selection..." +msg_python_desc="Software related to the Python language." +msg_quick_start_how_to_use_this_menu_system="Quick start - How to use this menu system" +msg_reading_package_index_data="Reading package index data" +msg_reinstall="Reinstall" +msg_reinstall_desc="Mark this package for reinstall" +msg_release_name="Release Name" +msg_required_package_not_found="Warning: %s is a required package but was not found." +msg_rerun_bsdconfig_initial_device_probe="Re-run bsdconfig initial device probe" +msg_rescan_wireless="Rescan Wireless" +msg_rescan_wireless_help="Scan for new wireless networks" +msg_rescan_devices="Re-scan Devices" +msg_reset="RESET!" +msg_reset_all_values_to_startup_defaults="Reset all values to startup defaults" +msg_return_to_previous_menu="Return to previous menu" +msg_reuse_old_ftp_site_selection_values="Re-use old FTP site selection values?" +msg_reuse_old_http_site_settings="Re-use old HTTP site settings?" +msg_review="Review" +msg_review_desc="Review/perform pending actions" +msg_review_help="Install, Re-Install, or Un-install selected packages and dependencies" +msg_reviewing_selected_packages="Reviewing %u selected packages:" +msg_ruby_desc="Software related to the Ruby language." +msg_rubygems_desc="Ports of RubyGems packages." +msg_russia="Russia" +msg_russian_desc="Ported software for the Russian market." +msg_scanning_for_dhcp_servers="Scanning for DHCP servers..." +msg_scanning_for_ra_servers="Scanning for RA servers..." +msg_scanning_wireless_pausing="Scanning Wireless... (pausing for %i seconds)" +msg_scheme_desc="Software related to the Scheme language." +msg_science_desc="Scientific software." +msg_secure_mode_requires_root="Secure-mode requires root-access!" +msg_secure_mode_requires_x11="Secure-mode requires X11 (use \`-X')!" +msg_security_desc="System security software." +msg_select="Select" +msg_select_a_site_thats_close="Select a site that's close!" +msg_select_the_configuration_you_would_like="Select the configuration you would like to edit:\nAddional network information displayed in help line." +msg_select_wlan_interfaces_for="Select wlan interfaces for %s:" +msg_selected="selected" +msg_server_error_when_requesting_url="Server error when requesting %s, you could try an other server" +msg_shells_desc="Various shells (tcsh, bash, etc)." +msg_show_all="Show All" +msg_show_all_help="Show wireless networks without an SSID and all BSSIDs" +msg_show_configured="Show Configured" +msg_show_configured_help="Show networks configured in wpa_supplicants.conf(5)" +msg_show_scan_results="Show Scan Results" +msg_show_scan_results_help="Show wpa_cli(8) scan results" +msg_skip="Skip" +msg_slovak_republic="Slovak Republic" +msg_slovenia="Slovenia" +msg_sorry_invalid_url="Sorry, %s is an invalid URL!" +msg_sorry_package_was_not_found_in_the_index="Sorry, package %s was not found in the INDEX." +msg_sorry_try_again="Sorry, try again." +msg_south_africa="South Africa" +msg_spain="Spain" +msg_spanish_desc="Ported software for the Spanish market." +msg_specify_some_other_ftp_site="Specify some other ftp site by URL" +msg_specify_some_other_http_site="Specify some other http site by URL" +msg_sweden="Sweden" +msg_switzerland="Switzerland" +msg_sysutils_desc="Various system utilities." +msg_taiwan="Taiwan" +msg_tcl_desc="TCL and packages that depend on it." +msg_textproc_desc="Text processing/search utilities." +msg_the_current_installation_media_type="The current installation media type." +msg_timeout_value_in_seconds_for_slow_media="Timeout value in seconds for slow media." +msg_tk_desc="Tk and packages that depend on it." +msg_try_dhcp_configuration="Do you want to try DHCP configuration of the interface?" +msg_try_ipv6_configuration="Do you want to try IPv6 configuration of the interface?" +msg_try_sudo_only_this_once="Try sudo(8) only this once" +msg_ufs="UFS" +msg_uk="UK" +msg_ukraine="Ukraine" +msg_ukrainian_desc="Ported software for the Ukrainian market." +msg_unable_to_configure_device="Unable to configure the %s interface!\nThis installation method cannot be used." +msg_unable_to_fetch_package_from_selected_media="Unable to fetch package %s from selected media.\nNo package add will be done." +msg_unable_to_get_file_from_selected_media="Unable to get %s file from selected media.\n\nThis may be because the packages collection is not available\non the distribution media you've chosen, most likely an FTP site\nwithout the packages collection mirrored. Please verify that\nyour media, or your path to the media, is correct and try again." +msg_unable_to_get_proper_ftp_path="Unable to get proper FTP path. FTP media not initialized." +msg_unable_to_initialize_media_type_for_package_extract="Unable to initialize media type for package extract." +msg_unable_to_make_directory_mountpoint="Unable to make %s directory mountpoint for %s!" +msg_unable_to_open="Unable to open %s" +msg_unable_to_update_pkg_from_selected_media="Unable to update pkg(8) from selected media." +msg_unconfigured="Unconfigured" +msg_uninstall="Uninstall" +msg_uninstall_desc="Mark this package for deletion" +msg_uninstalling_package_waiting_for_pkg_delete="Uninstalling %s package - waiting for pkg-delete(8)" +msg_unknown="unknown" +msg_unknown_user="Unknown user: %s" +msg_url_was_not_found="%s was not found,\nmaybe directory or release-version are wrong?" +msg_usa="USA" +msg_usage="Usage" +msg_usb="USB" +msg_use_defaults="Use Defaults" +msg_use_nfs_version_3="Use NFS version 3" +msg_use_tcp_protocol_for_nfs="Use TCP protocol for NFS" +msg_user_disallowed="User disallowed: %s" +msg_user_is_using_a_slow_pc_or_ethernet_card="User is using a slow PC or Ethernet card" +msg_username_and_password_to_use="Username and password to use instead of anonymous" +msg_using_interface="Using interface %s" +msg_using_usb_device="Using USB device: %s" +msg_vietnamese_desc="Ported software for the Vietnamese market." +msg_view_set_various_media_options="View/Set various media options" +msg_warning_no_wireless_devices="WARNING! No wireless devices found." +msg_what_would_you_like_to_do_with="What would you like to do with %s?" +msg_which_release_to_attempt_to_load="Which release to attempt to load from installation media" +msg_which_text_editor_to_use="Which text editor to use during installation" +msg_wireless_networks_text="Select an unmarked ([ ]) entry to join that network.\nSelect a marked ([X]) entry to edit that configuration." +msg_windowmaker_desc="Ports to support the WindowMaker window manager." +msg_wireless_network_configuration_for="Wireless network configuration for SSID \`%s'" +msg_would_you_like_to_bring_interface_up="Would you like to bring the %s interface up right now?" +msg_wpa_cli_ping_failed="wpa_cli(8) ping failed" +msg_www_desc="Web utilities (browsers, HTTP servers, etc)." +msg_x11_clocks_desc="X Window System based clocks." +msg_x11_desc="X Window System based utilities." +msg_x11_drivers_desc="X Window System drivers." +msg_x11_fm_desc="X Window System based file managers." +msg_x11_fonts_desc="X Window System fonts and font utilities." +msg_x11_servers_desc="X Window System servers." +msg_x11_themes_desc="X Window System themes." +msg_x11_toolkits_desc="X Window System based development toolkits." +msg_x11_wm_desc="X Window System window managers." +msg_xfce_desc="Software related to the Xfce Desktop Environment." +msg_yes="Yes" +msg_yes_to_all="Yes to All" +msg_you_are_not_root_but="You are not root but %s can use sudo(8).\nWhat would you like to do?" +msg_you_may_remove_the_floppy="You may remove the floppy from %s" +msg_youve_already_done_the_network_configuration="You've already done the network configuration once,\nwould you like to skip over it now?" +msg_zope_desc="Software related to the Zope platform." +tcplayout_extras_help="Any interface-specific options to ifconfig you would like to add" +tcplayout_extras_help_for_plip="For PLIP configuration, you must enter the peer's IP address here." +tcplayout_gateway_help="IPv4 address of host forwarding packets to non-local destinations" +tcplayout_hostname_help="Your fully-qualified hostname, e.g. foo.example.com" +tcplayout_ipaddr_help="The IPv4 address to be used for this interface" +tcplayout_nameserver_help="IPv4 or IPv6 address of your local DNS server" +tcplayout_netmask_help="The netmask for this interface, e.g. 255.255.255.0 for a class C network" diff --git a/bsdconfig/include/network_device.hlp b/bsdconfig/include/network_device.hlp new file mode 100644 index 000000000000..affa86a91ec8 --- /dev/null +++ b/bsdconfig/include/network_device.hlp @@ -0,0 +1,58 @@ +You can do network installations over 3 types of communications links: + + Serial port: SLIP / PPP + Parallel port: PLIP (laplink cable) + Ethernet: A standard Ethernet controller (includes some + PCMCIA networking cards). + +SLIP support is rather primitive and limited primarily to directly +connected links, such as a serial cable running between a laptop +computer and another PC. The link must be hard-wired as the SLIP +installation doesn't currently offer a dialing capability (that +facility is offered by the PPP utility, which should be used in +preference to SLIP whenever possible). When you choose the SLIP +option, you'll be given the option of later editing the slattach +command before it's run on the serial line. It is expected that +you'll run slattach (or some equivalent command) on the other end of +the link at that time and bring up the line. FreeBSD will then +install itself at serial speeds of up to 115.2K/baud (the recommended +speed for a hardwired cable). + +If you're using a modem then PPP is almost certainly your only choice. +Make sure that you have your service provider's information handy as +you'll need to know it fairly early in the installation process. You +will need to know your service provider's IP address, the IP address +of your provider's DNS server, and possibly your own IP address unless +your ISP supports dynamic negotiation, most do. If you do not choose +a PAP or CHAP login you will also need to know how to use the various +"AT commands" to dial the ISP with your particular brand of modem as +the PPP dialer provides only a very simple terminal emulator and has no +"modem capabilities database". If you choose a PAP or CHAP login you +can simply enter `dial' (without the quotes) at the ppp prompt if your +modem uses the Hayes compatible AT command set. + +If a hard-wired connection to another FreeBSD (2.0R or later) machine +is available, you might also consider installing over a "laplink" +parallel port cable. The data rate over the parallel port is much +higher than what is typically possible over a serial line, and speeds +of over 50KB/sec are not uncommon. + +Finally, for the fastest possible network installation, an Ethernet +adaptor is always a good choice! FreeBSD supports most common PC +Ethernet cards, a table of which is provided in the FreeBSD Hardware +Guide (see the `Documentation' entry in the main menu). If you are +using one of the supported PCMCIA Ethernet cards, also be sure that +it's plugged in BEFORE the laptop is powered on! Sysinstall does not, +unfortunately, currently support "hot insertion" of PCMCIA cards. + +You will also need to know your IP address on the network, the +"netmask" value for your address class, and the name of your machine. +Your system administrator can tell you which values to use for your +particular network setup. If you will be referring to other hosts by +name rather than IP address, you'll also need a name server and +possibly the address of a gateway (if you're using PPP, it's your +provider's IP address) to use in talking to it. If you do not know +the answers to all or most of these questions then you should really +probably talk to your system administrator FIRST before trying this +type of installation! Choosing the wrong IP address on a busy network +will NOT make you popular with your systems administrator! :-) diff --git a/bsdconfig/include/options.hlp b/bsdconfig/include/options.hlp new file mode 100644 index 000000000000..f47df27a6b88 --- /dev/null +++ b/bsdconfig/include/options.hlp @@ -0,0 +1,115 @@ +The following options may be set from this screen. + +NFS Secure: NFS server talks only on a secure port + + This is most commonly used when talking to Sun workstations, which + will not talk NFS over "non privileged" ports. + + +NFS Slow: User is using a slow PC or Ethernet card + + Use this option if you have a slow PC (386) or an Ethernet card + with poor performance being "fed" by NFS on a higher-performance + workstation. This will throttle the workstation back to prevent + the PC from becoming swamped with data. + + +NFS TCP: Use TCP for the NFS mount + + This option can be used if your NFS server supports TCP + connections; not all do! This may be useful if your NFS server + is at a remote site in which case it may offer some additional + stability. + + +NFS version 3: Use NFS version 3 + + This option forces the use of NFS version 3 and is on by default. + If your NFS server only supports NFS version 2, disable this option. + + +Debugging: Turn on the extra debugging flag + + This turns on a lot of extra noise in between dialogs (unless + debugFile has been set, sending the data to a logfile instead). + Optionally, if debugFile begins with a plus sign (`+'), output will + occur both on standard output and to debugFile (minus leading plus). + If your installation should fail for any reason, PLEASE turn this + flag on when attempting to reproduce the problem. It will provide a + lot of extra debugging at the failure point and may be very helpful + to the developers in tracking such problems down! + + +Yes To All: Assume "Yes" answers to all non-critical dialogs + + This flag should be used with caution. It will essentially + decide NOT to ask the user about any "boundary" conditions that + might not constitute actual errors but may be warnings indicative + of other problems. It's most useful to those who are doing unattended + installs. + + +DHCP: Enable DHCP configuration of interfaces + + This option specifies whether DHCP configuration of interfaces + may be attempted. The default setting is to interactively ask + the user. + + +IPv6: Enable IPv6 router solicitation configuration + + This option specifies whether automatic configuration of IPv6 + interfaces may be attempted. This uses the router solicitation + method of automatic configuration. The default setting is to + interactively ask the user. + + +FTP username: Specify username and password instead of anonymous. + + By default, the installation attempts to log in as the + anonymous user. If you wish to log in as someone else, + specify the username and password with this option. + + +Editor: Specify which screen editor to use. + + At various points during the installation it may be necessary + to customize some text file, at which point the user will be + thrown unceremoniously into a screen editor. A relatively + simplistic editor which shows its command set on-screen is + selected by default, but UNIX purists may wish to change this + setting to `/usr/bin/vi'. + + +Release Name: Which release to attempt to load from installation media. + + You should only change this option if you're really sure you know + what you are doing! This will change the release name used by + bsdconfig when fetching components of any distributions, and + is a useful way of using a more recent installation boot floppy + with an older release (say, on CDROM). + + +Media Type: Which media type is being used. + + This is mostly informational and indicates which media type (if any) + was last selected in the Media menu. It's also a convenient short-cut + to the media menu itself. + + +Package Temp: Where package temporary files should go + + Some packages, like emacs, can use a LOT of temporary space - up to + 20 or 30MB. If you are going to configure a small / directory and no + separate /var (and hence a small /var/tmp), then you may wish to set + this to point at another location (say, /usr/tmp). + + +Re-scan Devices: + + Reprobe the system for devices. + + +Use Defaults: Use default values. + + Reset all options back to their default values. diff --git a/bsdconfig/include/tcp.hlp b/bsdconfig/include/tcp.hlp new file mode 100644 index 000000000000..6d0ba10f60f1 --- /dev/null +++ b/bsdconfig/include/tcp.hlp @@ -0,0 +1,33 @@ +This screen allows you to set up your general network parameters +(hostname, domain name, DNS server, etc) as well as the settings for a +given interface (which was selected from the menu before this screen). + +PLIP/SLIP users - please read through to the end of this doc! + +The "options" field is kind of special (read: a hack :-): + +Any valid options to ifconfig can be specified here, so if you need +to do something "special" to get your interface working, then here +is the place to do it. + +If you're running SLIP or PLIP, you also need to use it for specifying +the remote end of the link (simply type the foreign IP address in). +In the specific case where you're running PLIP with a Linux host peer +rather than a FreeBSD one, you also must add the "-link0" flag after the +foreign address. + +If you're dealing with an ethernet adaptor with multiple media +connectors (e.g. AUI, 10BT, 10B2, etc), you can use this field to +specify which one to use. Examples of valid strings include: + + "media 10base5/AUI" - Select the AUI port. + "media 10baseT/UTP" - Select the twisted pair port. + "media 10base2/BNC" - Select the BNC connector. + "media 100baseTX" - Select 100BaseT on a 100/10 dual adaptor. + +If you have a wireless interface and must specify arguments such as a +WEP key here, you may use something like: + + "wepmode on wepkey 0xFEEDFACE" + +When you're done with this form, select OK. diff --git a/bsdconfig/include/usage.hlp b/bsdconfig/include/usage.hlp new file mode 100644 index 000000000000..4412da7ddcb8 --- /dev/null +++ b/bsdconfig/include/usage.hlp @@ -0,0 +1,64 @@ +HOW TO USE THIS SYSTEM +====================== + +[press the PageDown key to go to the next screen when you finish + reading this one] + +The following keys are recognized in most of the dialogs you'll +encounter during this installation: + +KEY ACTION +--- ------ +SPACE Select or toggle the current item. +ENTER Finish with a menu or item. +UP ARROW Move to previous item (or up, in a text display box). +DOWN ARROW Move to next item (or down, in a text display box). +TAB Move to next item or group. +RIGHT ARROW Move to next item or group (same as TAB). +SHIFT-TAB Move to previous item or group. +LEFT ARROW Move to previous item or group (same as SHIFT-TAB). +PAGE UP In text display boxes, scrolls up one page. +PAGE DOWN In text display boxes, scrolls down one page. +F1 Display associated help text. + +If you see small "^(-)" or "v(+)" symbols at the edges of a menu, it +means that there are more items above or below the current one that +aren't being shown (due to insufficient screen space). In text +display boxes, the amount of text above the current point will be +displayed as a percentage in the lower right corner. Using the +Up/Down arrow keys will cause the object to scroll by line. The +PageUp and PageDown keys will scroll by entire screens. + +Selecting OK in a menu will confirm whatever action it's controlling. +Selecting Cancel will cancel the operation and generally return you to +the previous menu. Use TAB to move the cursor around and select the +buttons. + +Most screens offer a Help button - USE IT! It generally offers useful +context-specific hints on what to do and if you're at all unsure about +what to do at a given configuration menu, choose Help! + + +SPECIAL FEATURES: +================= + +It is possible to select a menu item by typing the first character of +its name, if unique. This will generally be an item number. + +The console driver contains a scroll-back buffer for reviewing things +that may have scrolled off the screen. To use scroll-back, press the +"Scroll Lock" key on your keyboard and use the arrow or Page Up/Page +Down keys to move through the saved text. To leave scroll-back mode, +press the Scroll Lock key again. This feature is most useful for +reading back through your boot messages (go ahead, try it now!) though +it's also useful when dealing with sub-shells or other "expert modes" +that don't use menus and tend to scroll their output off the top of +the screen. + +FreeBSD also supports multiple "virtual consoles" which you can use +in order to have several active sessions at once. Use ALT-F<n> to +switch between screens, where `F<n>' is the function key corresponding +to the screen you wish to see. By default, the system comes with 8 +virtual consoles enabled - you can enable more by editing the +/etc/ttys file and turning the "off" field to "on" in the relevant vty +entries (up to 12). diff --git a/bsdconfig/includes/INDEX b/bsdconfig/includes/INDEX new file mode 100644 index 000000000000..a6a6c49212a4 --- /dev/null +++ b/bsdconfig/includes/INDEX @@ -0,0 +1,57 @@ +# Copyright (c) 2013-2015 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# +# Title that will be shown in the bsdconfig menu. +# +menu_title="" + +# +# A short descriptive line shown at the bottom of the bsdconfig menu. keep it +# short because any line longer than the terminal width will be truncated. +# +menu_help="" + +# +# Two-part variable that defines an action to take when `keyword' is passed on +# a bsdconfig command line. Variable takes the form "keyword|command" and +# multiple occurrences of the variable (with different `keyword's, or different +# `keyword's AND `command's) are allowed. If `command' begins with a '/' then +# the full path to the program is needed. If `command' begins with anything +# else it is a path relative to the directory this INDEX file is in. `keyword' +# can be i18n'ed but `command' is the name of a script. +# +menu_selection="includes|includes" +menu_selection="api|includes" + +# +# ------------ Items below this line do NOT need i18n translation ------------ +# +# Name of the program to be run when this menu choice is selected. If it begins +# with a '/' then the full path to the program is needed. If it begins with +# anything else it is a path relative to the directory this INDEX file is in. +# +menu_program="" diff --git a/bsdconfig/includes/Makefile b/bsdconfig/includes/Makefile new file mode 100644 index 000000000000..367776c245a8 --- /dev/null +++ b/bsdconfig/includes/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +SUBDIR= include + +FILESDIR= ${LIBEXECDIR}/bsdconfig/includes +FILES= INDEX USAGE + +SCRIPTSDIR= ${FILESDIR} +SCRIPTS= includes.sh + +.include <bsd.prog.mk> diff --git a/bsdconfig/includes/Makefile.depend b/bsdconfig/includes/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/includes/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/includes/USAGE b/bsdconfig/includes/USAGE new file mode 100644 index 000000000000..4af1b732c718 --- /dev/null +++ b/bsdconfig/includes/USAGE @@ -0,0 +1,71 @@ +# Copyright (c) 2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS] [include ...] + +OPTIONS: + -a Always use color even when output is not to a terminal. + -d Print description for each function selected. Implies `-f'. + -f Show functions for selected includes. + -F pattern + If `-f', only print functions matching pattern. Without `-f' + print only includes containing functions matching pattern. + -h Print this usage statement and exit. + -n Disable the use of color. + +EXAMPLES: + View a list of available includes: + + bsdconfig @PROGRAM_NAME@ + + View functions for all available includes (function names are + highlighted): + + bsdconfig @PROGRAM_NAME@ -f + + View functions with less(1) (function names are not highlighted): + + bsdconfig @PROGRAM_NAME@ -f | less + + View functions with less(1) and color: + + bsdconfig @PROGRAM_NAME@ -af | less -R + + View functions from `common.subr': + + bsdconfig @PROGRAM_NAME@ common.subr + + NB: The `-f' flag is implied when given an include. + + Show only functions containing the word `show' in common.subr: + + bsdconfig @PROGRAM_NAME@ -F show common + + NB: The `.subr' suffix on the end of the include is optional. + + Show descriptions of each of the `show' functions: + + bsdconfig @PROGRAM_NAME@ -dF show diff --git a/bsdconfig/includes/include/Makefile b/bsdconfig/includes/include/Makefile new file mode 100644 index 000000000000..3b8b3ec66f27 --- /dev/null +++ b/bsdconfig/includes/include/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${LIBEXECDIR}/bsdconfig/includes/include +FILES= messages.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/includes/include/Makefile.depend b/bsdconfig/includes/include/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/includes/include/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/includes/include/messages.subr b/bsdconfig/includes/include/messages.subr new file mode 100644 index 000000000000..8fa881b4cf15 --- /dev/null +++ b/bsdconfig/includes/include/messages.subr @@ -0,0 +1,28 @@ +# Copyright (c) 2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +msg_functions_in="Functions in %s:" +msg_functions_in_matching="Functions in %s matching \`%s':" diff --git a/bsdconfig/includes/includes.sh b/bsdconfig/includes/includes.sh new file mode 100755 index 000000000000..6e9906fd0420 --- /dev/null +++ b/bsdconfig/includes/includes.sh @@ -0,0 +1,205 @@ +#!/bin/sh +#- +# Copyright (c) 2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +# Prevent common.subr from auto initializing debugging (this is not an inter- +# active utility that requires debugging; also `-d' has been repurposed). +# +DEBUG_SELF_INITIALIZE=NO + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="includes" +f_include_lang $BSDCFG_LIBE/include/messages.subr +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ GLOBALS + +# +# Options +# +USE_COLOR=1 +SHOW_DESC= +SHOW_FUNCS= +FUNC_PATTERN= + +############################################################ FUNCTIONS + +# show_functions $file +# +# Show the functions in the given include file. +# +show_include() +{ + local file="${1#./}" + + local pattern="${FUNC_PATTERN:-.*}" + output=$( awk \ + -v use_color=${USE_COLOR:-0} \ + -v re="$pattern" \ + -v show_desc=${SHOW_DESC:-0} ' + function _asorti(src, dest) + { + k = nitems = 0; + + # Copy src indices to dest and calculate array length + for (i in src) dest[++nitems] = i + + # Sort the array of indices (dest) using insertion sort method + for (i = 1; i <= nitems; k = i++) + { + idx = dest[i] + while ((k > 0) && (dest[k] > idx)) + { + dest[k+1] = dest[k] + k-- + } + dest[k+1] = idx + } + + return nitems + } + /^$/,/^#/ { + if ($0 ~ /^# f_/) { + if (!match($2, re)) next + fn = $2 + if (use_color) + syntax[fn] = sprintf("+%s[1;31m%s[0m%s\n", + substr($0, 2, RSTART), + substr($0, 2 + RSTART, RLENGTH), + substr($0, 2 + RSTART + RLENGTH)) + else + syntax[fn] = "+" substr($0, 2) "\n" + if (show_desc) + print_more = 1 + else + print_more = substr($0, length($0)) == "\\" + } + if (show_desc && print_more) { + getline + while ($0 ~ /^#/) { + syntax[fn] = syntax[fn] " " substr($0, 2) "\n" + getline + } + print_more = 0 + } else while (print_more) { + getline + syntax[fn] = syntax[fn] " " substr($0, 2) "\n" + print_more = substr($0, length($0)) == "\\" + } + } + END { + n = _asorti(syntax, sorted_indices) + for (i = 1; i <= n; i++) + printf "%s", syntax[sorted_indices[i]] + }' "$file" ) + if [ "$output" ]; then + if [ ! "$SHOW_FUNCS" ]; then + echo "$file" + return $SUCCESS + fi + if [ "$FUNC_PATTERN" ]; then + printf ">>> $msg_functions_in_matching\n" \ + "$file" "$FUNC_PATTERN" + else + printf ">>> $msg_functions_in\n" "$file" + fi + echo "$output" + echo # blank line to simplify awk(1)-based reparse + fi +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# Are we in a terminal? +[ -t 1 ] || USE_COLOR= + +# +# Process command-line arguments +# +while getopts adfF:hn flag; do + case "$flag" in + a) USE_COLOR=1 ;; + d) SHOW_DESC=1 SHOW_FUNCS=1 ;; + f) SHOW_FUNCS=1 ;; + F) FUNC_PATTERN="$OPTARG" ;; + n) USE_COLOR= ;; + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# cd(1) to `share' dir so relative paths work for find and positional args +cd $BSDCFG_SHARE || f_die # Pedantic + +# +# If given an argument, operate on it specifically (implied `-f') and exit +# +[ $# -gt 0 ] && SHOW_FUNCS=1 +for include in "$@"; do + # See if they've just omitted the `*.subr' suffix + [ -f "$include.subr" -a ! -f "$include" ] && include="$include.subr" + if [ ! -f "$include" ]; then + printf "$msg_no_such_file_or_directory\n" "$0" "$include" + exit $FAILURE + elif [ ! -r "$include" ]; then + printf "$msg_permission_denied\n" "$0" "$include" + exit $FAILURE + fi + show_include "$include" || f_die +done + +# Exit if we processed some include arguments +[ $# -gt 0 ] && exit $SUCCESS + +# +# Operate an all known include files +# NB: If we get this far, we had no include arguments +# +find -s . -type f -and -iname '*.subr' | while read file; do + if [ "$SHOW_FUNCS" -o "$FUNC_PATTERN" ]; then + show_include "$file" + else + echo "${file#./}" + fi +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/mouse/INDEX b/bsdconfig/mouse/INDEX new file mode 100644 index 000000000000..4a33a792976e --- /dev/null +++ b/bsdconfig/mouse/INDEX @@ -0,0 +1,62 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# +# Title that will be shown in the bsdconfig menu. +# +menu_title="Mouse" + +# +# A short descriptive line shown at the bottom of the bsdconfig menu. keep it +# short because any line longer than the terminal width will be truncated. +# +menu_help="Configure the Mouse" + +# +# Two-part variable that defines an action to take when `keyword' is passed on +# a bsdconfig command line. Variable takes the form "keyword|command" and +# multiple occurrences of the variable (with different `keyword's, or different +# `keyword's AND `command's) are allowed. If `command' begins with a '/' then +# the full path to the program is needed. If `command' begins with anything +# else it is a path relative to the directory this INDEX file is in. `keyword' +# can be i18n'ed but `command' is the name of a script. +# +menu_selection="mouse|mouse" +menu_selection="mouse_enable|enable" +menu_selection="mouse_type|type" +menu_selection="mouse_port|port" +menu_selection="mouse_flags|flags" +menu_selection="mouse_disable|disable" + +# +# ------------ Items below this line do NOT need i18n translation ------------ +# +# Name of the program to be run when this menu choice is selected. If it begins +# with a '/' then the full path to the program is needed. If it begins with +# anything else it is a path relative to the directory this INDEX file is in. +# +menu_program="mouse" diff --git a/bsdconfig/mouse/Makefile b/bsdconfig/mouse/Makefile new file mode 100644 index 000000000000..97fa52b60520 --- /dev/null +++ b/bsdconfig/mouse/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +SUBDIR= include + +FILESDIR= ${LIBEXECDIR}/bsdconfig/110.mouse +FILES= INDEX USAGE + +SCRIPTSDIR= ${FILESDIR} +SCRIPTS= disable enable flags mouse port type + +.include <bsd.prog.mk> diff --git a/bsdconfig/mouse/Makefile.depend b/bsdconfig/mouse/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/mouse/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/mouse/USAGE b/bsdconfig/mouse/USAGE new file mode 100644 index 000000000000..a06d8af24928 --- /dev/null +++ b/bsdconfig/mouse/USAGE @@ -0,0 +1,37 @@ +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS] + +OPTIONS: + -d Provide lots of debugging info on standard-out when running. + -D file Send debugging info to file. If file begins with a plus-sign + debug info is sent to both standard-out and file (minus the + leading plus). + -h Print this usage statement and exit. + -S Secure X11 mode (implies `-X'). As root, always prompt-for + and validate sudo(8) username/password before starting. + -X Use Xdialog(1) in place of dialog(1). diff --git a/bsdconfig/mouse/disable b/bsdconfig/mouse/disable new file mode 100755 index 000000000000..f2c528f2b7bf --- /dev/null +++ b/bsdconfig/mouse/disable @@ -0,0 +1,97 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ CONFIGURATION + +# +# Location of moused(8) pidfile +# +MOUSED_PIDFILE=/var/run/moused.pid + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_mouse_disable" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Stop the mouse daemon +# +if [ -r "$MOUSED_PIDFILE" ]; then + f_eval_catch -dk pid "$0" cat 'cat "%s"' "$MOUSED_PIDFILE" && + f_isinteger "$pid" && + [ $pid -gt 0 ] && + f_eval_catch -d "$0" kill 'kill %s' $pid +fi +f_eval_catch "$0" f_sysrc_set 'f_sysrc_set moused_enable NO' || f_die +f_eval_catch "$0" f_sysrc_set 'f_sysrc_set moused_type NO' || f_die +f_eval_catch "$0" f_sysrc_delete 'f_sysrc_delete moused_port' || f_die +f_eval_catch "$0" f_sysrc_delete 'f_sysrc_delete moused_flags' || f_die + +# +# Message box +# +f_dialog_title "$msg_message" +f_dialog_msgbox "$msg_mouse_daemon_is_disabled" "$hline_press_enter_or_space" + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/mouse/enable b/bsdconfig/mouse/enable new file mode 100755 index 000000000000..9ad6857e139b --- /dev/null +++ b/bsdconfig/mouse/enable @@ -0,0 +1,128 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ CONFIGURATION + +# +# Location of moused(8) pidfile +# +MOUSED_PIDFILE=/var/run/moused.pid + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_mouse_enable" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Get the type, port, and flags +# +type=$( f_sysrc_get moused_type ) +case "$type" in +[Nn][Oo]|"") f_die 1 "$msg_please_select_protocol_and_port_first" ;; +esac +port=$( f_sysrc_get moused_port ) +[ "$port" ] || f_die 1 "$msg_please_select_protocol_and_port_first" +flags=$( f_sysrc_get moused_flags ) + +# +# Start the mouse daemon +# +f_dialog_info "$msg_trying_to_start_the_mouse_daemon" +if [ -r "$MOUSED_PIDFILE" ]; then + f_eval_catch -dk pid "$0" cat 'cat "%s"' "$MOUSED_PIDFILE" && + f_isinteger "$pid" && + [ $pid -gt 0 ] && + f_eval_catch -d "$0" kill 'kill %s' $pid +fi +f_eval_catch -d "$0" vidcontrol 'vidcontrol -m on' +f_eval_catch -d "$0" moused \ + 'moused -t "%s" -p "%s" %s' "$type" "$port" "$flags" + +# +# Confirm with the user that the mouse is working +# +f_dialog_title "$msg_user_confirmation_requested" +f_dialog_yesno "$msg_now_move_the_mouse" +retval=$? +f_dialog_title_restore + +# +# Stop the mouse daemon +# +f_eval_catch -d "$0" vidcontrol 'vidcontrol -m off' +if [ $retval -eq $DIALOG_OK ]; then + f_eval_catch "$0" f_sysrc_set 'f_sysrc_set moused_enable YES' || f_die + f_eval_catch "$0" ln \ + 'ln -fs /dev/sysmouse /dev/mouse' || f_die # backwards compat +else + if [ -r "$MOUSED_PIDFILE" ]; then + f_eval_catch -dk pid "$0" cat 'cat "%s"' "$MOUSED_PIDFILE" && + f_isinteger "$pid" && + [ $pid -gt 0 ] && + f_eval_catch -d "$0" kill 'kill %s' $pid + fi + f_eval_catch "$0" f_sysrc_set 'f_sysrc_set moused_enable NO' || f_die +fi + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/mouse/flags b/bsdconfig/mouse/flags new file mode 100755 index 000000000000..181ee3f41c57 --- /dev/null +++ b/bsdconfig/mouse/flags @@ -0,0 +1,95 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ CONFIGURATION + +# +# Location of moused(8) pidfile +# +MOUSED_PIDFILE=/var/run/moused.pid + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_mouse_flags" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Get the current flags +# +flags=$( f_sysrc_get moused_flags ) + +# +# Prompt the user with the current value +# +f_dialog_title "$msg_value_required" +f_dialog_input flags "$msg_please_specify_the_mouse_daemon_flags" \ + "$flags" || f_die +f_dialog_title_restore + +# +# Save the new value +# +f_eval_catch "$0" f_sysrc_set 'f_sysrc_set moused_flags "%s"' "$flags" || f_die + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/mouse/include/Makefile b/bsdconfig/mouse/include/Makefile new file mode 100644 index 000000000000..2cc852f9ac67 --- /dev/null +++ b/bsdconfig/mouse/include/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${LIBEXECDIR}/bsdconfig/110.mouse/include +FILES= messages.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/mouse/include/Makefile.depend b/bsdconfig/mouse/include/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/mouse/include/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/mouse/include/messages.subr b/bsdconfig/mouse/include/messages.subr new file mode 100644 index 000000000000..2699b9a5471c --- /dev/null +++ b/bsdconfig/mouse/include/messages.subr @@ -0,0 +1,91 @@ +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +hline_press_enter_or_space="Press enter or space" +msg_auto="Auto" +msg_auto_desc="Bus mouse, PS/2 style mouse or PnP serial mouse" +msg_cancel="Cancel" +msg_com1="COM1" +msg_com1_desc="Serial mouse on COM1 (/dev/cuau0)" +msg_com2="COM2" +msg_com2_desc="Serial mouse on COM2 (/dev/cuau1)" +msg_com3="COM3" +msg_com3_desc="Serial mouse on COM3 (/dev/cuau2)" +msg_com4="COM4" +msg_com4_desc="Serial mouse on COM4 (/dev/cuau3)" +msg_disable="Disable" +msg_disable_the_mouse_daemon="Disable the mouse daemon" +msg_enable="Enable" +msg_exit="Exit" +msg_exit_this_menu="Exit this menu" +msg_flags="Flags" +msg_glidepoint="GlidePoint" +msg_glidepoint_desc="ALPS GlidePoint pad (serial)" +msg_hitachi="Hitachi" +msg_hitachi_desc="Hitachi tablet (serial)" +msg_intellimouse="IntelliMouse" +msg_intellimouse_desc="Microsoft IntelliMouse (serial)" +msg_logitech="Logitech" +msg_logitech_desc="Logitech protocol (old models) (serial)" +msg_menu_text="You can cut and paste text in the text console by running the mouse\ndaemon. Specify a port and a protocol type of your mouse and enable\nthe mouse daemon. If you don't want this feature, select 6 to disable\nthe daemon.\nOnce you've enabled the mouse daemon, you can specify \"/dev/sysmouse\"\nas your mouse device and \"SysMouse\" or \"MouseSystems\" as mouse\nprotocol when running the X configuration utility (see Configuration\nmenu)." +msg_message="Message" +msg_microsoft="Microsoft" +msg_microsoft_desc="Microsoft protocol (serial)" +msg_mm_series="MM Series" +msg_mm_series_desc="MM Series protocol (serial)" +msg_mouse_daemon_is_disabled="The mouse daemon is disabled." +msg_mouse_disable="Mouse Disable" +msg_mouse_enable="Mouse Enable" +msg_mouse_flags="Mouse Flags" +msg_mouseman="MouseMan" +msg_mouseman_desc="Logitech MouseMan/TrackMan models (serial)" +msg_mousesystems="MouseSystems" +msg_mousesystems_desc="MouseSystems protocol (serial)" +msg_now_move_the_mouse="Now move the mouse and see if it works.\n(Note that buttons don't have any effect for now.)\n\n Is the mouse cursor moving?\n" +msg_ok="OK" +msg_please_configure_your_mouse="Please configure your mouse" +msg_please_select_protocol_and_port_first="Please select a mouse protocol and a port first." +msg_please_specify_the_mouse_daemon_flags="Please specify the mouse daemon flags. If you would like to\nemulate 3 buttons, use -3 here.\n " +msg_port="Port" +msg_port_menu_text="The built-in pointing device of laptop/notebook computers is usually\na PS/2 style device." +msg_protocol_menu_text="If your mouse is attached to the PS/2 mouse port or the bus mouse port,\nyou should always choose \"Auto\", regardless of the model and the brand\nof the mouse. All other protocol types are for serial mice and should\nnot be used with the PS/2 port mouse or the bus mouse. If you have\na serial mouse and are not sure about its protocol, you should also try\n\"Auto\". It may not work for the serial mouse if the mouse does not\nsupport the PnP standard. But, it won't hurt. Many 2-button serial mice\nare compatible with \"Microsoft\" or \"MouseMan\". 3-button serial mice\nmay be compatible with \"MouseSystems\" or \"MouseMan\". If the serial\nmouse has a wheel, it may be compatible with \"IntelliMouse\"." +msg_ps2="PS/2" +msg_ps2_desc="PS/2 style mouse (/dev/psm0)" +msg_select_a_protocol_type_for_your_mouse="Select a protocol type for your mouse" +msg_select_mouse_port="Select mouse port" +msg_select_mouse_protocol_type="Select mouse protocol type" +msg_select_your_mouse_port_from_the_following_menu="Select your mouse port from the following menu" +msg_set_additional_flags="Set additional flags" +msg_test_and_run_the_mouse_daemon="Test and run the mouse daemon" +msg_thinkingmouse="ThinkingMouse" +msg_thinkingmouse_desc="Kensington ThinkingMouse (serial)" +msg_trying_to_start_the_mouse_daemon="Trying to start the mouse daemon..." +msg_type="Type" +msg_unknown_mouse_menu_selection="Unknown mouse menu selection" +msg_unknown_mouse_port_selection="Unknown mouse port selection" +msg_unknown_mouse_protocol_selection="Unknown mouse protocol selection" +msg_user_confirmation_requested="User Confirmation Requested" +msg_value_required="Value Required" diff --git a/bsdconfig/mouse/mouse b/bsdconfig/mouse/mouse new file mode 100755 index 000000000000..0dce574feea2 --- /dev/null +++ b/bsdconfig/mouse/mouse @@ -0,0 +1,144 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_menu_text" + local menu_list=" + 'X $msg_exit' '$msg_exit_this_menu' + '2 $msg_enable' '$msg_test_and_run_the_mouse_daemon' + '3 $msg_type' '$msg_select_mouse_protocol_type' + '4 $msg_port' '$msg_select_mouse_port' + '5 $msg_flags' '$msg_set_additional_flags' + '6 $msg_disable' '$msg_disable_the_mouse_daemon' + " # END-QUOTE + local defaultitem= # Calculated below + local hline= + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_data_sanitize menu_choice + f_dialog_menutag_store "$menu_choice" + f_dialog_default_store "$menu_choice" + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_please_configure_your_mouse" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +while :; do + dialog_menu_main || f_die + f_dialog_menutag_fetch mtag + + command= + case "$mtag" in + "X $msg_exit") break ;; + "2 $msg_enable") command=enable ;; # Test and run the mouse daemon + "3 $msg_type") command=type ;; # Select mouse protocol type + "4 $msg_port") command=port ;; # Select mouse port + "5 $msg_flags") command=flags ;; # Set additional flags + "6 $msg_disable") command=disable ;; # Disable the mouse daemon + esac + + if [ "$command" ]; then + $BSDCFG_LIBE/$APP_DIR/$command ${USE_XDIALOG:+-X} + else + f_die 1 "$msg_unknown_mouse_menu_selection" + fi +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/mouse/port b/bsdconfig/mouse/port new file mode 100755 index 000000000000..92c7ff25ea1f --- /dev/null +++ b/bsdconfig/mouse/port @@ -0,0 +1,150 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_port_menu_text" + local menu_list=" + '1 $msg_ps2' '$msg_ps2_desc' + '2 $msg_com1' '$msg_com1_desc' + '3 $msg_com2' '$msg_com2_desc' + '4 $msg_com3' '$msg_com3_desc' + '5 $msg_com4' '$msg_com4_desc' + " # END-QUOTE + local defaultitem= # Calculated below + local hline= + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + case "$( f_sysrc_get moused_port )" in + /dev/psm0) defaultitem="1 $msg_ps2" ;; + /dev/cuau0) defaultitem="2 $msg_com1" ;; + /dev/cuau1) defaultitem="3 $msg_com2" ;; + /dev/cuau2) defaultitem="4 $msg_com3" ;; + /dev/cuau3) defaultitem="5 $msg_com4" ;; + esac + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_menutag_store -s "$menu_choice" + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_select_your_mouse_port_from_the_following_menu" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +dialog_menu_main || f_die +f_dialog_menutag_fetch mtag + +moused_port_to_set= +case "$mtag" in +"1 $msg_ps2") # PS/2 style mouse (/dev/psm0) + moused_port_to_set="/dev/psm0" ;; +"2 $msg_com1") # Serial mouse on COM1 (/dev/cuau0) + moused_port_to_set="/dev/cuau0" ;; +"3 $msg_com2") # Serial mouse on COM2 (/dev/cuau1) + moused_port_to_set="/dev/cuau1" ;; +"4 $msg_com3") # Serial mouse on COM3 (/dev/cuau2) + moused_port_to_set="/dev/cuau2" ;; +"5 $msg_com4") # Serial mouse on COM4 (/dev/cuau3) + moused_port_to_set="/dev/cuau3" ;; +esac + +if [ "$moused_port_to_set" ]; then + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set moused_port "%s"' "$moused_port_to_set" || f_die +else + f_die 1 "$msg_unknown_mouse_port_selection" +fi + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/mouse/type b/bsdconfig/mouse/type new file mode 100755 index 000000000000..7d99753a62be --- /dev/null +++ b/bsdconfig/mouse/type @@ -0,0 +1,170 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_protocol_menu_text" + local menu_list=" + '1 $msg_auto' '$msg_auto_desc' + '2 $msg_glidepoint' '$msg_glidepoint_desc' + '3 $msg_hitachi' '$msg_hitachi_desc' + '4 $msg_intellimouse' '$msg_intellimouse_desc' + '5 $msg_logitech' '$msg_logitech_desc' + '6 $msg_microsoft' '$msg_microsoft_desc' + '7 $msg_mm_series' '$msg_mm_series_desc' + '8 $msg_mouseman' '$msg_mouseman_desc' + '9 $msg_mousesystems' '$msg_mousesystems_desc' + 'A $msg_thinkingmouse' '$msg_thinkingmouse_desc' + " # END-QUOTE + local defaultitem= # Calculated below + local hline= + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + case "$( f_sysrc_get moused_type )" in + auto) defaultitem="1 $msg_auto" ;; + glidepoint) defaultitem="2 $msg_glidepoint" ;; + mmhittab) defaultitem="3 $msg_hitachi" ;; + intellimouse) defaultitem="4 $msg_intellimouse" ;; + logitech) defaultitem="5 $msg_logitech" ;; + microsoft) defaultitem="6 $msg_microsoft" ;; + mmseries) defaultitem="7 $msg_mm_series" ;; + mouseman) defaultitem="8 $msg_mouseman" ;; + mousesystems) defaultitem="9 $msg_mousesystems" ;; + thinkingmouse) defaultitem="A $msg_thinkingmouse" ;; + esac + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_menutag_store -s "$menu_choice" + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_select_a_protocol_type_for_your_mouse" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +dialog_menu_main || f_die +f_dialog_menutag_fetch mtag + +moused_type_to_set= +case "$mtag" in +"1 $msg_auto") # Bus mouse, PS/2 style mouse or PnP serial mouse + moused_type_to_set="auto" ;; +"2 $msg_glidepoint") # ALPS GlidePoint pad (serial) + moused_type_to_set="glidepoint" ;; +"3 $msg_hitachi") # Hitachi tablet (serial) + moused_type_to_set="mmhittab" ;; +"4 $msg_intellimouse") # Microsoft Intellimouse (serial) + moused_type_to_set="intellimouse" ;; +"5 $msg_logitech") # Logitech protocol (old models) (serial) + moused_type_to_set="logitech" ;; +"6 $msg_microsoft") # Microsoft protocol (serial) + moused_type_to_set="microsoft" ;; +"7 $msg_mm_series") # MM Series protocol (serial) + moused_type_to_set="mmseries" ;; +"8 $msg_mouseman") # Logitech MouseMan/TrackMan models (serial) + moused_type_to_set="mouseman" ;; +"9 $msg_mousesystems") # MouseSystems protocol (serial) + moused_type_to_set="mousesystems" ;; +"A $msg_thinkingmouse") # Kensignton ThinkingMouse (serial) + moused_type_to_set="thinkingmouse" ;; +esac + +if [ "$moused_type_to_set" ]; then + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set moused_type "%s"' "$moused_type_to_set" || f_die +else + f_die 1 "$msg_unknown_mouse_protocol_selection" +fi + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/networking/INDEX b/bsdconfig/networking/INDEX new file mode 100644 index 000000000000..d05d4948606e --- /dev/null +++ b/bsdconfig/networking/INDEX @@ -0,0 +1,64 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012-2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# +# Title that will be shown in the bsdconfig menu. +# +menu_title="Networking Management" + +# +# A short descriptive line shown at the bottom of the bsdconfig menu. keep it +# short because any line longer than the terminal width will be truncated. +# +menu_help="Setup Networking interfaces, services, etc." + +# +# Two-part variable that defines an action to take when `keyword' is passed on +# a bsdconfig command line. Variable takes the form "keyword|command" and +# multiple occurrences of the variable (with different `keyword's, or different +# `keyword's AND `command's) are allowed. If `command' begins with a '/' then +# the full path to the program is needed. If `command' begins with anything +# else it is a path relative to the directory this INDEX file is in. `keyword' +# can be i18n'ed but `command' is the name of a script. +# +menu_selection="networking|networking" +menu_selection="defaultrouter|defaultrouter" +menu_selection="hostname|hostname" +menu_selection="nameservers|nameservers" +menu_selection="netdev|devices" +menu_selection="wireless|wlanconfig" +menu_selection="wlan|wlanconfig" +menu_selection="wifi|wlanconfig" + +# +# ------------ Items below this line do NOT need i18n translation ------------ +# +# Name of the program to be run when this menu choice is selected. If it begins +# with a '/' then the full path to the program is needed. If it begins with +# anything else it is a path relative to the directory this INDEX file is in. +# +menu_program="networking" diff --git a/bsdconfig/networking/Makefile b/bsdconfig/networking/Makefile new file mode 100644 index 000000000000..6a1eedda8a9f --- /dev/null +++ b/bsdconfig/networking/Makefile @@ -0,0 +1,12 @@ +# $FreeBSD$ + +SUBDIR= include share + +FILESDIR= ${LIBEXECDIR}/bsdconfig/120.networking +FILES= INDEX USAGE + +SCRIPTSDIR= ${FILESDIR} +SCRIPTS= defaultrouter devices hostname nameservers networking \ + wlanconfig + +.include <bsd.prog.mk> diff --git a/bsdconfig/networking/Makefile.depend b/bsdconfig/networking/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/networking/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/networking/USAGE b/bsdconfig/networking/USAGE new file mode 100644 index 000000000000..872094666bb0 --- /dev/null +++ b/bsdconfig/networking/USAGE @@ -0,0 +1,37 @@ +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS] + +OPTIONS: + -d Provide lots of debugging info on standard-out when running. + -D file Send debugging info to file. If file begins with a plus-sign + debug info is sent to both standard-out and file (minus the + leading plus). + -h Print this usage statement and exit. + -S Secure X11 mode (implies `-X'). As root, always prompt-for + and validate sudo(8) username/password before starting. + -X Use Xdialog(1) in place of dialog(1). diff --git a/bsdconfig/networking/defaultrouter b/bsdconfig/networking/defaultrouter new file mode 100755 index 000000000000..b65981f604f2 --- /dev/null +++ b/bsdconfig/networking/defaultrouter @@ -0,0 +1,76 @@ +#!/bin/sh +#- +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +# Prevent device.subr (included indirectly) from auto scanning on load +DEVICE_SELF_SCAN_ALL=NO + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_default_router" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Change the default router/gateway +# +f_dialog_input_defaultrouter + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/networking/devices b/bsdconfig/networking/devices new file mode 100755 index 000000000000..433f25c75fa0 --- /dev/null +++ b/bsdconfig/networking/devices @@ -0,0 +1,164 @@ +#!/bin/sh +#- +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +# Prevent device.subr (included indirectly) from auto scanning; this will be +# performed indirectly later via f_dialog_menu_netdev() -- but only after we've +# successfully completed f_mustberoot_init(). +# +DEVICE_SELF_SCAN_ALL=NO + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +f_include $BSDCFG_SHARE/sysrc.subr +f_include $BSDCFG_SHARE/media/tcpip.subr +f_include $BSDCFG_SHARE/networking/device.subr +f_include $BSDCFG_SHARE/networking/ipaddr.subr +f_include $BSDCFG_SHARE/networking/media.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line options +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_networking_devices" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +defaultitem= +while :; do + f_dialog_menu_netdev "$defaultitem" || break + f_dialog_menutag_fetch interface + defaultitem="$interface" + + # + # dialog_menu_netdev adds an asterisk (*) to the right of the + # device name if the interface is active. Remove the asterisk + # from the device name if present. + # + case "$interface" in + *\*) interface="${interface%?}" ;; + esac + + # + # Obtain initial interface settings to be configured. These will be + # passed to the f_dialog_menu_netdev_edit function-call below which + # will block until the user has either cancelled or finished editing + # the values. + # + # First, attempt to read stored configuration from rc.conf(5) and + # fallback to reading the active configuration if not configured in + # the rc.conf(5) file(s). + # + dhcp= + _ipaddr= + _netmask= + _ifconfig=$( f_sysrc_get ifconfig_$interface ) + if [ "$_ifconfig" ]; then + # If DHCP, get IP address/netmask later from ifconfig(8) + glob="[Dd][Hh][Cc][Pp]" + case "$_ifconfig" in + $glob) dhcp=1 ;; + [Ss][Yy][Nn][Cc]$glob) dhcp=1 ;; + [Nn][Oo][Ss][Yy][Nn][Cc]$glob) dhcp=1 ;; + *) + # + # Get IP address/netmask from rc.conf(5) configuration + # + dhcp= + eval "$( + exec 2> /dev/null + set -- $_ifconfig + while [ $# -gt 0 ]; do + case "$1" in + inet) + shift 1 + echo "_ipaddr='$1'" + ;; + netmask) + shift 1 + echo "_netmask='$1'" + ;; + esac + shift 1 + done + )" + ;; + esac + fi + + # + # Fill in IP address/netmask from active settings if no + # configuration could be extrapolated from rc.conf(5) + # + [ "$_ipaddr" ] || f_ifconfig_inet $interface _ipaddr + [ "$_netmask" ] || f_ifconfig_netmask $interface _netmask + + # Get the extra options (this always comes from rc.conf(5)) + _options=$( f_ifconfig_options $interface ) + + # Block on user-configuration of the probed settings + f_dialog_menu_netdev_edit \ + "$interface" "$_ipaddr" "$_netmask" "$_options" $dhcp + + # Return to root menu if above returns success + [ $? -eq $DIALOG_OK ] && break +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/networking/hostname b/bsdconfig/networking/hostname new file mode 100755 index 000000000000..d0fff0120eea --- /dev/null +++ b/bsdconfig/networking/hostname @@ -0,0 +1,76 @@ +#!/bin/sh +#- +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +# Prevent device.subr (included indirectly) from auto scanning on load +DEVICE_SELF_SCAN_ALL=NO + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_hostname_domain" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Change the local hostname +# +f_dialog_input_hostname + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/networking/include/Makefile b/bsdconfig/networking/include/Makefile new file mode 100644 index 000000000000..54f66e128407 --- /dev/null +++ b/bsdconfig/networking/include/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${LIBEXECDIR}/bsdconfig/120.networking/include +FILES= messages.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/networking/include/Makefile.depend b/bsdconfig/networking/include/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/networking/include/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/networking/include/messages.subr b/bsdconfig/networking/include/messages.subr new file mode 100644 index 000000000000..55881ffa63f7 --- /dev/null +++ b/bsdconfig/networking/include/messages.subr @@ -0,0 +1,107 @@ +# Copyright (c) 2012-2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +hline_alnum_punc_tab_enter="Use alpha-numeric, punctuation, TAB or ENTER" +hline_arrows_tab_enter="Press arrows, TAB or ENTER" +hline_num_punc_tab_enter="Use numbers, punctuation, TAB or ENTER" +msg_activate_default_router="Would you like to activate the new defaultrouter right now?\nIf you choose NO or press ESC, changes will be applied\nduring the next boot.\n\n Current Default Router: %s\n New Default Router: %s\n" +msg_activate_hostname="Would you like to activate the new hostname right now?\nIf you choose NO or press ESC, changes will be applied\nduring the next boot.\n\n Current Hostname: %s\n New Hostname: %s\n\nNOTE: Your shell prompt may still reflect the original\nhostname until your next login." +msg_activate_hostname_x11warning="WARNING! Activating the new hostname during an X11-Forwarded\n ssh(1) session will cause an X11 authentication error.\n\n Current Hostname: %s\n New Hostname: %s\n\nNOTE: Settings will become active upon reboot or if you\n relaunch this utility either locally or on the console." +msg_add="Add" +msg_add_nameserver="Add a new nameserver" +msg_bring_interface_up="Would you like to bring the %s interface up right now?" +msg_cancel="Cancel" +msg_current_default_router="Current Default Route/Gateway: %s" +msg_current_dhcp_status="Current DHCP status for %s: %s" +msg_current_ipaddr="Current IP Address for %s: %s" +msg_current_options="Current Options for %s: %s" +msg_current_subnet="Current Subnet Mask for %s: %s" +msg_custom="Custom (Manual)" +msg_default_router="Default Router/Gateway" +msg_dhcp="DHCP" +msg_disabled="Disabled" +msg_dns_configuration="DNS Nameserver Configuration:\nChoose Exit when finished else Cancel." +msg_dns_nameservers="DNS nameservers" +msg_enabled="Enabled" +msg_exit="Exit" +msg_hostname_domain="Hostname/Domain" +msg_hostname_exceeds_max_length="ERROR! The hostname entered exceeds the maximum length of\n255 characters.\n\nInvalid Hostname: %s" +msg_hostname_label_contains_invalid_chars="ERROR! One or more individual labels within the hostname\n(separated by dots) contains one or more invalid characters.\nLabels are case-insensitive and must contain only 0-9, a-z,\n or dash (though must not begin with or end with a dash).\n\nInvalid Hostname: %s" +msg_hostname_label_exceeds_max_length="ERROR! One or more individual labels within the hostname\n(separated by dots) exceeds the maximum of 63 characters.\n\nInvalid Hostname: %s" +msg_hostname_label_is_null="ERROR! One or more individual labels within the hostname\n(separated by dots) are null.\n\nInvalid Hostname: %s" +msg_hostname_label_starts_or_ends_with_hyphen="ERROR! One or more individual labels within the hostname\n(separated by dots) starts or ends with a hyphen (hyphens\nare allowed, but a label cannot begin or end with a hyphen).\n\nInvalid Hostname: %s" +msg_internal_error_nsindex_value="FATAL! dialog_input_nameserver_edit_awk: variable\nnsindex must be a whole positive integer greater-\nthan or equal-to zero.\n\nInvalid nsindex: %s" +msg_ipaddr4="ipaddr" +msg_ipv4_addr_octet_contains_invalid_chars="ERROR! One or more individual octets within the IPv4 address\n(separated by dots) contains one or more invalid characters.\nOctets must contain only the characters 0-9.\n\nInvalid IP Address: %s" +msg_ipv4_addr_octet_exceeds_max_value="ERROR! One or more individual octets within the IPv4 address\n(separated by dots) exceeds the maximum of 255.\n\nInvalid IP Address: %s" +msg_ipv4_addr_octet_is_null="ERROR! One or more individual octets within the IPv4 address\n(separated by dots) are null and/or missing.\n\nInvalid IP Address: %s" +msg_ipv4_addr_octet_missing_or_extra="ERROR! The IPv4 address entered has either too few (less than\nfour) or too many (more than four) octets, separated by dots.\n\nInvalid IP Address: %s" +msg_ipv4_mask_field_contains_invalid_chars="ERROR! One or more individual fields within the subnet mask\n(separated by dots) contains one or more invalid characters.\n\nInvalid Subnet Mask: %s" +msg_ipv4_mask_field_exceeds_max_value="ERROR! One or more individual fields within the subnet mask\n(separated by dots) exceeds the maximum of 255.\n\nInvalid Subnet Mask: %s" +msg_ipv4_mask_field_invalid_value="ERROR! One or more individual fields within the subnet mask\n(separated by dots) contains one or more invalid integers.\nFields must be one of 0/128/192/224/240/248/252/254/255.\n\nInvalid Subnet Mask: %s" +msg_ipv4_mask_field_is_null="ERROR! One or more individual fields within the subnet mask\n(separated by dots) are null and/or missing.\n\nInvalid Subnet Mask: %s" +msg_ipv4_mask_field_missing_or_extra="ERROR! The subnet mask entered has either too few or too many\nfields.\n\nInvalid Subnet Mask: %s" +msg_ipv6_addr_segment_contains_invalid_chars="ERROR! One or more individual segments within the IP address\n(separated by colons) contains one or more invalid characters.\nSegments must contain only combinations of the characters 0-9,\nA-F, or a-f.\n\nInvalid IPv6 Address: %s" +msg_ipv6_addr_segment_contains_too_many_chars="ERROR! One or more individual segments within the IP address\n(separated by colons) exceeds the length of 4 hex-digits.\n\nInvalid IPv6 Address: %s" +msg_ipv6_addr_too_few_or_extra_segments="ERROR! The IP address entered has either too few (less than 3), too\nmany (more than 8), or not enough segments, separated by colons.\n\nInvalid IPv6 Address: %s" +msg_ipv6_addr_too_many_null_segments="ERROR! Too many/incorrect null segments. A single null\nsegment is allowed within the IP address (separated by\ncolons) but not allowed at the beginning or end (unless\na double-null segment; i.e., \"::*\" or \"*::\").\n\nInvalid IPv6 Address: %s" +msg_netmask="netmask" +msg_network_configuration="%s Network Configuration:\nChoose Save/Exit when finished or Cancel." +msg_network_interfaces="Network Interfaces" +msg_network_management="Network Management" +msg_networking_devices="Networking Devices" +msg_nfs_mounts_may_cause_hang="WARNING! Changing this setting while NFS directories are\nmounted may cause the system to hang. Are you sure you\nwant to proceed?\n\n%s" +msg_no_network_interfaces="No network interfaces detected." +msg_no_options="No options (Default)" +msg_ok="OK" +msg_options="options" +msg_please_enter_default_router="Please enter the IP address of your default\nrouter/gateway. The address entered will be\napplied as the default gateway for all interfaces\nusing route(4)." +msg_please_enter_fqhn="Please enter your fully qualified hostname (e.g. full.example.com). The\ndomain portion of the hostname will be configured in resolv.conf(5)." +msg_please_enter_mediaopts="Please enter additional network media options to be passed to ifconfig(8) for the %s interface:" +msg_please_enter_nameserver="Please enter the new IP address of the DNS nameserver:" +msg_please_enter_nameserver_existing="Please enter the new IP address of the DNS nameserver\n(set to the NULL string [Ctrl-U] to remove entry):" +msg_please_enter_new_ip_addr="Please enter the new IP address of the %s interface:" +msg_please_enter_subnet_mask="Please enter the new network subnet mask for the %s interface:" +msg_probing_network_interfaces="Probing network interface devices..." +msg_removing_nameserver="Removing DNS nameserver from resolv.conf(5)..." +msg_resolv_conf_changed_while_editing="ERROR! resolv.conf(5) has changed while editing this\nvalue. Please try again after waiting a few seconds." +msg_resolv_conf_entry_no_longer_exists="ERROR! The entry you are trying to edit no longer\nexists in resolv.conf(5). Please try again after\nwaiting a few seconds." +msg_return_to_previous_menu="Return to previous menu" +msg_save_exit="Save/Exit" +msg_saving_default_router="Saving new default router/gateway settings..." +msg_saving_hostname="Saving new hostname/domain settings..." +msg_saving_nameserver="Saving new DNS nameserver to resolv.conf(5)..." +msg_saving_nameserver_existing="Editing DNS nameserver in resolv.conf(5)..." +msg_saving_network_interface="Saving %s network interface settings..." +msg_scanning_for_dhcp="Scanning for DHCP servers on %s interface..." +msg_select_network_interface="Select a network interface to configure.\n\n* Interface is marked as \"active\"" +msg_supported_media_options="Below is a list of supported media options for the %s interface. Please select the options that you would like to set for the %s network interface" +msg_unknown_networking_menu_selection="Unknown networking menu selection" +msg_wireless_networks="Wireless Networks" +msg_wlans="wlans" +xmsg_please_enter_fqhn="Please enter your fully qualified hostname (e.g. foo.bar.com).\n The domain portion of the hostname will be configured in resolv.conf(5)." +xmsg_please_enter_nameserver_existing="Please enter the new IP address of the DNS nameserver\n(set to the NULL string to remove entry):" +xmsg_supported_media_options="Below is a list of supported media options for the %s interface. Please\nselect the options that you would like to set for the %s network interface" diff --git a/bsdconfig/networking/nameservers b/bsdconfig/networking/nameservers new file mode 100755 index 000000000000..e18f00493efb --- /dev/null +++ b/bsdconfig/networking/nameservers @@ -0,0 +1,76 @@ +#!/bin/sh +#- +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +# Prevent device.subr (included indirectly) from auto scanning on load +DEVICE_SELF_SCAN_ALL=NO + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_dns_nameservers" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Change the DNS nameservers +# +f_dialog_menu_nameservers + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/networking/networking b/bsdconfig/networking/networking new file mode 100755 index 000000000000..af37caaf3d6c --- /dev/null +++ b/bsdconfig/networking/networking @@ -0,0 +1,153 @@ +#!/bin/sh +#- +# Copyright (c) 2006-2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt= + local menu_list=" + 'X' '$msg_exit' + '1' '$msg_hostname_domain' + '2' '$msg_network_interfaces' + '3' '$msg_wireless_networks' + '4' '$msg_default_router' + '5' '$msg_dns_nameservers' + " # END-QUOTE + local defaultitem= # Calculated below + local hline="$hline_arrows_tab_enter" + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_data_sanitize menu_choice + f_dialog_menutag_store "$menu_choice" + f_dialog_default_store "$menu_choice" + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_network_management" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +while :; do + dialog_menu_main || f_die + f_dialog_menutag_fetch mtag + + command= + case "$mtag" in + X) break ;; + 1) command=hostname ;; # Hostname/Domain + 2) command=devices ;; # Network Interfaces + 3) command=wlanconfig ;; # Wireless Networks + 4) command=defaultrouter ;; # Default Router/Gateway + 5) command=nameservers ;; # DNS nameservers + esac + + if [ "$command" ]; then + $BSDCFG_LIBE/$APP_DIR/$command ${USE_XDIALOG:+-X} + else + f_die 1 "$msg_unknown_networking_menu_selection" + fi + + if [ "$mtag" = "devices" ]; then + # + # Make subsequent uses of this menu faster by not performing + # "ifconfig up" (limiting the pain one must endure). See also + # `$BSDCFG_SHARE/networking/device.subr'. + # + export DIALOG_MENU_NETDEV_KICK_INTERFACES= + fi +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/networking/share/Makefile b/bsdconfig/networking/share/Makefile new file mode 100644 index 000000000000..6d77f25c5e9e --- /dev/null +++ b/bsdconfig/networking/share/Makefile @@ -0,0 +1,7 @@ +# $FreeBSD$ + +FILESDIR= ${SHAREDIR}/bsdconfig/networking +FILES= common.subr device.subr hostname.subr ipaddr.subr media.subr \ + netmask.subr resolv.subr routing.subr services.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/networking/share/Makefile.depend b/bsdconfig/networking/share/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/networking/share/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/networking/share/common.subr b/bsdconfig/networking/share/common.subr new file mode 100644 index 000000000000..152d1aceb03b --- /dev/null +++ b/bsdconfig/networking/share/common.subr @@ -0,0 +1,58 @@ +if [ ! "$_NETWORKING_COMMON_SUBR" ]; then _NETWORKING_COMMON_SUBR=1 +# +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +############################################################ FUNCTIONS + +# f_jailed +# +# Returns true if the current process is jail(8)ed. +# +f_jailed() +{ + ! f_quietly ps 1 +} + +# f_nfs_mounted +# +# Returns true if there are any NFS mounts currently active, otherwise false. +# +f_nfs_mounted() +{ + [ "$( df -t nfs )" ] +} + +############################################################ MAIN + +f_dprintf "%s: Successfully loaded." networking/common.subr + +fi # ! $_NETWORKING_COMMON_SUBR diff --git a/bsdconfig/networking/share/device.subr b/bsdconfig/networking/share/device.subr new file mode 100644 index 000000000000..41ea29def67c --- /dev/null +++ b/bsdconfig/networking/share/device.subr @@ -0,0 +1,403 @@ +if [ ! "$_NETWORKING_DEVICE_SUBR" ]; then _NETWORKING_DEVICE_SUBR=1 +# +# Copyright (c) 2006-2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." networking/device.subr +f_include $BSDCFG_SHARE/device.subr +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/media/tcpip.subr +f_include $BSDCFG_SHARE/media/wlan.subr +f_include $BSDCFG_SHARE/networking/common.subr +f_include $BSDCFG_SHARE/networking/ipaddr.subr +f_include $BSDCFG_SHARE/networking/media.subr +f_include $BSDCFG_SHARE/networking/netmask.subr +f_include $BSDCFG_SHARE/networking/resolv.subr +f_include $BSDCFG_SHARE/networking/routing.subr +f_include $BSDCFG_SHARE/strings.subr +f_include $BSDCFG_SHARE/sysrc.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +############################################################ GLOBALS + +# +# Settings used while interacting with various dialog(1) menus +# +: ${DIALOG_MENU_NETDEV_KICK_INTERFACES=1} +: ${DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK=3} + +############################################################ FUNCTIONS + +# f_dialog_menu_netdev [$default] +# +# Display a list of network devices with descriptions. Optionally, if present +# and non-NULL, initially highlight $default interface. +# +f_dialog_menu_netdev() +{ + local menu_list # Calculated below + local defaultitem="${1%\*}" # Trim trailing asterisk if present + + # + # Display a message to let the user know we're working... + # (message will remain until we throw up the next dialog) + # + f_dialog_info "$msg_probing_network_interfaces" + + # + # Get list of usable network interfaces + # + local dev devs if iflist= # Calculated below + f_device_rescan_network + f_device_find "" $DEVICE_TYPE_NETWORK devs + for dev in $devs; do + f_struct "$dev" get name if || continue + # Skip unsavory interfaces + case "$if" in + lo[0-9]*|ppp[0-9]*|sl[0-9]*) continue ;; + esac + iflist="$iflist $if" + done + iflist="${iflist# }" + + # + # Optionally kick interfaces in the head to get them to accurately + # track the carrier status in realtime (required on FreeBSD). + # + if [ "$DIALOG_MENU_NETDEV_KICK_INTERFACES" ]; then + DIALOG_MENU_NETDEV_KICK_INTERFACES= + + for if in $iflist; do + f_quietly ifconfig $if up + done + + if [ "$DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK" ]; then + # interfaces need time to update carrier status + sleep $DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK + fi + fi + + # + # Mark any "active" interfaces with an asterisk (*) + # to the right of the device name. + # + menu_list=$( + for if in $iflist; do + f_device_desc $if $DEVICE_TYPE_NETWORK desc + f_shell_escape "$desc" desc + if f_device_is_active $if; then + printf "'%s\*' '%s'\n" $if "$desc" + else + printf "'%s' '%s'\n" $if "$desc" + fi + done + ) + if [ ! "$menu_list" ]; then + f_show_msg "$msg_no_network_interfaces" + return $DIALOG_CANCEL + fi + + # Maybe the default item was marked as active + f_device_is_active "$defaultitem" && defaultitem="$defaultitem*" + + # + # Ask user to select an interface + # + local prompt="$msg_select_network_interface" + local hline="$hline_arrows_tab_enter" + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_menutag_store -s "$menu_choice" + return $retval +} + +# f_dialog_menu_netdev_edit $interface $ipaddr $netmask $options $dhcp +# +# Allow a user to edit network interface settings. Current values are not +# probed but rather taken from the positional arguments. +# +f_dialog_menu_netdev_edit() +{ + local funcname=f_dialog_menu_netdev_edit + local interface="$1" ipaddr="$2" netmask="$3" options="$4" dhcp="$5" + local prompt menu_list height width rows + + # + # Create a duplicate set of variables for change-tracking... + # + local ipaddr_orig="$2" \ + netmask_orig="$3" \ + options_orig="$4" \ + dhcp_orig="$5" + + local hline="$hline_arrows_tab_enter" + f_sprintf prompt "$msg_network_configuration" "$interface" + + # + # Loop forever until the user has finished configuring the different + # components of the network interface. + # + # To apply the settings, we need to know each of the following: + # - IP Address + # - Network subnet mask + # - Additional ifconfig(8) options + # + # It is only when we have all of the above values that we can make the + # changes effective because all three options must be specified at-once + # to ifconfig(8). + # + local defaultitem= + local wlans wlan_status + while :; do + local dhcp_status="$msg_disabled" + [ "$dhcp" ] && dhcp_status="$msg_enabled" + + if f_device_is_wireless "$interface"; then + wlans=$( f_sysrc_get "wlans_$interface" ) + wlan_status="$msg_unconfigured" + [ -e "$( f_sysrc_get wpa_supplicant_conf_file )" ] && + wlan_status="$msg_configured" + fi + + # + # Display configuration-edit menu + # + menu_list=" + 'X $msg_save_exit' '$msg_return_to_previous_menu' + " # END-QUOTE + f_device_is_wireless "$interface" && menu_list="$menu_list + 'W $msg_wireless_networks' '$wlan_status' + '1 $msg_wlans' '$wlans' + " # END-QUOTE + menu_list="$menu_list + '2 $msg_dhcp' '$dhcp_status' + '3 $msg_ipaddr4' '$ipaddr' + '4 $msg_netmask' '$netmask' + '5 $msg_options' '$options' + " # END-QUOTE + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + local tag + tag=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --help-button \ + --help-label \"\$msg_help\" \ + ${USE_XDIALOG:+--help \"\"} \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_data_sanitize tag + + if [ $retval -eq $DIALOG_HELP ]; then + f_show_help "$TCP_HELPFILE" + continue + elif [ $retval -ne $DIALOG_OK ]; then + return $retval + else + # Only update default-item on success + defaultitem="$tag" + fi + + # + # Call the below ``modifier functions'' whose job it is to take + # input from the user and assign the newly-acquired values back + # to the ipaddr, netmask, and options variables for us to re- + # read and display in the summary dialog. + # + case "$tag" in + X\ *) break ;; + W\ *) f_dialog_menu_wireless_edit ;; + 1\ *) f_dialog_menu_wlandev_edit \ + "$interface" "${wlans%%[$IFS]*}" ;; + 2\ *) # + # Proceed cautiously (confirm with the user) if/when NFS- + # mounts are active. If the network on which these mounts + # are made is changed parts of the system may hang. + # + if f_nfs_mounted && ! f_jailed; then + local setting + f_sprintf setting "$msg_current_dhcp_status" \ + "$interface" "$dhcp_status" + f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" || + continue + fi + + # + # Toggle DHCP status + # + if [ "$dhcp_status" = "$msg_enabled" ]; then + dhcp= + else + trap - SIGINT + ( # Execute within sub-shell to allow/catch Ctrl-C + trap 'exit $FAILURE' SIGINT + f_sprintf msg "$msg_scanning_for_dhcp" "$interface" + if [ "$USE_XDIALOG" ]; then + ( + f_quietly ifconfig "$interface" delete + f_quietly dhclient "$interface" + ) | + f_xdialog_info "$msg" + else + f_dialog_info "$msg" + f_quietly ifconfig "$interface" delete + f_quietly dhclient "$interface" + fi + ) + retval=$? + trap 'interrupt' SIGINT + if [ $retval -eq $DIALOG_OK ]; then + dhcp=1 + f_ifconfig_inet "$interface" ipaddr + f_ifconfig_inet6 "$interface" ipaddr6 + f_ifconfig_netmask "$interface" netmask + options= + + # Fixup search/domain in resolv.conf(5) + hostname=$( f_sysrc_get \ + 'hostname:-$(hostname)' ) + f_dialog_resolv_conf_update "$hostname" + fi + fi + ;; + 3\ *) f_dialog_input_ipaddr "$interface" "$ipaddr" + [ $? -eq $DIALOG_OK ] && dhcp= ;; + 4\ *) f_dialog_input_netmask "$interface" "$netmask" + [ $? -eq $DIALOG_OK -a "$_netmask" ] && dhcp= ;; + 5\ *) f_dialog_menu_media_options "$interface" "$options" + [ $? -eq $DIALOG_OK ] && dhcp= ;; + esac + done + + # + # Save only if the user changed at least one feature of the interface + # + if [ "$ipaddr" != "$ipaddr_orig" -o \ + "$netmask" != "$netmask_orig" -o \ + "$options" != "$options_orig" -o \ + "$dhcp" != "$dhcp_orig" ] + then + f_show_info "$msg_saving_network_interface" "$interface" + + local value= + if [ "$dhcp" ]; then + f_eval_catch $funcname f_sysrc_delete \ + 'f_sysrc_delete defaultrouter' + value=DHCP + else + value="inet $ipaddr netmask $netmask" + value="$value${options:+ }$options" + fi + + f_eval_catch $funcname f_sysrc_set \ + 'f_sysrc_set "ifconfig_%s" "%s"' "$interface" "$value" + fi + + # + # Re/Apply the settings if desired + # + if [ ! "$dhcp" ]; then + if f_yesno "$msg_bring_interface_up" "$interface" + then + f_show_info "$msg_bring_interface_up" "$interface" + + local dr="$( f_sysrc_get defaultrouter )" + if [ "$dr" = "NO" -o ! "$dr" ]; then + f_route_get_default dr + [ "$dr" ] && f_eval_catch \ + $funcname f_sysrc_set \ + 'f_sysrc_set defaultrouter "%s"' "$dr" + fi + # + # Make a backup of resolv.conf(5) before using + # ifconfig(8) and then restore it afterward. This + # allows preservation of nameservers acquired via + # DHCP on FreeBSD-8.x (normally lost as ifconfig(8) + # usage causes dhclient(8) to exit which scrubs + # resolv.conf(5) by-default upon termination). + # + f_quietly cp -fp "$RESOLV_CONF" "$RESOLV_CONF.$$" + if f_eval_catch $funcname ifconfig \ + 'ifconfig "%s" inet "%s" netmask "%s" %s' \ + "$interface" "$ipaddr" "$netmask" "$options" + then + [ "$dr" -a "$dr" != "NO" ] && + f_eval_catch $funcname route \ + 'route add default "%s"' "$dr" + fi + if cmp -s "$RESOLV_CONF" "$RESOLV_CONF.$$"; then + f_quietly rm -f "$RESOLV_CONF.$$" + else + f_quietly mv -f "$RESOLV_CONF.$$" "$RESOLV_CONF" + fi + fi + fi + + return $DIALOG_OK +} + +############################################################ MAIN + +f_dprintf "%s: Successfully loaded." networking/device.subr + +fi # ! $_NETWORKING_DEVICE_SUBR diff --git a/bsdconfig/networking/share/hostname.subr b/bsdconfig/networking/share/hostname.subr new file mode 100644 index 000000000000..34bfd6e1d572 --- /dev/null +++ b/bsdconfig/networking/share/hostname.subr @@ -0,0 +1,162 @@ +if [ ! "$_NETWORKING_HOSTNAME_SUBR" ]; then _NETWORKING_HOSTNAME_SUBR=1 +# +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." networking/hostname.subr +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/networking/common.subr +f_include $BSDCFG_SHARE/networking/resolv.subr +f_include $BSDCFG_SHARE/sysrc.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +############################################################ FUNCTIONS + +# f_dialog_hnerror $error $hostname +# +# Display a msgbox with the appropriate error message for an error returned by +# the f_validate_hostname function. +# +f_dialog_hnerror() +{ + local error="$1" fqhn="$2" + + [ ${error:-0} -ne 0 ] || return $SUCCESS + + case "$error" in + 1) f_show_msg "$msg_hostname_label_contains_invalid_chars" "$fqhn" ;; + 2) f_show_msg \ + "$msg_hostname_label_starts_or_ends_with_hyphen" "$fqhn" ;; + 3) f_show_msg "$msg_hostname_label_is_null" "$fqhn" ;; + 63) f_show_msg "$msg_hostname_label_exceeds_max_length" "$fqhn" ;; + 255) f_show_msg "$msg_hostname_exceeds_max_length" "$fqhn" ;; + esac +} + +# f_dialog_validate_hostname $hostname +# +# Returns zero if the given argument (a fully-qualified hostname) is compliant +# with standards set-forth in RFC's 952 and 1123 of the Network Working Group: +# +# RFC 952 - DoD Internet host table specification +# https://tools.ietf.org/html/rfc952 +# +# RFC 1123 - Requirements for Internet Hosts - Application and Support +# https://tools.ietf.org/html/rfc1123 +# +# If the hostname is determined to be invalid, the appropriate error will be +# displayed using the f_dialog_hnerror function above. +# +f_dialog_validate_hostname() +{ + local fqhn="$1" + + f_validate_hostname "$fqhn" + local retval=$? + + # Produce an appropriate error message if necessary. + [ $retval -eq $SUCCESS ] || f_dialog_hnerror $retval "$fqhn" + + return $retval +} + +# f_dialog_input_hostname +# +# Edits the current hostname. +# +f_dialog_input_hostname() +{ + local funcname=f_dialog_input_hostname + local hostname="$( f_sysrc_get 'hostname:-$(hostname)' )" + local hostname_orig="$hostname" # for change-tracking + + local msg + if [ "$USE_XDIALOG" ]; then + msg="$xmsg_please_enter_fqhn" + else + msg="$msg_please_enter_fqhn" + fi + + # + # Loop until the user provides taint-free input. + # + while :; do + f_dialog_input hostname "$msg" "$hostname" \ + "$hline_alnum_punc_tab_enter" || return $? + # Taint-check the user's input + f_dialog_validate_hostname "$hostname" && break + done + + # + # Save hostname only if the user changed the hostname. + # + if [ "$hostname" != "$hostname_orig" ]; then + f_dialog_info "$msg_saving_hostname" + f_eval_catch $funcname f_sysrc_set \ + 'f_sysrc_set hostname "%s"' "$hostname" + fi + + # + # Update resolv.conf(5) search/domain directives + # + f_dialog_resolv_conf_update "$hostname" + + # + # Only ask to apply setting if the current hostname is different than + # the stored configuration (in rc.conf(5)). + # + if [ "$( hostname )" != "$( f_sysrc_get hostname )" ]; then + [ ! "$USE_XDIALOG" ] && f_dialog_clear + + # + # If connected via ssh(1) and performing X11-Forwarding, don't + # allow the hostname to be changed to prevent the fatal error + # "X11 connection rejected because of wrong authentication." + # + if [ "$USE_XDIALOG" -a "$SSH_CONNECTION" ]; then + f_show_msg "$msg_activate_hostname_x11warning" \ + "$( hostname )" "$hostname" + else + f_yesno "$msg_activate_hostname" \ + "$( hostname )" "$hostname" \ + && hostname "$hostname" + fi + fi + + return $DIALOG_OK +} + +############################################################ MAIN + +f_dprintf "%s: Successfully loaded." networking/hostname.subr + +fi # ! $_NETWORKING_HOSTNAME_SUBR diff --git a/bsdconfig/networking/share/ipaddr.subr b/bsdconfig/networking/share/ipaddr.subr new file mode 100644 index 000000000000..b7624cc792d4 --- /dev/null +++ b/bsdconfig/networking/share/ipaddr.subr @@ -0,0 +1,219 @@ +if [ ! "$_NETWORKING_IPADDR_SUBR" ]; then _NETWORKING_IPADDR_SUBR=1 +# +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." networking/ipaddr.subr +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/networking/common.subr +f_include $BSDCFG_SHARE/strings.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +############################################################ FUNCTIONS + +# f_dialog_iperror $error $ipaddr +# +# Display a msgbox with the appropriate error message for an error returned by +# the f_validate_ipaddr function. +# +f_dialog_iperror() +{ + local error="$1" ip="$2" + + [ ${error:-0} -ne 0 ] || return $SUCCESS + + case "$error" in + 1) f_show_msg "$msg_ipv4_addr_octet_contains_invalid_chars" "$ip" ;; + 2) f_show_msg "$msg_ipv4_addr_octet_is_null" "$ip" ;; + 3) f_show_msg "$msg_ipv4_addr_octet_exceeds_max_value" "$ip" ;; + 4) f_show_msg "$msg_ipv4_addr_octet_missing_or_extra" "$ip" ;; + esac +} + +# f_dialog_validate_ipaddr $ipaddr +# +# Returns zero if the given argument (an IP address) is of the proper format. +# +# If the IP address is determined to be invalid, the appropriate error will be +# displayed using the f_dialog_iperror function above. +# +f_dialog_validate_ipaddr() +{ + local ip="$1" + + f_validate_ipaddr "$ip" + local retval=$? + + # Produce an appropriate error message if necessary. + [ $retval -eq $SUCCESS ] || f_dialog_iperror $retval "$ip" + + return $retval +} + +# f_dialog_ip6error $error $ipv6_addr +# +# Display a msgbox with the appropriate error message for an error returned by +# the f_validate_ipaddr6 function above. +# +f_dialog_ip6error() +{ + local error="$1" ip="$2" + + [ ${error:-0} -ne 0 ] || return $SUCCESS + + case "$error" in + 1) f_show_msg "$msg_ipv6_addr_segment_contains_invalid_chars" "$ip" ;; + 2) f_show_msg "$msg_ipv6_addr_too_many_null_segments" "$ip" ;; + 3) f_show_msg "$msg_ipv6_addr_segment_contains_too_many_chars" "$ip" ;; + 4) f_show_msg "$msg_ipv6_addr_too_few_or_extra_segments" "$ip" ;; + *) + if [ $(( $error & 0xF )) -eq 5 ]; then + # IPv4 at the end of IPv6 address is invalid + f_dialog_iperror $(( $error >> 4 )) "$ip" + fi + esac +} + +# f_dialog_validate_ipaddr6 $ipv6_addr +# +# Returns zero if the given argument (an IPv6 address) is of the proper format. +# +# If the IP address is determined to be invalid, the appropriate error will be +# displayed using the f_dialog_ip6error function above. +# +f_dialog_validate_ipaddr6() +{ + local ip="$1" + + f_validate_ipaddr6 "$ip" + local retval=$? + + # Produce an appropriate error message if necessary. + [ $retval -eq $SUCCESS ] || f_dialog_ip6error $retval "$ip" + + return $retval +} + +# f_dialog_input_ipaddr $interface $ipaddr +# +# Allows the user to edit a given IP address. If the user does not cancel or +# press ESC, the $ipaddr environment variable will hold the newly-configured +# value upon return. +# +# Optionally, the user can enter the format "IP_ADDRESS/NBITS" to set the +# netmask at the same time as the IP address. If such a format is entered by +# the user, the $netmask environment variable will hold the newly-configured +# netmask upon return. +# +f_dialog_input_ipaddr() +{ + local interface="$1" _ipaddr="$2" _input + + # + # Return with-error when there are NFS-mounts currently active. If the + # IP address is changed while NFS-exported directories are mounted, the + # system may hang (if any NFS mounts are using that interface). + # + if f_nfs_mounted && ! f_jailed; then + local setting + f_sprintf setting "$msg_current_ipaddr" "$interface" "$_ipaddr" + f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" || + return $DIALOG_CANCEL + fi + + local msg + f_sprintf msg "$msg_please_enter_new_ip_addr" "$interface" + + # + # Loop until the user provides taint-free input. + # + local retval + while :; do + # + # Return error status if: + # - User has either pressed ESC or chosen Cancel/No + # - User has not made any changes to the given value + # + f_dialog_input _input "$msg" "$_ipaddr" \ + "$hline_num_punc_tab_enter" || return $? + [ "$_ipaddr" = "$_input" ] && return $DIALOG_CANCEL + + # Return success if NULL value was entered + [ "$_input" ] || return $DIALOG_OK + + # Take only the first "word" of the user's input + _ipaddr="$_input" + _ipaddr="${_ipaddr%%[$IFS]*}" + + # Taint-check the user's input + f_dialog_validate_ipaddr "${_ipaddr%%/*}" && break + done + + # + # Support the syntax: IP_ADDRESS/NBITS + # + local _netmask="" + case "$_ipaddr" in + */*) + local nbits="${_ipaddr#*/}" n=0 + _ipaddr="${_ipaddr%%/*}" + + # + # Taint-check $nbits to be (a) a positive whole-integer, + # and (b) to be less than or equal to 32. Otherwise, set + # $n so that the below loop never executes. + # + ( f_isinteger "$nbits" && [ $nbits -ge 0 -a $nbits -le 32 ] ) \ + || n=4 + + while [ $n -lt 4 ]; do + _netmask="$_netmask${_netmask:+.}$(( + (65280 >> ($nbits - 8 * $n) & 255) + * ((8*$n) < $nbits & $nbits <= (8*($n+1))) + + 255 * ($nbits > (8*($n+1))) + ))" + n=$(( $n + 1 )) + done + ;; + esac + + ipaddr="$_ipaddr" + [ "$_netmask" ] && netmask="$_netmask" + + return $DIALOG_OK +} + +############################################################ MAIN + +f_dprintf "%s: Successfully loaded." networking/ipaddr.subr + +fi # ! $_NETWORKING_IPADDR_SUBR diff --git a/bsdconfig/networking/share/media.subr b/bsdconfig/networking/share/media.subr new file mode 100644 index 000000000000..028944b5eb6b --- /dev/null +++ b/bsdconfig/networking/share/media.subr @@ -0,0 +1,247 @@ +if [ ! "$_NETWORKING_MEDIA_SUBR" ]; then _NETWORKING_MEDIA_SUBR=1 +# +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." networking/media.subr +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/networking/common.subr +f_include $BSDCFG_SHARE/strings.subr +f_include $BSDCFG_SHARE/sysrc.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +############################################################ FUNCTIONS + +# f_ifconfig_options $interface +# +# Returns any/all extra ifconfig(8) parameters associated with $interface. +# +f_ifconfig_options() +{ + local interface="$1" + [ "$interface" ] || return $SUCCESS + + # + # Loop over the options, removing what we don't want + # + ( + set -- $( f_sysrc_get ifconfig_$interface ) + + # + # Return if the interface is configured for DHCP + # + glob="[Dd][Hh][Cc][Pp]" + case "$*" in + $glob|[Ss][Yy][Nn][Cc]$glob|[Nn][Oo][Ss][Yy][Nn][Cc]$glob) + exit $SUCCESS + esac + + output= + while [ $# -gt 0 ]; do + case "$1" in + inet|netmask) shift 1 ;; + *) output="$output${output:+ }$1" + esac + shift 1 + done + echo "$output" + ) +} + +# f_ifconfig_media $interface +# +# Returns list of supported media for $interface. +# +f_ifconfig_media() +{ + local interface="$1" + ifconfig -m "$interface" 2> /dev/null | awk \ + ' + BEGIN { media_found = 0 } + { + if ( media_found == 1 ) { print; next } + } + ( $1 $2 == "supported" "media:" ) \ + { + media_found = 1 + next + } + END { exit ! media_found } + ' +} + +# f_dialog_input_options $interface +# +# Input custom interface options. If the user does not press ESC or choose +# Cancel/No, $options will hold the user's input. Default input is taken from +# the same variable ($options). +# +f_dialog_input_options() +{ + local interface="$1" + + # + # Return with-error when there are NFS-mounts currently active. If the + # options are changed while NFS-exported directories are mounted, + # the system may hang (if any NFS mounts are using that interface). + # + if f_nfs_mounted && ! f_jailed; then + local setting + f_sprintf setting "$msg_current_options" \ + "$interface" "$options" + f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" || + return $DIALOG_CANCEL + fi + + local msg + f_sprintf msg "$msg_please_enter_mediaopts" "$interface" + local hline="$hline_alnum_punc_tab_enter" + + local _options + _options=$( $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --cancel-label "$msg_cancel" \ + --inputbox "$msg" 9 70 \ + "$options" \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_line_sanitize _options + + [ $retval -eq $DIALOG_OK ] && options="$_options" + + return $retval +} + +# f_dialog_menu_media_options $interface +# +# Display a menu of additional media options for the given network interface. +# +f_dialog_menu_media_options() +{ + local interface="$1" _options="$2" + # + # Not all network interfaces support additional media options, but + # when available we should prompt the user to select from a list + # of available options (or none, as is the first/default option). + # + + # + # Return with-error when there are NFS-mounts currently active. If the + # media options are changed while NFS-exported directories are mounted, + # the system may hang (if any NFS mounts are using that interface). + # + if f_nfs_mounted && ! f_jailed; then + local setting + f_sprintf setting "$msg_current_options" \ + "$interface" "$_options" + f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" || + return $DIALOG_CANCEL + fi + + # + # Build list of additional media options + # + local opt_none="$msg_no_options" + local opt_cust="$msg_custom" + local supported_media="$( + f_ifconfig_media $interface | \ + ( index=1 + + f_substr -v tagn "$DIALOG_MENU_TAGS" $index 1 + echo "'$tagn' '$opt_none'" + index=$(( $index + 1 )) + + f_substr -v tagn "$DIALOG_MENU_TAGS" $index 1 + echo "'$tagn' '$opt_cust'" + index=$(( $index + 1 )) + + while read media_options; do + [ $index -lt ${#DIALOG_MENU_TAGS} ] || break + f_substr -v tagn "$DIALOG_MENU_TAGS" $index 1 + echo "'$tagn' '$media_options'" + index=$(( $index + 1 )) + done + ) + )" + + local msg + if [ "$USE_XDIALOG" ]; then + f_sprintf msg "$xmsg_supported_media_options" \ + "$interface" "$interface" + else + f_sprintf msg "$msg_supported_media_options" \ + "$interface" "$interface" + fi + + local hline="$hline_arrows_tab_enter" + + local tag + tag=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --menu \"\$msg\" 21 60 12 \ + $supported_media \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_data_sanitize tag + + if [ $retval -eq $DIALOG_OK ]; then + options=$( eval f_dialog_menutag2item \"\$tag\" \ + $supported_media ) + case "$options" in + "$opt_none") + options= + ;; + "$opt_cust") + options="$_options" + f_dialog_input_options "$interface" + retval=$? + ;; + esac + fi + + return $retval +} + +############################################################ MAIN + +f_dprintf "%s: Successfully loaded." networking/media.subr + +fi # ! $_NETWORKING_MEDIA_SUBR diff --git a/bsdconfig/networking/share/netmask.subr b/bsdconfig/networking/share/netmask.subr new file mode 100644 index 000000000000..a7d44a55e00a --- /dev/null +++ b/bsdconfig/networking/share/netmask.subr @@ -0,0 +1,137 @@ +if [ ! "$_NETWORKING_NETMASK_SUBR" ]; then _NETWORKING_NETMASK_SUBR=1 +# +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." networking/netmask.subr +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/networking/common.subr +f_include $BSDCFG_SHARE/strings.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +############################################################ FUNCTIONS + +# f_dialog_maskerror $error $netmask +# +# Display a msgbox with the appropriate error message for an error returned by +# the f_validate_netmask function. +# +f_dialog_maskerror() +{ + local error="$1" netmask="$2" + + [ ${error:-0} -ne 0 ] || return $SUCCESS + + case "$error" in + 1) f_show_msg "$msg_ipv4_mask_field_contains_invalid_chars" "$mask" ;; + 2) f_show_msg "$msg_ipv4_mask_field_is_null" "$mask" ;; + 3) f_show_msg "$msg_ipv4_mask_field_exceeds_max_value" "$mask" ;; + 4) f_show_msg "$msg_ipv4_mask_field_missing_or_extra" "$mask" ;; + 5) f_show_msg "$msg_ipv4_mask_field_invalid_value" "$mask" ;; + esac +} + +# f_dialog_validate_netmask $netmask +# +# Returns zero if the given argument (a subnet mask) is of the proper format. +# +# If the subnet mask is determined to be invalid, the appropriate error will be +# displayed using the f_dialog_maskerror function above. +# +f_dialog_validate_netmask() +{ + local netmask="$1" + + f_validate_netmask "$netmask" + local retval=$? + + # Produce an appropriate error message if necessary. + [ $retval -eq $SUCCESS ] || f_dialog_maskerror $retval "$netmask" + + return $retval +} + +# f_dialog_input_netmask $interface $netmask +# +# Edits the IP netmask of the given interface. +# +f_dialog_input_netmask() +{ + local interface="$1" _netmask="$2" _input + + # + # Return with-error when there are NFS-mounts currently active. If the + # subnet mask is changed while NFS-exported directories are mounted, + # the system may hang (if any NFS mounts are using that interface). + # + if f_nfs_mounted && ! f_jailed; then + local setting + f_sprintf setting "$msg_current_subnet" \ + "$interface" "$_netmask" + f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" || + return $DIALOG_CANCEL + fi + + # + # Loop until the user provides taint-free input. + # + local msg + f_sprintf msg "$msg_please_enter_subnet_mask" "$interface" + while :; do + # + # Return error status if: + # - User has either pressed ESC or chosen Cancel/No + # - User has not made any changes to the given value + # + f_dialog_input _input "$msg" "$_netmask" \ + "$hline_num_punc_tab_enter" || return $? + [ "$_netmask" = "$_input" ] && return $DIALOG_CANCEL + + # Return success if NULL value was entered + [ "$_input" ] || return $DIALOG_OK + + # Take only the first "word" of the user's input + _netmask="$_input" + _netmask="${_netmask%%[$IFS]*}" + + # Taint-check the user's input + f_dialog_validate_netmask "$_netmask" && break + done + + netmask="$_netmask" +} + +############################################################ MAIN + +f_dprintf "%s: Successfully loaded." networking/netmask.subr + +fi # ! $_NETWORKING_NETMASK_SUBR diff --git a/bsdconfig/networking/share/resolv.subr b/bsdconfig/networking/share/resolv.subr new file mode 100644 index 000000000000..779863c9981d --- /dev/null +++ b/bsdconfig/networking/share/resolv.subr @@ -0,0 +1,502 @@ +if [ ! "$_NETWORKING_RESOLV_SUBR" ]; then _NETWORKING_RESOLV_SUBR=1 +# +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." networking/resolv.subr +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/media/tcpip.subr +f_include $BSDCFG_SHARE/networking/common.subr +f_include $BSDCFG_SHARE/networking/ipaddr.subr +f_include $BSDCFG_SHARE/strings.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +############################################################ CONFIGURATION + +# +# When updating resolv.conf(5), should we populate the `search' directive with +# all possible sub-domains? In example, if the domain is "sub.domain.com", when +# the below option is set to 1, include both "sub.domain.com" and "domain.com" +# in the `search' directive, otherwise use only "sub.domain.com". +# +# When enabled (set to 1), specify the minimum number of dots required for each +# `search' domain by setting the second option below, `RESOLVER_SEARCH_NDOTS'. +# +: ${RESOLVER_SEARCH_DOMAINS_ALL:=1} +: ${RESOLVER_SEARCH_NDOTS:=1} + +############################################################ FUNCTIONS + +# f_resolv_conf_domain +# +# Returns the domain configured in resolv.conf(5). +# +f_resolv_conf_domain() +{ + tail -r "$RESOLV_CONF" 2> /dev/null | awk \ + ' + BEGIN { found = 0 } + ( tolower($1) == "domain" ) \ + { + print $2 + found = 1 + exit + } + END { exit ! found } + ' +} + +# f_resolv_conf_search +# +# Returns the search configured in resolv.conf(5). +# +f_resolv_conf_search() +{ + tail -r "$RESOLV_CONF" 2> /dev/null | awk \ + ' + BEGIN { found = 0 } + { + tl0 = tolower($0) + if ( match(tl0, /^[[:space:]]*search[[:space:]]+/) ) { + search = substr($0, RLENGTH + 1) + sub(/[[:space:]]*#.*$/, "", search) + gsub(/[[:space:]]+/, " ", search) + print search + found = 1 + exit + } + } + END { exit ! found } + ' +} + +# f_dialog_resolv_conf_update $hostname +# +# Updates the search/domain directives in resolv.conf(5) given a valid fully- +# qualified hostname. +# +# 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_dialog_resolv_conf_update_awk=' +# Variables that should be defined on the invocation line: +# -v domain="domain" +# -v search_all="0|1" +# -v search_ndots="1+" +# +BEGIN { + domain_found = search_found = 0 + + if ( search_all ) { + search = "" + subdomain = domain + if ( search_ndots < 1 ) + search_ndots = 1 + + ndots = split(subdomain, labels, ".") - 1 + while ( ndots-- >= search_ndots ) { + if ( length(search) ) search = search " " + search = search subdomain + sub(/[^.]*\./, "", subdomain) + } + } + else search = domain +} +{ + if ( domain_found && search_found ) { print; next } + + tl0 = tolower($0) + if ( ! domain_found && \ + match(tl0, /^[[:space:]]*domain[[:space:]]+/) ) \ + { + if ( length(domain) ) { + printf "%s%s\n", substr($0, 0, RLENGTH), domain + domain_found = 1 + } + } + else if ( ! search_found && \ + match(tl0, /^[[:space:]]*search[[:space:]]+/) ) \ + { + if ( length(search) ) { + printf "%s%s\n", substr($0, 0, RLENGTH), search + search_found = 1 + } + } + else print +} +END { + if ( ! search_found && length(search) ) + printf "search\t%s\n", search + if ( ! domain_found && length(domain) ) + printf "domain\t%s\n", domain +} +' +f_dialog_resolv_conf_update() +{ + local funcname=f_dialog_resolv_conf_update + local hostname="$1" + + # + # Extrapolate the desired domain search parameter for resolv.conf(5) + # + local search nfields ndots domain="${hostname#*.}" + if [ "$RESOLVER_SEARCH_DOMAINS_ALL" = "1" ]; then + search= + IFS=. f_count_ifs nfields "$domain" + ndots=$(( $nfields - 1 )) + while [ $ndots -ge ${RESOLVER_SEARCH_NDOTS:-1} ]; do + search="$search $domain" + domain="${domain#*.}" + ndots=$(( $ndots - 1 )) + done + search="${search# }" + domain="${hostname#*.}" + else + search="$domain" + fi + + # + # Save domain/search information only if different from resolv.conf(5) + # + if [ "$domain" != "$( f_resolv_conf_domain )" -o \ + "$search" != "$( f_resolv_conf_search )" ] + then + f_dialog_info "Saving new domain/search settings" \ + "to resolv.conf(5)..." + + # + # Create a new temporary file to write our resolv.conf(5) + # update with our new `domain' and `search' directives. + # + local tmpfile + f_eval_catch -dk tmpfile $funcname mktemp \ + 'mktemp -t "%s"' "$tmpfile" || return $DIALOG_CANCEL + + # + # Fixup permissions and ownership (mktemp(1) creates the + # temporary file with 0600 permissions -- change the + # permissions and ownership to match resolv.conf(5) before + # we write it out and mv(1) it into place). + # + local mode owner + f_eval_catch -dk mode $funcname stat \ + 'stat -f "%%#Lp" "%s"' "$RESOLV_CONF" || mode=0644 + f_eval_catch -dk owner $funcname stat \ + 'stat -f "%%u:%%g" "%s"' "$RESOLV_CONF" || + owner="root:wheel" + f_eval_catch -d $funcname chmod \ + 'chmod "%s" "%s"' "$mode" "$tmpfile" + f_eval_catch -d $funcname chown \ + 'chown "%s" "%s"' "$owner" "$tmpfile" + + # + # Operate on resolv.conf(5), replacing only the last + # occurrences of `domain' and `search' directives (or add + # them to the top if not found), in strict-adherence to the + # following entry in resolver(5): + # + # The domain and search keywords are mutually exclusive. + # If more than one instance of these keywords is present, + # the last instance will override. + # + # NOTE: If RESOLVER_SEARCH_DOMAINS_ALL is set to `1' in the + # environment, all sub-domains will be added to the `search' + # directive, not just the FQDN. + # + local domain="${hostname#*.}" new_contents + [ "$domain" = "$hostname" ] && domain= + new_contents=$( tail -r "$RESOLV_CONF" 2> /dev/null ) + new_contents=$( echo "$new_contents" | awk \ + -v domain="$domain" \ + -v search_all="${RESOLVER_SEARCH_DOMAINS_ALL:-1}" \ + -v search_ndots="${RESOLVER_SEARCH_NDOTS:-1}" \ + "$f_dialog_resolv_conf_update_awk" ) + + # + # Write the temporary file contents and move the temporary + # file into place. + # + echo "$new_contents" | tail -r > "$tmpfile" || + return $DIALOG_CANCEL + f_eval_catch -d $funcname mv \ + 'mv "%s" "%s"' "$tmpfile" "$RESOLV_CONF" + + fi +} + +# f_dialog_input_nameserver [ $n $nameserver ] +# +# Allows the user to edit a given nameserver. The first argument is the +# resolv.conf(5) nameserver ``instance'' integer. For example, this will be one +# if editing the first nameserver instance, two if editing the second, three if +# the third, ad nauseum. If this argument is zero, null, or missing, the value +# entered by the user (if non-null) will be added to resolv.conf(5) as a new +# `nameserver' entry. The second argument is the IPv4 address of the nameserver +# to be edited -- this will be displayed as the initial value during the edit. +# +# Taint-checking is performed when editing an existing entry (when the second +# argument is one or higher) in that the first argument must match the current +# value of the Nth `nameserver' instance in resolv.conf(5) else an error is +# generated discarding any/all changes. +# +# 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_dialog_input_nameserver_edit_awk=' +# Variables that should be defined on the invocation line: +# -v nsindex="1+" +# -v old_value="..." +# -v new_value="..." +# +BEGIN { + if ( nsindex < 1 ) exit 1 + found = n = 0 +} +{ + if ( found ) { print; next } + + if ( match(tolower($0), /^[[:space:]]*nameserver[[:space:]]+/)) { + if ( ++n == nsindex ) { + if ( $2 != old_value ) exit 2 + if ( new_value != "" ) printf "%s%s\n", \ + substr($0, 0, RLENGTH), new_value + found = 1 + } + else print + } + else print +} +END { if ( ! found ) exit 3 } +' +f_dialog_input_nameserver() +{ + local funcname=f_dialog_input_nameserver + local index="${1:-0}" old_ns="$2" new_ns + local ns="$old_ns" + + # + # Perform sanity checks + # + f_isinteger "$index" || return $DIALOG_CANCEL + [ $index -ge 0 ] || return $DIALOG_CANCEL + + local msg + if [ $index -gt 0 ]; then + if [ "$USE_XDIALOG" ]; then + msg="$xmsg_please_enter_nameserver_existing" + else + msg="$msg_please_enter_nameserver_existing" + fi + else + msg="$msg_please_enter_nameserver" + fi + + # + # Loop until the user provides taint-free input. + # + while :; do + f_dialog_input new_ns "$msg" "$ns" \ + "$hline_num_punc_tab_enter" || return $? + + # Take only the first "word" of the user's input + new_ns="${new_ns%%[$IFS]*}" + + # Taint-check the user's input + [ "$new_ns" ] || break + f_dialog_validate_ipaddr "$new_ns" && break + + # Update prompt to allow user to re-edit previous entry + ns="$new_ns" + done + + # + # Save only if the user changed the nameserver. + # + if [ $index -eq "0" -a "$new_ns" ]; then + f_dialog_info "$msg_saving_nameserver" + printf "nameserver\t%s\n" "$new_ns" >> "$RESOLV_CONF" + return $DIALOG_OK + elif [ $index -gt 0 -a "$old_ns" != "$new_ns" ]; then + if [ "$new_ns" ]; then + msg="$msg_saving_nameserver_existing" + else + msg="$msg_removing_nameserver" + fi + f_dialog_info "$msg" + + # + # Create a new temporary file to write our new resolv.conf(5) + # + local tmpfile + f_eval_catch -dk tmpfile $funcname mktemp \ + 'mktemp -t "%s"' "$pgm" || return $DIALOG_CANCEL + + # + # Quietly fixup permissions and ownership + # + local mode owner + f_eval_catch -dk mode $funcname stat \ + 'stat -f "%%#Lp" "%s"' "$RESOLV_CONF" || mode=0644 + f_eval_catch -dk owner $funcname stat \ + 'stat -f "%%u:%%g" "%s"' "$RESOLV_CONF" || + owner="root:wheel" + f_eval_catch -d $funcname chmod \ + 'chmod "%s" "%s"' "$mode" "$tmpfile" + f_eval_catch -d $funcname chown \ + 'chown "%s" "%s"' "$owner" "$tmpfile" + + # + # Operate on resolv.conf(5) + # + local new_contents + new_contents=$( awk -v nsindex="$index" \ + -v old_value="$old_ns" \ + -v new_value="$new_ns" \ + "$f_dialog_input_nameserver_edit_awk" \ + "$RESOLV_CONF" ) + + # + # Produce an appropriate error message if necessary. + # + local retval=$? + case $retval in + 1) f_die 1 "$msg_internal_error_nsindex_value" "$nsindex" ;; + 2) f_show_msg "$msg_resolv_conf_changed_while_editing" + return $retval ;; + 3) f_show_msg "$msg_resolv_conf_entry_no_longer_exists" + return $retval ;; + esac + + # + # Write the temporary file contents and move the temporary + # file into place. + # + echo "$new_contents" > "$tmpfile" || return $DIALOG_CANCEL + f_eval_catch -d $funcname mv \ + 'mv "%s" "%s"' "$tmpfile" "$RESOLV_CONF" + fi +} + +# f_dialog_menu_nameservers +# +# Edit the nameservers in resolv.conf(5). +# +f_dialog_menu_nameservers() +{ + local prompt="$msg_dns_configuration" + local menu_list # Calculated below + local hline="$hline_arrows_tab_enter" + local defaultitem= + + local height width rows + local opt_exit="$msg_return_to_previous_menu" + local opt_add="$msg_add_nameserver" + + # + # Loop forever until the user has finished configuring nameservers + # + while :; do + # + # Re/Build list of nameservers + # + local nameservers + f_resolv_conf_nameservers nameservers + menu_list=$( + index=1 + + echo "'X $msg_exit' '$opt_exit'" + index=$(( $index + 1 )) + + echo "'A $msg_add' '$opt_add'" + index=$(( $index + 1 )) + + for ns in $nameservers; do + [ $index -lt ${#DIALOG_MENU_TAGS} ] || break + f_substr -v tag "$DIALOG_MENU_TAGS" $index 1 + echo "'$tag nameserver' '$ns'" + index=$(( $index + 1 )) + done + ) + + # + # Display configuration-edit menu + # + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + local tag + tag=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_data_sanitize tag + + # Return if "Cancel" was chosen (-1) or ESC was pressed (255) + if [ $retval -ne $DIALOG_OK ]; then + return $retval + else + # Only update default-item on success + defaultitem="$tag" + fi + + case "$tag" in + "X $msg_exit") break ;; + "A $msg_add") + f_dialog_input_nameserver + ;; + *) + local n ns + n=$( eval f_dialog_menutag2index \"\$tag\" $menu_list ) + ns=$( eval f_dialog_menutag2item \"\$tag\" $menu_list ) + f_dialog_input_nameserver $(( $n - 2 )) "$ns" + ;; + esac + done +} + +############################################################ MAIN + +f_dprintf "%s: Successfully loaded." networking/resolv.subr + +fi # ! $_NETWORKING_RESOLV_SUBR diff --git a/bsdconfig/networking/share/routing.subr b/bsdconfig/networking/share/routing.subr new file mode 100644 index 000000000000..826ac6e10baf --- /dev/null +++ b/bsdconfig/networking/share/routing.subr @@ -0,0 +1,133 @@ +if [ ! "$_NETWORKING_ROUTING_SUBR" ]; then _NETWORKING_ROUTING_SUBR=1 +# +# Copyright (c) 2006-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." networking/routing.subr +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/media/tcpip.subr +f_include $BSDCFG_SHARE/networking/common.subr +f_include $BSDCFG_SHARE/networking/ipaddr.subr +f_include $BSDCFG_SHARE/strings.subr +f_include $BSDCFG_SHARE/sysrc.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +############################################################ FUNCTIONS + +# f_dialog_input_defaultrouter +# +# Edits the default router. +# +f_dialog_input_defaultrouter() +{ + local funcname=f_dialog_input_defaultrouter + + # + # Get the defaultrouter. When this is not configured, the default is + # "NO", however we don't ever want to present this default to the user + # in the following dialog. If the current value is "NO", then try to + # obtain the value from the running system using route(8). + # + # NOTE: Our `f_route_get_default' function will return NULL if the + # system does not have an active default router set (which is what we + # want). + # + local defaultrouter="$( f_sysrc_get 'defaultrouter:-NO' )" + local defaultrouter_orig="$defaultrouter" # for change-tracking + case "$defaultrouter" in + [Nn][Oo]) f_route_get_default defaultrouter ;; + esac + + # + # Return with-error when there are NFS-mounts currently active. If the + # default router/gateway is changed while NFS-exported directories are + # mounted, the system will hang. + # + if f_nfs_mounted && ! f_jailed; then + local setting + f_sprintf setting "$msg_current_default_router" \ + "$defaultrouter" + f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" || + return $DIALOG_CANCEL + fi + + # + # Loop until the user provides taint-free input. + # + local retval + while :; do + f_dialog_input defaultrouter \ + "$msg_please_enter_default_router" \ + "$defaultrouter" "$hline_num_punc_tab_enter" + retval=$? + [ "$defaultrouter" ] || return $DIALOG_OK + [ $retval -eq $DIALOG_OK ] || return $retval + + # Taint-check the user's input + f_dialog_validate_ipaddr "$defaultrouter" && break + done + + # + # Save only if the user changed the default router/gateway. + # + if [ "$defaultrouter" != "$defaultrouter_orig" ]; then + f_dialog_info "$msg_saving_default_router" + + # Save the default router/gateway + f_eval_catch $funcname f_sysrc_set \ + 'f_sysrc_set defaultrouter "%s"' "$defaultrouter" + fi + + # + # Only ask to apply setting if the current defaultrouter is different + # than the stored configuration (in rc.conf(5)). + # + local dr + f_route_get_default dr + if [ "$dr" != "$defaultrouter" ]; then + f_dialog_clear + f_yesno "$msg_activate_default_router" "$dr" "$defaultrouter" + if [ $? -eq $DIALOG_OK ]; then + # Apply the default router/gateway + f_eval_catch -d $funcname route 'route delete default' + f_eval_catch $funcname route \ + 'route add default "%s"' "$defaultrouter" || + return $DIALOG_CANCEL + fi + fi +} + +############################################################ MAIN + +f_dprintf "%s: Successfully loaded." networking/routing.subr + +fi # ! $_NETWORKING_ROUTING_SUBR diff --git a/bsdconfig/networking/share/services.subr b/bsdconfig/networking/share/services.subr new file mode 100644 index 000000000000..246d8956e322 --- /dev/null +++ b/bsdconfig/networking/share/services.subr @@ -0,0 +1,55 @@ +if [ ! "$_NETWORKING_SERVICES_SUBR" ]; then _NETWORKING_SERVICES_SUBR=1 +# +# Copyright (c) 2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." networking/services.subr +f_include $BSDCFG_SHARE/packages/packages.subr +f_include $BSDCFG_SHARE/sysrc.subr + +############################################################ FUNCTIONS + +# f_config_pcnfsd +# +# Load pcnfsd package and adjust mountd_flags in rc.conf(5). +# +f_config_pcnfsd() +{ + local funcname=f_config_pcnfsd + f_package_add "pcnfsd" || return $? + f_eval_catch $funcname f_sysrc_set 'f_sysrc_set mountd_flags -n' + return $SUCCESS +} + +############################################################ MAIN + +f_dprintf "%s: Successfully loaded." networking/services.subr + +fi # ! $_NETWORKING_SERVICES_SUBR diff --git a/bsdconfig/networking/wlanconfig b/bsdconfig/networking/wlanconfig new file mode 100755 index 000000000000..989bb794fb8e --- /dev/null +++ b/bsdconfig/networking/wlanconfig @@ -0,0 +1,78 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2013 Tom Rhodes +# Copyright (c) 2013-2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +# Prevent device.subr (included indirectly) from auto scanning on load +DEVICE_SELF_SCAN_ALL=NO + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/media/wlan.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_wireless_networks" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch the wireless network menu +# +f_dialog_menu_wireless_edit + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/packages/INDEX b/bsdconfig/packages/INDEX new file mode 100644 index 000000000000..80434779f202 --- /dev/null +++ b/bsdconfig/packages/INDEX @@ -0,0 +1,56 @@ +# Copyright (c) 2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# +# Title that will be shown in the bsdconfig menu. +# +menu_title="Packages" + +# +# A short descriptive line shown at the bottom of the bsdconfig menu. keep it +# short because any line longer than the terminal width will be truncated. +# +menu_help="Install pre-packaged software for FreeBSD" + +# +# Two-part variable that defines an action to take when `keyword' is passed on +# a bsdconfig command line. Variable takes the form "keyword|command" and +# multiple occurrences of the variable (with different `keyword's, or different +# `keyword's AND `command's) are allowed. If `command' begins with a '/' then +# the full path to the program is needed. If `command' begins with anything +# else it is a path relative to the directory this INDEX file is in. `keyword' +# can be i18n'ed but `command' is the name of a script. +# +menu_selection="packages|packages" + +# +# ------------ Items below this line do NOT need i18n translation ------------ +# +# Name of the program to be run when this menu choice is selected. If it begins +# with a '/' then the full path to the program is needed. If it begins with +# anything else it is a path relative to the directory this INDEX file is in. +# +menu_program="packages" diff --git a/bsdconfig/packages/Makefile b/bsdconfig/packages/Makefile new file mode 100644 index 000000000000..fa5bd302c6d7 --- /dev/null +++ b/bsdconfig/packages/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +SUBDIR= include + +FILESDIR= ${LIBEXECDIR}/bsdconfig/030.packages +FILES= INDEX USAGE + +SCRIPTSDIR= ${FILESDIR} +SCRIPTS= packages + +.include <bsd.prog.mk> diff --git a/bsdconfig/packages/Makefile.depend b/bsdconfig/packages/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/packages/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/packages/USAGE b/bsdconfig/packages/USAGE new file mode 100644 index 000000000000..5f99b3826454 --- /dev/null +++ b/bsdconfig/packages/USAGE @@ -0,0 +1,37 @@ +# Copyright (c) 2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS] + +OPTIONS: + -d Provide lots of debugging info on standard-out when running. + -D file Send debugging info to file. If file begins with a plus-sign + debug info is sent to both standard-out and file (minus the + leading plus). + -h Print this usage statement and exit. + -S Secure X11 mode (implies `-X'). As root, always prompt-for + and validate sudo(8) username/password before starting. + -X Use Xdialog(1) in place of dialog(1). diff --git a/bsdconfig/packages/include/Makefile b/bsdconfig/packages/include/Makefile new file mode 100644 index 000000000000..3d30fd2b4a5f --- /dev/null +++ b/bsdconfig/packages/include/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${LIBEXECDIR}/bsdconfig/030.packages/include +FILES= messages.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/packages/include/Makefile.depend b/bsdconfig/packages/include/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/packages/include/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/packages/include/messages.subr b/bsdconfig/packages/include/messages.subr new file mode 100755 index 000000000000..8e945acc8ab6 --- /dev/null +++ b/bsdconfig/packages/include/messages.subr @@ -0,0 +1,27 @@ +# Copyright (c) 2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +msg_package_selection="Package Selection" diff --git a/bsdconfig/packages/packages b/bsdconfig/packages/packages new file mode 100755 index 000000000000..ec429f282462 --- /dev/null +++ b/bsdconfig/packages/packages @@ -0,0 +1,82 @@ +#!/bin/sh +#- +# Copyright (c) 2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +# Prevent device.subr (included indirectly via media/*.subr below) from auto +# scanning; we'll perform this manually using f_device_get_all() during init +# but only after we've successfully completed f_mustberoot_init(). +# +DEVICE_SELF_SCAN_ALL=NO + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/media/common.subr +f_include $BSDCFG_SHARE/mustberoot.subr +f_include $BSDCFG_SHARE/packages/packages.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="030.packages" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_package_selection" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init +f_device_get_all + +# +# Display the package configuration menu and exit +# +trap 'f_media_close' EXIT +f_package_config + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/password/INDEX b/bsdconfig/password/INDEX new file mode 100644 index 000000000000..10f23db67b0b --- /dev/null +++ b/bsdconfig/password/INDEX @@ -0,0 +1,57 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# +# Title that will be shown in the bsdconfig menu. +# +menu_title="Root Password" + +# +# A short descriptive line shown at the bottom of the bsdconfig menu. keep it +# short because any line longer than the terminal width will be truncated. +# +menu_help="Set the system manager's password" + +# +# Two-part variable that defines an action to take when `keyword' is passed on +# a bsdconfig command line. Variable takes the form "keyword|command" and +# multiple occurrences of the variable (with different `keyword's, or different +# `keyword's AND `command's) are allowed. If `command' begins with a '/' then +# the full path to the program is needed. If `command' begins with anything +# else it is a path relative to the directory this INDEX file is in. `keyword' +# can be i18n'ed but `command' is the name of a script. +# +menu_selection="password|password" + +# +# ------------ Items below this line do NOT need i18n translation ------------ +# +# Name of the program to be run when this menu choice is selected. If it begins +# with a '/' then the full path to the program is needed. If it begins with +# anything else it is a path relative to the directory this INDEX file is in. +# +menu_program="password" diff --git a/bsdconfig/password/Makefile b/bsdconfig/password/Makefile new file mode 100644 index 000000000000..d660e452a659 --- /dev/null +++ b/bsdconfig/password/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +SUBDIR= include share + +FILESDIR= ${LIBEXECDIR}/bsdconfig/040.password +FILES= INDEX USAGE + +SCRIPTSDIR= ${FILESDIR} +SCRIPTS= password + +.include <bsd.prog.mk> diff --git a/bsdconfig/password/Makefile.depend b/bsdconfig/password/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/password/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/password/USAGE b/bsdconfig/password/USAGE new file mode 100644 index 000000000000..a06d8af24928 --- /dev/null +++ b/bsdconfig/password/USAGE @@ -0,0 +1,37 @@ +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS] + +OPTIONS: + -d Provide lots of debugging info on standard-out when running. + -D file Send debugging info to file. If file begins with a plus-sign + debug info is sent to both standard-out and file (minus the + leading plus). + -h Print this usage statement and exit. + -S Secure X11 mode (implies `-X'). As root, always prompt-for + and validate sudo(8) username/password before starting. + -X Use Xdialog(1) in place of dialog(1). diff --git a/bsdconfig/password/include/Makefile b/bsdconfig/password/include/Makefile new file mode 100644 index 000000000000..a146eb230ae9 --- /dev/null +++ b/bsdconfig/password/include/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${LIBEXECDIR}/bsdconfig/040.password/include +FILES= messages.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/password/include/Makefile.depend b/bsdconfig/password/include/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/password/include/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/password/include/messages.subr b/bsdconfig/password/include/messages.subr new file mode 100644 index 000000000000..655160de0724 --- /dev/null +++ b/bsdconfig/password/include/messages.subr @@ -0,0 +1,35 @@ +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +hline_alnum_punc_tab_enter="Use alpha-numeric, punctuation, TAB or ENTER" +msg_cancel="Cancel" +msg_enter_new_password="Enter New Password" +msg_ok="OK" +msg_password_changed="Password successfully changed." +msg_password_is_empty="Password is empty." +msg_passwords_do_not_match="Passwords do not match." +msg_reenter_password="Re-enter Password" +msg_root_password="Root Password" diff --git a/bsdconfig/password/password b/bsdconfig/password/password new file mode 100755 index 000000000000..b73a8d0936f0 --- /dev/null +++ b/bsdconfig/password/password @@ -0,0 +1,85 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +f_include $BSDCFG_SHARE/password/password.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="040.password" + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ CONFIGURATION + +# +# Default login of system manager +# +USER_ROOT=root + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_root_password" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Prompt the user to input a new password (and change it if they don't cancel) +# +if f_dialog_input_password; then + echo "$pw_password" | f_eval_catch "$0" pw \ + 'pw usermod "%s" -h 0' "$USER_ROOT" || f_die + f_show_msg "$msg_password_changed" +fi + +return $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/password/share/Makefile b/bsdconfig/password/share/Makefile new file mode 100644 index 000000000000..65f9e8c5c0f1 --- /dev/null +++ b/bsdconfig/password/share/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${SHAREDIR}/bsdconfig/password +FILES= password.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/password/share/Makefile.depend b/bsdconfig/password/share/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/password/share/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/password/share/password.subr b/bsdconfig/password/share/password.subr new file mode 100644 index 000000000000..22803394fc30 --- /dev/null +++ b/bsdconfig/password/share/password.subr @@ -0,0 +1,124 @@ +if [ ! "$_PASSWORD_PASSWORD_SUBR" ]; then _PASSWORD_PASSWORD_SUBR=1 +# +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." password/password.subr +f_include $BSDCFG_SHARE/dialog.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="040.password" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +############################################################ FUNCTIONS + +# f_dialog_input_password +# +# Prompt the user to enter a password (twice). If the user does not cancel or +# press ESC, the $pw_password environment variable will hold the password. +# +f_dialog_input_password() +{ + local prompt1="$msg_enter_new_password" + local prompt2="$msg_reenter_password" + local hline="$hline_alnum_punc_tab_enter" + + local height1 width1 + f_dialog_inputbox_size height1 width1 \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$prompt1" \ + "" \ + "$hline" + + local height2 width2 + f_dialog_inputbox_size height2 width2 \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$prompt2" \ + "" \ + "$hline" + + # + # Loop until the user provides taint-free/valid input + # + local _password1 _password2 + while :; do + _password1=$( $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --cancel-label "$msg_cancel" \ + --insecure \ + --passwordbox "$prompt1" \ + $height1 $width1 \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) || return $? + # Return if user either pressed ESC or chose Cancel/No + debug= f_dialog_line_sanitize _password1 + + _password2=$( $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --cancel-label "$msg_cancel" \ + --insecure \ + --passwordbox "$prompt2" \ + $height2 $width2 \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) || return $? + # Return if user either pressed ESC or chose Cancel/No + debug= f_dialog_line_sanitize _password2 + + # Check for NULL entry + if ! [ "$_password1" -o "$_password2" ]; then + f_show_msg "$msg_password_is_empty" + continue + fi + + # Check for password mismatch + if [ "$_password1" != "$_password2" ]; then + f_show_msg "$msg_passwords_do_not_match" + continue + fi + + pw_password="$_password1" + break + done + + return $DIALOG_OK +} + +############################################################ MAIN + +f_dprintf "%s: Successfully loaded." password/password.subr + +fi # ! $_PASSWORD_PASSWORD_SUBR diff --git a/bsdconfig/security/INDEX b/bsdconfig/security/INDEX new file mode 100644 index 000000000000..9e7718690622 --- /dev/null +++ b/bsdconfig/security/INDEX @@ -0,0 +1,58 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# +# Title that will be shown in the bsdconfig menu. +# +menu_title="Security" + +# +# A short descriptive line shown at the bottom of the bsdconfig menu. keep it +# short because any line longer than the terminal width will be truncated. +# +menu_help="Set Security Parameters" + +# +# Two-part variable that defines an action to take when `keyword' is passed on +# a bsdconfig command line. Variable takes the form "keyword|command" and +# multiple occurrences of the variable (with different `keyword's, or different +# `keyword's AND `command's) are allowed. If `command' begins with a '/' then +# the full path to the program is needed. If `command' begins with anything +# else it is a path relative to the directory this INDEX file is in. `keyword' +# can be i18n'ed but `command' is the name of a script. +# +menu_selection="security|security" +menu_selection="kern_securelevel|kern_securelevel" + +# +# ------------ Items below this line do NOT need i18n translation ------------ +# +# Name of the program to be run when this menu choice is selected. If it begins +# with a '/' then the full path to the program is needed. If it begins with +# anything else it is a path relative to the directory this INDEX file is in. +# +menu_program="security" diff --git a/bsdconfig/security/Makefile b/bsdconfig/security/Makefile new file mode 100644 index 000000000000..af83cee47158 --- /dev/null +++ b/bsdconfig/security/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +SUBDIR= include + +FILESDIR= ${LIBEXECDIR}/bsdconfig/130.security +FILES= INDEX USAGE + +SCRIPTSDIR= ${FILESDIR} +SCRIPTS= kern_securelevel security + +.include <bsd.prog.mk> diff --git a/bsdconfig/security/Makefile.depend b/bsdconfig/security/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/security/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/security/USAGE b/bsdconfig/security/USAGE new file mode 100644 index 000000000000..a06d8af24928 --- /dev/null +++ b/bsdconfig/security/USAGE @@ -0,0 +1,37 @@ +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS] + +OPTIONS: + -d Provide lots of debugging info on standard-out when running. + -D file Send debugging info to file. If file begins with a plus-sign + debug info is sent to both standard-out and file (minus the + leading plus). + -h Print this usage statement and exit. + -S Secure X11 mode (implies `-X'). As root, always prompt-for + and validate sudo(8) username/password before starting. + -X Use Xdialog(1) in place of dialog(1). diff --git a/bsdconfig/security/include/Makefile b/bsdconfig/security/include/Makefile new file mode 100644 index 000000000000..2efcc0f8a399 --- /dev/null +++ b/bsdconfig/security/include/Makefile @@ -0,0 +1,6 @@ +# $FreeBSD$ + +FILESDIR= ${LIBEXECDIR}/bsdconfig/130.security/include +FILES= messages.subr securelevel.hlp + +.include <bsd.prog.mk> diff --git a/bsdconfig/security/include/Makefile.depend b/bsdconfig/security/include/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/security/include/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/security/include/messages.subr b/bsdconfig/security/include/messages.subr new file mode 100644 index 000000000000..1ab2333c1fb8 --- /dev/null +++ b/bsdconfig/security/include/messages.subr @@ -0,0 +1,50 @@ +# Copyright (c) 2012 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +hline_arrows_tab_enter="Press arrows, TAB or ENTER" +hline_select_securelevel_to_operate_at="Select a securelevel to operate at" +msg_cancel="Cancel" +msg_disable_securelevels="Disable securelevels" +msg_disabled="Disabled" +msg_exit="Exit" +msg_exit_this_menu="Exit this menu" +msg_highly_secure="Highly Secure" +msg_highly_secure_mode="Highly secure mode" +msg_menu_text="This menu allows you to configure aspects of the operating system security\npolicy. Please read the system documentation carefully before modifying\nthese settings, as they may cause service disruption if used improperly.\n\nMost settings will take effect only following a system reboot." +msg_network_secure="Network Secure" +msg_network_secure_mode="Network secure mode" +msg_nfs_port="NFS port" +msg_nfs_port_desc="Require that the NFS clients use reserved ports" +msg_ok="OK" +msg_secure="Secure" +msg_secure_mode="Secure mode" +msg_securelevel="Securelevel" +msg_securelevel_desc="Configure securelevels for the system" +msg_securelevels_menu_text="This menu allows you to select the securelevel your system runs with.\nWhen operating at a securelevel, certain root privileges are disabled,\nwhich may increase resistance to exploits and protect system integrity.\nIn secure mode system flags may not be overridden by the root user,\naccess to direct kernel memory is limited, and kernel modules may not\nbe changed. In highly secure mode, mounted file systems may not be\nmodified on-disk, tampering with the system clock is prohibited. In\nnetwork secure mode configuration changes to firewalling are prohibited.\n " +msg_securelevels_menu_title="Securelevel Configuration Menu" +msg_system_security_options_menu="System Security Options Menu" +msg_unknown_kern_securelevel_selection="Unknown kern.securelevel selection" +msg_unknown_security_menu_selection="Unknown security menu selection" diff --git a/bsdconfig/security/include/securelevel.hlp b/bsdconfig/security/include/securelevel.hlp new file mode 100644 index 000000000000..27eb1ec231b9 --- /dev/null +++ b/bsdconfig/security/include/securelevel.hlp @@ -0,0 +1,40 @@ +This menu allows you to configure the Securelevel mechanism in FreeBSD. + +Securelevels may be used to limit the privileges assigned to the +root user in multi-user mode, which in turn may limit the effects of +a root compromise, at the cost of reducing administrative functions. +Refer to the security(7) and init(8) manual pages for complete details. + + -1 Permanently insecure mode - always run the system in level 0 + mode. This is the default initial value. + + 0 Insecure mode - immutable and append-only flags may be turned + off. All devices may be read or written subject to their + permissions. + + 1 Secure mode - the system immutable and system append-only + flags may not be turned off; disks for mounted file systems, + /dev/mem, /dev/kmem and /dev/io (if your platform has it) + may not be opened for writing; kernel modules (see kld(4)) + may not be loaded or unloaded. + + 2 Highly secure mode - same as secure mode, plus disks may not + be opened for writing (except by mount(2)) whether mounted or + not. This level precludes tampering with file systems by + unmounting them, but also inhibits running newfs(8) while the + system is multi-user. + + In addition, kernel time changes are restricted to less than + or equal to one second. Attempts to change the time by more + than this will log the message ``Time adjustment clamped to +1 + second''. + + 3 Network secure mode - same as highly secure mode, plus IP + packet filter rules (see ipfw(8), ipfirewall(4) and pfctl(8)) + cannot be changed and dummynet(4) or pf(4) configuration + cannot be adjusted. + +Securelevels must be used in combination with careful system design and +application of protective mechanisms to prevent system configuration +files from being modified in a way that compromises the protections of +the securelevel variable upon reboot. diff --git a/bsdconfig/security/kern_securelevel b/bsdconfig/security/kern_securelevel new file mode 100755 index 000000000000..9aa79b7de8f7 --- /dev/null +++ b/bsdconfig/security/kern_securelevel @@ -0,0 +1,175 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +SECURELEVEL_HELPFILE=$BSDCFG_LIBE/$APP_DIR/include/securelevel.hlp + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_securelevels_menu_text" + local menu_list=" + '$msg_disabled' '$msg_disable_securelevels' + '$msg_secure' '$msg_secure_mode' + '$msg_highly_secure' '$msg_highly_secure_mode' + '$msg_network_secure' '$msg_network_secure_mode' + " # END-QUOTE + local defaultitem= # Calculated below + local hline="$hline_select_securelevel_to_operate_at" + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + case "$( f_sysrc_get kern_securelevel_enable )" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + case "$( f_sysrc_get kern_securelevel )" in + 1) defaultitem="$msg_secure" ;; + 2) defaultitem="$msg_highly_secure" ;; + 3) defaultitem="$msg_network_secure" ;; + esac ;; + *) + defaultitem="$msg_disabled" + esac + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --help-button \ + --help-label \"\$msg_help\" \ + ${USE_XDIALOG:+--help \"\"} \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_menutag_store -s "$menu_choice" + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_securelevels_menu_title" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu (loop for additional `Help' button) +# +while :; do + dialog_menu_main + retval=$? + f_dialog_menutag_fetch mtag + + if [ $retval -eq $DIALOG_HELP ]; then + f_show_help "$SECURELEVEL_HELPFILE" + continue + elif [ $retval -ne $DIALOG_OK ]; then + f_die + fi + + break +done + +case "$mtag" in +"$msg_disabled") + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set kern_securelevel_enable NO' || f_die + ;; +"$msg_secure") + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set kern_securelevel_enable YES' || f_die + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set kern_securelevel 1' || f_die + ;; +"$msg_highly_secure") + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set kern_securelevel_enable YES' || f_die + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set kern_securelevel 2' || f_die + ;; +"$msg_network_secure") + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set kern_securelevel_enable YES' || f_die + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set kern_securelevel 3' || f_die + ;; +*) + f_die 1 "$msg_unknown_kern_securelevel_selection" +esac + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/security/security b/bsdconfig/security/security new file mode 100755 index 000000000000..e045ad8a2027 --- /dev/null +++ b/bsdconfig/security/security @@ -0,0 +1,179 @@ +#!/bin/sh +#- +# Copyright (c) 2012-2013 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +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 + +f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && + pgm="${ipgm:-$pgm}" + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local prompt="$msg_menu_text" + local menu_list=" + 'X $msg_exit' '$msg_exit_this_menu' + " # END-QUOTE + local defaultitem= # Calculated below + local hline="$hline_arrows_tab_enter" + + # Obtain default-item (adjusted below for dynamic tags) + f_dialog_default_fetch defaultitem + local ditem="${defaultitem%%[$IFS]*}" + + # + # Add dynamically tagged entry for kern_securelevels + # + local mark=" " + case "$( f_sysrc_get kern_securelevel_enable )" in + [Yy][Ee][Ss]) + local kern_securelevel="$( f_sysrc_get kern_securelevel )" + if [ ${#kern_securelevel} -eq 1 ] && + f_isinteger "$kern_securelevel" && + [ $kern_securelevel -lt 9 ] + then + mark="$kern_securelevel" + else + mark="X" + fi ;; + *) + mark=" " + esac + menu_list="$menu_list + '2 [$mark] $msg_securelevel' '$msg_securelevel_desc'" + + # Update default-item if appropriate + [ "$ditem" = 2 ] && defaultitem="2 [$mark] $msg_securelevel" + + # + # Add dynamically tagged entry for nfs_reserved_port_only + # + case "$( f_sysrc_get nfs_reserved_port_only )" in + [Yy][Ee][Ss]) mark="X" ;; + *) mark=" " ;; + esac + menu_list="$menu_list + '3 [$mark] $msg_nfs_port' '$msg_nfs_port_desc'" + + # Update default-item if appropriate + [ "$ditem" = 3 ] && defaultitem="3 [$mark] $msg_nfs_port" + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + local menu_choice + menu_choice=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + f_dialog_data_sanitize menu_choice + f_dialog_menutag_store "$menu_choice" + + # Only update default-item on success + [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice" + + return $retval +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts h$GETOPTS_STDARGS flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_title "$msg_system_security_options_menu" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu (loop for menu update after selection) +# +while :; do + dialog_menu_main || f_die + f_dialog_menutag_fetch mtag + + case "$mtag" in + "X $msg_exit") break ;; + "2 ["?"] $msg_securelevel") # Configure securelevels for the system + $BSDCFG_LIBE/$APP_DIR/kern_securelevel ${USE_XDIALOG:+-X} ;; + "3 [X] $msg_nfs_port") # Require that NFS clients use reserved ports + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set nfs_reserved_port_only NO' ;; + "3 [ ] $msg_nfs_port") # Same; Toggle value + f_eval_catch "$0" f_sysrc_set \ + 'f_sysrc_set nfs_reserved_port_only YES' ;; + *) + f_die 1 "$msg_unknown_security_menu_selection" + esac +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/bsdconfig/share/Makefile b/bsdconfig/share/Makefile new file mode 100644 index 000000000000..a09697a29d0d --- /dev/null +++ b/bsdconfig/share/Makefile @@ -0,0 +1,10 @@ +# $FreeBSD$ + +SUBDIR= media packages + +FILESDIR= ${SHAREDIR}/bsdconfig +FILES= common.subr device.subr dialog.subr geom.subr keymap.subr \ + mustberoot.subr script.subr strings.subr struct.subr \ + sysrc.subr variable.subr + +.include <bsd.prog.mk> diff --git a/bsdconfig/share/Makefile.depend b/bsdconfig/share/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/bsdconfig/share/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bsdconfig/share/common.subr b/bsdconfig/share/common.subr new file mode 100644 index 000000000000..49b9186f548f --- /dev/null +++ b/bsdconfig/share/common.subr @@ -0,0 +1,1046 @@ +if [ ! "$_COMMON_SUBR" ]; then _COMMON_SUBR=1 +# +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012-2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ CONFIGURATION + +# +# Default file descriptors to link to stdout/stderr for passthru allowing +# redirection within a sub-shell to bypass directly to the terminal. +# +: ${TERMINAL_STDOUT_PASSTHRU:=3} +: ${TERMINAL_STDERR_PASSTHRU:=4} + +############################################################ GLOBALS + +# +# Program name +# +pgm="${0##*/}" + +# +# Program arguments +# +ARGC="$#" +ARGV="$@" + +# +# Global exit status variables +# +SUCCESS=0 +FAILURE=1 + +# +# Operating environment details +# +export UNAME_S="$( uname -s )" # Operating System (i.e. FreeBSD) +export UNAME_P="$( uname -p )" # Processor Architecture (i.e. i386) +export UNAME_M="$( uname -m )" # Machine platform (i.e. i386) +export UNAME_R="$( uname -r )" # Release Level (i.e. X.Y-RELEASE) + +# +# Default behavior is to call f_debug_init() automatically when loaded. +# +: ${DEBUG_SELF_INITIALIZE=1} + +# +# Default behavior of f_debug_init() is to truncate $debugFile (set to NULL to +# disable truncating the debug file when initializing). To get child processes +# to append to the same log file, export this variarable (with a NULL value) +# and also export debugFile with the desired value. +# +: ${DEBUG_INITIALIZE_FILE=1} + +# +# Define standard optstring arguments that should be supported by all programs +# using this include (unless DEBUG_SELF_INITIALIZE is set to NULL to prevent +# f_debug_init() from autamatically processing "$@" for the below arguments): +# +# d Sets $debug to 1 +# D: Sets $debugFile to $OPTARG +# +GETOPTS_STDARGS="dD:" + +# +# The getopts builtin will return 1 either when the end of "$@" or the first +# invalid flag is reached. This makes it impossible to determine if you've +# processed all the arguments or simply have hit an invalid flag. In the cases +# where we want to tolerate invalid flags (f_debug_init() for example), the +# following variable can be appended to your optstring argument to getopts, +# preventing it from prematurely returning 1 before the end of the arguments. +# +# NOTE: This assumes that all unknown flags are argument-less. +# +GETOPTS_ALLFLAGS="abcdefghijklmnopqrstuvwxyz" +GETOPTS_ALLFLAGS="${GETOPTS_ALLFLAGS}ABCDEFGHIJKLMNOPQRSTUVWXYZ" +GETOPTS_ALLFLAGS="${GETOPTS_ALLFLAGS}0123456789" + +# +# When we get included, f_debug_init() will fire (unless $DEBUG_SELF_INITIALIZE +# is set to disable automatic initialization) and process "$@" for a few global +# options such as `-d' and/or `-D file'. However, if your program takes custom +# flags that take arguments, this automatic processing may fail unexpectedly. +# +# The solution to this problem is to pre-define (before including this file) +# the following variable (which defaults to NULL) to indicate that there are +# extra flags that should be considered when performing automatic processing of +# globally persistent flags. +# +: ${GETOPTS_EXTRA:=} + +############################################################ FUNCTIONS + +# f_dprintf $format [$arguments ...] +# +# Sensible debug function. Override in ~/.bsdconfigrc if desired. +# See /usr/share/examples/bsdconfig/bsdconfigrc for example. +# +# If $debug is set and non-NULL, prints DEBUG info using printf(1) syntax: +# + To $debugFile, if set and non-NULL +# + To standard output if $debugFile is either NULL or unset +# + To both if $debugFile begins with a single plus-sign (`+') +# +f_dprintf() +{ + [ "$debug" ] || return $SUCCESS + local fmt="$1"; shift + case "$debugFile" in ""|+*) + printf "DEBUG: $fmt${fmt:+\n}" "$@" >&${TERMINAL_STDOUT_PASSTHRU:-1} + esac + [ "${debugFile#+}" ] && + printf "DEBUG: $fmt${fmt:+\n}" "$@" >> "${debugFile#+}" + return $SUCCESS +} + +# f_debug_init +# +# Initialize debugging. Truncates $debugFile to zero bytes if set. +# +f_debug_init() +{ + # + # Process stored command-line arguments + # + set -- $ARGV + local OPTIND OPTARG flag + f_dprintf "f_debug_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \ + "$ARGV" "$GETOPTS_STDARGS" + while getopts "$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" flag \ + > /dev/null; do + case "$flag" in + d) debug=1 ;; + D) debugFile="$OPTARG" ;; + esac + done + shift $(( $OPTIND - 1 )) + f_dprintf "f_debug_init: debug=[%s] debugFile=[%s]" \ + "$debug" "$debugFile" + + # + # Automagically enable debugging if debugFile is set (and non-NULL) + # + [ "$debugFile" ] && { [ "${debug+set}" ] || debug=1; } + + # + # Make debugging persistent if set + # + [ "$debug" ] && export debug + [ "$debugFile" ] && export debugFile + + # + # Truncate debug file unless requested otherwise. Note that we will + # trim a leading plus (`+') from the value of debugFile to support + # persistent meaning that f_dprintf() should print both to standard + # output and $debugFile (minus the leading plus, of course). + # + local _debug_file="${debugFile#+}" + if [ "$_debug_file" -a "$DEBUG_INITIALIZE_FILE" ]; then + if ( umask 022 && :> "$_debug_file" ); then + f_dprintf "Successfully initialized debugFile \`%s'" \ + "$_debug_file" + f_isset debug || debug=1 # turn debugging on if not set + else + unset debugFile + f_dprintf "Unable to initialize debugFile \`%s'" \ + "$_debug_file" + fi + fi +} + +# f_err $format [$arguments ...] +# +# Print a message to stderr (fd=2). +# +f_err() +{ + printf "$@" >&2 +} + +# f_quietly $command [$arguments ...] +# +# Run a command quietly (quell any output to stdout or stderr) +# +f_quietly() +{ + "$@" > /dev/null 2>&1 +} + +# f_have $anything ... +# +# A wrapper to the `type' built-in. Returns true if argument is a valid shell +# built-in, keyword, or externally-tracked binary, otherwise false. +# +f_have() +{ + f_quietly type "$@" +} + +# setvar $var_to_set [$value] +# +# Implement setvar for shells unlike FreeBSD sh(1). +# +if ! f_have setvar; then +setvar() +{ + [ $# -gt 0 ] || return $SUCCESS + local __setvar_var_to_set="$1" __setvar_right="$2" __setvar_left= + case $# in + 1) unset "$__setvar_var_to_set" + return $? ;; + 2) : fall through ;; + *) f_err "setvar: too many arguments\n" + return $FAILURE + esac + case "$__setvar_var_to_set" in *[!0-9A-Za-z_]*) + f_err "setvar: %s: bad variable name\n" "$__setvar_var_to_set" + return 2 + esac + while case "$__setvar_r" in *\'*) : ;; *) false ; esac + do + __setvar_left="$__setvar_left${__setvar_right%%\'*}'\\''" + __setvar_right="${__setvar_right#*\'}" + done + __setvar_left="$__setvar_left${__setvar_right#*\'}" + eval "$__setvar_var_to_set='$__setvar_left'" +} +fi + +# f_which $anything [$var_to_set] +# +# A fast built-in replacement for syntaxes such as foo=$( which bar ). In a +# comparison of 10,000 runs of this function versus which, this function +# completed in under 3 seconds, while `which' took almost a full minute. +# +# If $var_to_set is missing or NULL, output is (like which) to standard out. +# Returns success if a match was found, failure otherwise. +# +f_which() +{ + local __name="$1" __var_to_set="$2" + case "$__name" in */*|'') return $FAILURE; esac + local __p __exec IFS=":" __found= + for __p in $PATH; do + __exec="$__p/$__name" + [ -f "$__exec" -a -x "$__exec" ] && __found=1 break + done + if [ "$__found" ]; then + if [ "$__var_to_set" ]; then + setvar "$__var_to_set" "$__exec" + else + echo "$__exec" + fi + return $SUCCESS + fi + return $FAILURE +} + +# f_getvar $var_to_get [$var_to_set] +# +# Utility function designed to go along with the already-builtin setvar. +# Allows clean variable name indirection without forking or sub-shells. +# +# Returns error status if the requested variable ($var_to_get) is not set. +# +# If $var_to_set is missing or NULL, the value of $var_to_get is printed to +# standard output for capturing in a sub-shell (which is less-recommended +# because of performance degredation; for example, when called in a loop). +# +f_getvar() +{ + local __var_to_get="$1" __var_to_set="$2" + [ "$__var_to_set" ] || local value + eval [ \"\${$__var_to_get+set}\" ] + local __retval=$? + eval ${__var_to_set:-value}=\"\${$__var_to_get}\" + eval f_dprintf '"f_getvar: var=[%s] value=[%s] r=%u"' \ + \"\$__var_to_get\" \"\$${__var_to_set:-value}\" \$__retval + [ "$__var_to_set" ] || { [ "$value" ] && echo "$value"; } + return $__retval +} + +# f_isset $var +# +# Check if variable $var is set. Returns success if variable is set, otherwise +# returns failure. +# +f_isset() +{ + eval [ \"\${${1%%[$IFS]*}+set}\" ] +} + +# f_die [$status [$format [$arguments ...]]] +# +# Abruptly terminate due to an error optionally displaying a message in a +# dialog box using printf(1) syntax. +# +f_die() +{ + local status=$FAILURE + + # If there is at least one argument, take it as the status + if [ $# -gt 0 ]; then + status=$1 + shift 1 # status + fi + + # If there are still arguments left, pass them to f_show_msg + [ $# -gt 0 ] && f_show_msg "$@" + + # Optionally call f_clean_up() function if it exists + f_have f_clean_up && f_clean_up + + exit $status +} + +# f_interrupt +# +# Interrupt handler. +# +f_interrupt() +{ + exec 2>&1 # fix sh(1) bug where stderr gets lost within async-trap + f_die +} + +# f_show_info $format [$arguments ...] +# +# Display a message in a dialog infobox using printf(1) syntax. +# +f_show_info() +{ + local msg + msg=$( printf "$@" ) + + # + # Use f_dialog_infobox from dialog.subr if possible, otherwise fall + # back to dialog(1) (without options, making it obvious when using + # un-aided system dialog). + # + if f_have f_dialog_info; then + f_dialog_info "$msg" + else + dialog --infobox "$msg" 0 0 + fi +} + +# f_show_msg $format [$arguments ...] +# +# Display a message in a dialog box using printf(1) syntax. +# +f_show_msg() +{ + local msg + msg=$( printf "$@" ) + + # + # Use f_dialog_msgbox from dialog.subr if possible, otherwise fall + # back to dialog(1) (without options, making it obvious when using + # un-aided system dialog). + # + if f_have f_dialog_msgbox; then + f_dialog_msgbox "$msg" + else + dialog --msgbox "$msg" 0 0 + fi +} + +# f_show_err $format [$arguments ...] +# +# Display a message in a dialog box with ``Error'' i18n title (overridden by +# setting msg_error) using printf(1) syntax. +# +f_show_err() +{ + local msg + msg=$( printf "$@" ) + + : ${msg:=${msg_an_unknown_error_occurred:-An unknown error occurred}} + + if [ "$_DIALOG_SUBR" ]; then + f_dialog_title "${msg_error:-Error}" + f_dialog_msgbox "$msg" + f_dialog_title_restore + else + dialog --title "${msg_error:-Error}" --msgbox "$msg" 0 0 + fi + return $SUCCESS +} + +# f_yesno $format [$arguments ...] +# +# Display a message in a dialog yes/no box using printf(1) syntax. +# +f_yesno() +{ + local msg + msg=$( printf "$@" ) + + # + # Use f_dialog_yesno from dialog.subr if possible, otherwise fall + # back to dialog(1) (without options, making it obvious when using + # un-aided system dialog). + # + if f_have f_dialog_yesno; then + f_dialog_yesno "$msg" + else + dialog --yesno "$msg" 0 0 + fi +} + +# f_noyes $format [$arguments ...] +# +# Display a message in a dialog yes/no box using printf(1) syntax. +# NOTE: THis is just like the f_yesno function except "No" is default. +# +f_noyes() +{ + local msg + msg=$( printf "$@" ) + + # + # Use f_dialog_noyes from dialog.subr if possible, otherwise fall + # back to dialog(1) (without options, making it obvious when using + # un-aided system dialog). + # + if f_have f_dialog_noyes; then + f_dialog_noyes "$msg" + else + dialog --defaultno --yesno "$msg" 0 0 + fi +} + +# f_show_help $file +# +# Display a language help-file. Automatically takes $LANG and $LC_ALL into +# consideration when displaying $file (suffix ".$LC_ALL" or ".$LANG" will +# automatically be added prior to loading the language help-file). +# +# If a language has been requested by setting either $LANG or $LC_ALL in the +# environment and the language-specific help-file does not exist we will fall +# back to $file without-suffix. +# +# If the language help-file does not exist, an error is displayed instead. +# +f_show_help() +{ + local file="$1" + local lang="${LANG:-$LC_ALL}" + + [ -f "$file.$lang" ] && file="$file.$lang" + + # + # Use f_dialog_textbox from dialog.subr if possible, otherwise fall + # back to dialog(1) (without options, making it obvious when using + # un-aided system dialog). + # + if f_have f_dialog_textbox; then + f_dialog_textbox "$file" + else + dialog --msgbox "$( cat "$file" 2>&1 )" 0 0 + fi +} + +# f_include $file +# +# Include a shell subroutine file. +# +# If the subroutine file exists but returns error status during loading, exit +# is called and execution is prematurely terminated with the same error status. +# +f_include() +{ + local file="$1" + f_dprintf "f_include: file=[%s]" "$file" + . "$file" || exit $? +} + +# f_include_lang $file +# +# Include a language file. Automatically takes $LANG and $LC_ALL into +# consideration when including $file (suffix ".$LC_ALL" or ".$LANG" will +# automatically by added prior to loading the language file). +# +# No error is produced if (a) a language has been requested (by setting either +# $LANG or $LC_ALL in the environment) and (b) the language file does not +# exist -- in which case we will fall back to loading $file without-suffix. +# +# If the language file exists but returns error status during loading, exit +# is called and execution is prematurely terminated with the same error status. +# +f_include_lang() +{ + local file="$1" + local lang="${LANG:-$LC_ALL}" + + f_dprintf "f_include_lang: file=[%s] lang=[%s]" "$file" "$lang" + if [ -f "$file.$lang" ]; then + . "$file.$lang" || exit $? + else + . "$file" || exit $? + fi +} + +# f_usage $file [$key1 $value1 ...] +# +# Display USAGE file with optional pre-processor macro definitions. The first +# argument is the template file containing the usage text to be displayed. If +# $LANG or $LC_ALL (in order of preference, respectively) is set, ".encoding" +# will automatically be appended as a suffix to the provided $file pathname. +# +# When processing $file, output begins at the first line containing that is +# (a) not a comment, (b) not empty, and (c) is not pure-whitespace. All lines +# appearing after this first-line are output, including (a) comments (b) empty +# lines, and (c) lines that are purely whitespace-only. +# +# If additional arguments appear after $file, substitutions are made while +# printing the contents of the USAGE file. The pre-processor macro syntax is in +# the style of autoconf(1), for example: +# +# f_usage $file "FOO" "BAR" +# +# Will cause instances of "@FOO@" appearing in $file to be replaced with the +# text "BAR" before being printed to the screen. +# +# 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_usage_awk=' +BEGIN { found = 0 } +{ + if ( !found && $0 ~ /^[[:space:]]*($|#)/ ) next + found = 1 + print +} +' +f_usage() +{ + local file="$1" + local lang="${LANG:-$LC_ALL}" + + f_dprintf "f_usage: file=[%s] lang=[%s]" "$file" "$lang" + + shift 1 # file + + local usage + if [ -f "$file.$lang" ]; then + usage=$( awk "$f_usage_awk" "$file.$lang" ) || exit $FAILURE + else + usage=$( awk "$f_usage_awk" "$file" ) || exit $FAILURE + fi + + while [ $# -gt 0 ]; do + local key="$1" + export value="$2" + usage=$( echo "$usage" | awk \ + "{ gsub(/@$key@/, ENVIRON[\"value\"]); print }" ) + shift 2 + done + + f_err "%s\n" "$usage" + + exit $FAILURE +} + +# f_index_file $keyword [$var_to_set] +# +# 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 $LANG or $LC_ALL (in order of preference, respectively) is set, +# "INDEX.encoding" files will be searched first. +# +# If no file is found, error status is returned along with the NULL string. +# +# If $var_to_set is NULL or missing, output is printed to stdout (which is less +# recommended due to performance degradation; in a loop for example). +# +# 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_file_awk=' +# Variables that should be defined on the invocation line: +# -v keyword="keyword" +BEGIN { found = 0 } +( $0 ~ "^menu_selection=\"" keyword "\\|" ) { + print FILENAME + found++ + exit +} +END { exit ! found } +' +f_index_file() +{ + local __keyword="$1" __var_to_set="$2" + local __lang="${LANG:-$LC_ALL}" + local __indexes="$BSDCFG_LIBE${BSDCFG_LIBE:+/}*/INDEX" + + f_dprintf "f_index_file: keyword=[%s] lang=[%s]" "$__keyword" "$__lang" + + if [ "$__lang" ]; then + if [ "$__var_to_set" ]; then + eval "$__var_to_set"='"$( awk -v keyword="$__keyword" \ + "$f_index_file_awk" $__indexes.$__lang + )"' && return $SUCCESS + else + awk -v keyword="$__keyword" "$f_index_file_awk" \ + $__indexes.$__lang && return $SUCCESS + fi + # No match, fall-thru to non-i18n sources + fi + if [ "$__var_to_set" ]; then + eval "$__var_to_set"='"$( awk -v keyword="$__keyword" \ + "$f_index_file_awk" $__indexes )"' && return $SUCCESS + else + awk -v keyword="$__keyword" "$f_index_file_awk" $__indexes && + return $SUCCESS + fi + + # No match? Fall-thru to `local' libexec sources (add-on modules) + + [ "$BSDCFG_LOCAL_LIBE" ] || return $FAILURE + __indexes="$BSDCFG_LOCAL_LIBE/*/INDEX" + if [ "$__lang" ]; then + if [ "$__var_to_set" ]; then + eval "$__var_to_set"='"$( awk -v keyword="$__keyword" \ + "$f_index_file_awk" $__indexes.$__lang + )"' && return $SUCCESS + else + awk -v keyword="$__keyword" "$f_index_file_awk" \ + $__indexes.$__lang && return $SUCCESS + fi + # No match, fall-thru to non-i18n sources + fi + if [ "$__var_to_set" ]; then + eval "$__var_to_set"='$( awk -v keyword="$__keyword" \ + "$f_index_file_awk" $__indexes )"' + else + awk -v keyword="$__keyword" "$f_index_file_awk" $__indexes + fi +} + +# f_index_menusel_keyword $indexfile $pgm [$var_to_set] +# +# 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. +# +# If $var_to_set is NULL or missing, output is printed to stdout (which is less +# recommended due to performance degradation; in a loop for example). +# +# 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" __var_to_set="$3" + local __lang="${LANG:-$LC_ALL}" __file="$__indexfile" + + [ -f "$__indexfile.$__lang" ] && __file="$__indexfile.$__lang" + f_dprintf "f_index_menusel_keyword: index=[%s] pgm=[%s] lang=[%s]" \ + "$__file" "$__pgm" "$__lang" + + if [ "$__var_to_set" ]; then + setvar "$__var_to_set" "$( awk \ + -v pgm="$__pgm" "$f_index_menusel_keyword_awk" "$__file" + )" + else + awk -v pgm="$__pgm" "$f_index_menusel_keyword_awk" "$__file" + fi +} + +# f_index_menusel_command $indexfile $keyword [$var_to_set] +# +# 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. +# +# If $var_to_set is NULL or missing, output is printed to stdout (which is less +# recommended due to performance degradation; in a loop for example). +# +# 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" __var_to_set="$3" __command + local __lang="${LANG:-$LC_ALL}" __file="$__indexfile" + + [ -f "$__indexfile.$__lang" ] && __file="$__indexfile.$__lang" + f_dprintf "f_index_menusel_command: index=[%s] key=[%s] lang=[%s]" \ + "$__file" "$__keyword" "$__lang" + + [ -f "$__file" ] || return $FAILURE + __command=$( awk -v key="$__keyword" \ + "$f_index_menusel_command_awk" "$__file" ) || return $FAILURE + + # + # 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 + + if [ "$__var_to_set" ]; then + setvar "$__var_to_set" "$__command" + else + echo "$__command" + fi +} + +# f_running_as_init +# +# Returns true if running as init(1). +# +f_running_as_init() +{ + # + # When a custom init(8) performs an exec(3) to invoke a shell script, + # PID 1 becomes sh(1) and $PPID is set to 1 in the executed script. + # + [ ${PPID:-0} -eq 1 ] # Return status +} + +# f_mounted $local_directory +# f_mounted -b $device +# +# Return success if a filesystem is mounted on a particular directory. If `-b' +# is present, instead check that the block device (or a partition thereof) is +# mounted. +# +f_mounted() +{ + local OPTIND OPTARG flag use_device= + while getopts b flag; do + case "$flag" in + b) use_device=1 ;; + esac + done + shift $(( $OPTIND - 1 )) + if [ "$use_device" ]; then + local device="$1" + mount | grep -Eq \ + "^$device([[:space:]]|p[0-9]|s[0-9]|\.nop|\.eli)" + else + [ -d "$dir" ] || return $FAILURE + mount | grep -Eq " on $dir \([^)]+\)$" + fi + # Return status is that of last grep(1) +} + +# f_eval_catch [-de] [-k $var_to_set] $funcname $utility \ +# $format [$arguments ...] +# +# Silently evaluate a command in a sub-shell and test for error. If debugging +# is enabled a copy of the command and its output is sent to debug (either +# stdout or file depending on environment). If an error occurs, output of the +# command is displayed in a dialog(1) msgbox using the [above] f_show_err() +# function (unless optional `-d' flag is given, then no dialog). +# +# The $funcname argument is sent to debugging while the $utility argument is +# used in the title of the dialog box. The command that is executed as well as +# sent to debugging with $funcname is the product of the printf(1) syntax +# produced by $format with optional $arguments. +# +# The following options are supported: +# +# -d Do not use dialog(1). +# -e Produce error text from failed command on stderr. +# -k var Save output from the command in var. +# +# Example 1: +# +# debug=1 +# f_eval_catch myfunc echo 'echo "%s"' "Hello, World!" +# +# Produces the following debug output: +# +# DEBUG: myfunc: echo "Hello, World!" +# DEBUG: myfunc: retval=0 <output below> +# Hello, World! +# +# Example 2: +# +# debug=1 +# f_eval_catch -k contents myfunc cat 'cat "%s"' /some/file +# # dialog(1) Error ``cat: /some/file: No such file or directory'' +# # contents=[cat: /some/file: No such file or directory] +# +# Produces the following debug output: +# +# DEBUG: myfunc: cat "/some/file" +# DEBUG: myfunc: retval=1 <output below> +# cat: /some/file: No such file or directory +# +# Example 3: +# +# debug=1 +# echo 123 | f_eval_catch myfunc rev rev +# +# Produces the following debug output: +# +# DEBUG: myfunc: rev +# DEBUG: myfunc: retval=0 <output below> +# 321 +# +# Example 4: +# +# debug=1 +# f_eval_catch myfunc true true +# +# Produces the following debug output: +# +# DEBUG: myfunc: true +# DEBUG: myfunc: retval=0 <no output> +# +# Example 5: +# +# f_eval_catch -de myfunc ls 'ls "%s"' /some/dir +# # Output on stderr ``ls: /some/dir: No such file or directory'' +# +# Example 6: +# +# f_eval_catch -dek contents myfunc ls 'ls "%s"' /etc +# # Output from `ls' sent to stderr and also saved in $contents +# +f_eval_catch() +{ + local __no_dialog= __show_err= __var_to_set= + + # + # Process local function arguments + # + local OPTIND OPTARG __flag + while getopts "dek:" __flag > /dev/null; do + case "$__flag" in + d) __no_dialog=1 ;; + e) __show_err=1 ;; + k) __var_to_set="$OPTARG" ;; + esac + done + shift $(( $OPTIND - 1 )) + + local __funcname="$1" __utility="$2"; shift 2 + local __cmd __output __retval + + __cmd=$( printf -- "$@" ) + f_dprintf "%s: %s" "$__funcname" "$__cmd" # Log command *before* eval + __output=$( exec 2>&1; eval "$__cmd" ) + __retval=$? + if [ "$__output" ]; then + [ "$__show_err" ] && echo "$__output" >&2 + f_dprintf "%s: retval=%i <output below>\n%s" "$__funcname" \ + $__retval "$__output" + else + f_dprintf "%s: retval=%i <no output>" "$__funcname" $__retval + fi + + ! [ "$__no_dialog" -o "$nonInteractive" -o $__retval -eq $SUCCESS ] && + msg_error="${msg_error:-Error}${__utility:+: $__utility}" \ + f_show_err "%s" "$__output" + # NB: f_show_err will handle NULL output appropriately + + [ "$__var_to_set" ] && setvar "$__var_to_set" "$__output" + + return $__retval +} + +# f_count $var_to_set arguments ... +# +# Sets $var_to_set to the number of arguments minus one (the effective number +# of arguments following $var_to_set). +# +# Example: +# f_count count dog house # count=[2] +# +f_count() +{ + setvar "$1" $(( $# - 1 )) +} + +# f_count_ifs $var_to_set string ... +# +# Sets $var_to_set to the number of words (split by the internal field +# separator, IFS) following $var_to_set. +# +# Example 1: +# +# string="word1 word2 word3" +# f_count_ifs count "$string" # count=[3] +# f_count_ifs count $string # count=[3] +# +# Example 2: +# +# IFS=. f_count_ifs count www.freebsd.org # count=[3] +# +# NB: Make sure to use double-quotes if you are using a custom value for IFS +# and you don't want the current value to effect the result. See example 3. +# +# Example 3: +# +# string="a-b c-d" +# IFS=- f_count_ifs count "$string" # count=[3] +# IFS=- f_count_ifs count $string # count=[4] +# +f_count_ifs() +{ + local __var_to_set="$1" + shift 1 + set -- $* + setvar "$__var_to_set" $# +} + +############################################################ MAIN + +# +# Trap signals so we can recover gracefully +# +trap 'f_interrupt' INT +trap 'f_die' TERM PIPE XCPU XFSZ FPE TRAP ABRT SEGV +trap '' ALRM PROF USR1 USR2 HUP VTALRM + +# +# Clone terminal stdout/stderr so we can redirect to it from within sub-shells +# +eval exec $TERMINAL_STDOUT_PASSTHRU\>\&1 +eval exec $TERMINAL_STDERR_PASSTHRU\>\&2 + +# +# Self-initialize unless requested otherwise +# +f_dprintf "%s: DEBUG_SELF_INITIALIZE=[%s]" \ + dialog.subr "$DEBUG_SELF_INITIALIZE" +case "$DEBUG_SELF_INITIALIZE" in +""|0|[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee]) : do nothing ;; +*) f_debug_init +esac + +# +# Log our operating environment for debugging purposes +# +f_dprintf "UNAME_S=[%s] UNAME_P=[%s] UNAME_R=[%s]" \ + "$UNAME_S" "$UNAME_P" "$UNAME_R" + +f_dprintf "%s: Successfully loaded." common.subr + +fi # ! $_COMMON_SUBR diff --git a/bsdconfig/share/device.subr b/bsdconfig/share/device.subr new file mode 100644 index 000000000000..97e878424703 --- /dev/null +++ b/bsdconfig/share/device.subr @@ -0,0 +1,1393 @@ +if [ ! "$_DEVICE_SUBR" ]; then _DEVICE_SUBR=1 +# +# Copyright (c) 2012-2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." device.subr +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/geom.subr +f_include $BSDCFG_SHARE/strings.subr +f_include $BSDCFG_SHARE/struct.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" +f_include_lang $BSDCFG_LIBE/include/messages.subr + +############################################################ GLOBALS + +NDEVICES=0 # Set by f_device_register(), used by f_device_*() + +# +# A "device" from legacy sysinstall's point of view (mostly) +# +# NB: Disk devices have their `private' property set to GEOM ident +# NB: USB devices have their `private' property set to USB disk device name +# +f_struct_define DEVICE \ + capacity \ + desc \ + devname \ + enabled \ + flags \ + get \ + init \ + name \ + private \ + shutdown \ + type \ + volume + +# Network devices have their `private' property set to this +f_struct_define DEVICE_INFO \ + extras \ + ipaddr \ + ipv6addr \ + netmask \ + use_dhcp \ + use_rtsol + +# +# Device types for f_device_register(), f_device_find(), et al. +# +setvar DEVICE_TYPE_ANY "any" # Any +setvar DEVICE_TYPE_NONE "NONE" # Unknown +setvar DEVICE_TYPE_DISK "DISK" # GEOM `DISK' +setvar DEVICE_TYPE_FLOPPY "FD" # GEOM `FD' +setvar DEVICE_TYPE_FTP "FTP" # Dynamic network device +setvar DEVICE_TYPE_NETWORK "NETWORK" # See f_device_get_all_network +setvar DEVICE_TYPE_CDROM "CDROM" # GEOM `DISK' +setvar DEVICE_TYPE_USB "USB" # GEOM `PART' +setvar DEVICE_TYPE_DOS "DOS" # GEOM `DISK' `PART' or `LABEL' +setvar DEVICE_TYPE_UFS "UFS" # GEOM `DISK' `PART' or `LABEL' +setvar DEVICE_TYPE_NFS "NFS" # Dynamic network device +setvar DEVICE_TYPE_HTTP_PROXY "HTTP_PROXY" # Dynamic network device +setvar DEVICE_TYPE_HTTP "HTTP" # Dynamic network device + +# Network devices have the following flags available +setvar IF_ETHERNET 1 +setvar IF_WIRELESS 2 +setvar IF_ACTIVE 4 + +# +# Default behavior is to call f_device_get_all() automatically when loaded. +# +: ${DEVICE_SELF_SCAN_ALL=1} + +# +# Device Catalog variables +# +DEVICE_CATALOG_APPEND_ONLY= # Used by f_device_catalog_set() +NCATALOG_DEVICES=0 # Used by f_device_catalog_*() and MAIN + +# +# A ``catalog'' device is for mapping GEOM devices to media devices (for +# example, determining if a $GEOM_CLASS_DISK geom is $DEVICE_TYPE_CDROM or +# $DEVICE_TYPE_DISK) and also getting default descriptions for devices that +# either lack a GEOM provided description or lack a presence in GEOM) +# +f_struct_define CATALOG_DEVICE \ + desc \ + name \ + type + +############################################################ FUNCTIONS + +# f_device_register $var_to_set $name $desc $devname $type $enabled +# $init_function $get_function $shutdown_function +# $private $capacity +# +# Register a device. A `structure' (see struct.subr) is created and if +# $var_to_set is non-NULL, upon success holds the name of the struct created. +# The remaining positional arguments correspond to the properties of the +# `DEVICE' structure-type to be assigned (defined above). +# +# If not already registered (based on $name and $type), a new device is created +# and $NDEVICES is incremented. +# +f_device_register() +{ + local __var_to_set="$1" __name="$2" __desc="$3" __devname="$4" + local __type="$5" __enabled="$6" __init_func="$7" __get_func="$8" + local __shutdown_func="$9" __private="${10}" __capacity="${11}" + + # Required parameter(s) + [ "$__name" ] || return $FAILURE + if [ "$__var_to_set" ]; then + setvar "$__var_to_set" "" || return $FAILURE + fi + + local __device + if f_device_find -1 "$__name" "$__type" __device; then + f_struct_free "$__device" + f_struct_new DEVICE "$__device" || return $FAILURE + else + __device=device_$(( NDEVICES + 1 )) + f_struct_new DEVICE "$__device" || return $FAILURE + NDEVICES=$(( $NDEVICES + 1 )) + fi + $__device set name "$__name" + $__device set desc "$__desc" + $__device set devname "$__devname" + $__device set type "$__type" + $__device set enabled "$__enabled" + $__device set init "$__init_func" + $__device set get "$__get_func" + $__device set shutdown "$__shutdown_func" + $__device set private "$__private" + $__device set capacity "$__capacity" + + [ "$__var_to_set" ] && setvar "$__var_to_set" "$__device" + return $SUCCESS +} + +# f_device_reset +# +# Reset the registered device chain. +# +f_device_reset() +{ + local n=1 + while [ $n -le $NDEVICES ]; do + f_device_shutdown device_$n + + # + # XXX This potentially leaks $dev->private if it's being + # used to point to something dynamic, but you're not supposed + # to call this routine at such times that some open instance + # has its private member pointing somewhere anyway. + # + f_struct_free device_$n + + n=$(( $n + 1 )) + done + NDEVICES=0 +} + +# f_device_reset_network +# +# Reset the registered network device chain. +# +f_device_reset_network() +{ + local n=1 device type private i + while [ $n -le $NDEVICES ]; do + device=device_$n + f_struct $device || continue + $device get type type + [ "$type" = "$DEVICE_TYPE_NETWORK" ] || continue + + # + # Leave the device up (don't call shutdown routine) + # + + # Network devices may have DEVICE_INFO private member + $device get private private + [ "$private" ] && f_struct_free "$private" + + # Free the network device + f_struct_free $device + + # Fill the gap we just created + i=$n + while [ $i -lt $NDEVICES ]; do + f_struct_copy device_$(( $i + 1 )) device_$i + done + f_struct_free device_$NDEVICES + + # Finally decrement the number of devices + NDEVICES=$(( $NDEVICES - 1 )) + + n=$(( $n + 1 )) + done +} + +# f_device_get_all +# +# Get all device information for all devices. +# +f_device_get_all() +{ + local devname type desc capacity + + f_dprintf "f_device_get_all: Probing devices..." + f_dialog_info "$msg_probing_devices_please_wait_this_can_take_a_while" + + # First go for the network interfaces + f_device_get_all_network + + # Next, go for the GEOM devices we might want to use as media + local geom geoms geom_name + debug= f_geom_find "" $GEOM_CLASS_DEV geoms + for geom in $geoms; do + if ! f_device_probe_geom $geom; then + debug= $geom get name geom_name + f_dprintf "WARNING! Unable to classify %s as %s" \ + "GEOM device $geom_name" "media source" + fi + done +} + +# f_device_get_all_network +# +# Get all network device information for attached network devices. +# +f_device_get_all_network() +{ + local devname desc device flags + for devname in $( ifconfig -l ); do + # Eliminate network devices that don't make sense + case "$devname" in + lo*) continue ;; + esac + + # Try and find its description + f_device_desc "$devname" $DEVICE_TYPE_NETWORK desc + + f_dprintf "Found network device named %s" "$devname" + debug= f_device_register device $devname "$desc" \ + "$devname" $DEVICE_TYPE_NETWORK 1 \ + f_media_init_network "" f_media_shutdown_network "" -1 + + # Set flags based on media and status + flags=0 + eval "$( ifconfig $devname 2> /dev/null | awk -v var=flags ' + function _or(var, mask) { + printf "%s=$(( $%s | $%s ))\n", var, var, mask + } + BEGIN { S = "[[:space:]]+" } + { + if (!match($0, "^" S "(media|status):" S)) next + value = substr($0, RLENGTH + 1) + if ($1 == "media:") { + if (value ~ /Ethernet/) _or(var, "IF_ETHERNET") + if (value ~ /802\.11/) _or(var, "IF_WIRELESS") + } else if ($1 == "status:") { + if (value ~ /^active/) _or(var, "IF_ACTIVE") + } + }' )" + $device set flags $flags + done +} + +# f_device_rescan +# +# Rescan all devices, after closing previous set - convenience function. +# +f_device_rescan() +{ + f_device_reset + f_geom_rescan + f_device_get_all +} + +# f_device_rescan_network +# +# Rescan all network devices, after closing previous set - for convenience. +# +f_device_rescan_network() +{ + f_device_reset_network + f_device_get_all_network +} + +# f_device_probe_geom $geom +# +# Probe a single GEOM device and if it can be classified as a media source, +# register it using f_device_register() with known type-specific arguments. +# +f_device_probe_geom() +{ + local geom="$1" + + f_struct "$geom" || return $FAILURE + + # geom associated variables + local geom_name geom_consumer provider_ref geom_provider= + local provider_geom provider_config provider_class= + local provider_config_type catalog_struct catalog_type + local disk_ident + + # gnop(8)/geli(8) associated variables (p for `parent device') + local p_devname p_geom p_consumer p_provider_ref p_provider + local p_provider_config p_provider_geom p_provider_class + + # md(4) associated variables + local config config_type config_file magic= + + # Temporarily disable debugging to keep debug output light + local old_debug="$debug" debug= + + # + # Get the GEOM name (for use below in device registration) + # + $geom get name devname || continue + + # + # Attempt to get the consumer, provider, provider config, and + # provider class for this geom (errors ignored). + # + # NB: Each GEOM in the `DEV' class should have one consumer. + # That consumer should have a reference to its provider. + # + $geom get consumer1 geom_consumer + f_struct "$geom_consumer" get provider_ref provider_ref && + f_geom_find_by id "$provider_ref" provider geom_provider + if f_struct "$geom_provider"; then + $geom_provider get config provider_config + f_geom_parent $geom_provider provider_geom && + f_geom_parent $provider_geom provider_class + fi + + # + # Get values for device registration (errors ignored) + # + f_struct "$provider_class" get name type + f_struct "$geom_provider" get mediasize capacity + f_struct "$provider_config" get descr desc + + # + # For gnop(8), geli(8), or combination thereof, change device type to + # that of the consumer + # + p_devname= p_geom= p_provider= p_provider_config= + case "$devname" in + *.nop.eli) p_devname="${devname%.nop.eli}" ;; + *.eli.nop) p_devname="${devname%.eli.nop}" ;; + *.eli) p_devname="${devname%.eli}" ;; + *.nop) p_devname="${devname%.nop}" ;; + esac + [ "$p_devname" ] && f_geom_find "$p_devname" $GEOM_CLASS_DEV p_geom + if [ "${p_geom:-$geom}" != "$geom" ]; then + f_struct "$p_geom" get consumer1 p_consumer + f_struct "$p_consumer" get provider_ref p_provider_ref && + f_geom_find_by id "$p_provider_ref" provider p_provider + if f_struct "$p_provider"; then + $p_provider get config p_provider_config + f_geom_parent $p_provider p_provider_geom && + f_geom_parent $p_provider_geom p_provider_class + fi + f_struct "$p_provider_class" get name type + fi + + # Look up geom device in device catalog for default description + f_device_catalog_get \ + $DEVICE_TYPE_ANY "${p_devname:-$devname}" catalog_struct + [ "$desc" ] || f_struct "catalog_device_$catalog_struct" get desc desc + + # Use device catalog entry for potential re-classification(s) + f_struct "catalog_device_$catalog_struct" get type catalog_type + + # Restore debugging for this next part (device registration) + debug="$old_debug" + + # + # Register the device + # + local retval device + case "$type" in + $GEOM_CLASS_DISK) + # First attempt to classify by device catalog (see MAIN) + case "$catalog_type" in + $DEVICE_TYPE_CDROM) + f_dprintf "Found CDROM device for disk %s" "$devname" + debug= f_device_register device "$devname" "$desc" \ + "/dev/$devname" $DEVICE_TYPE_CDROM 1 \ + f_media_init_cdrom f_media_get_cdrom \ + f_media_shutdown_cdrom "" "$capacity" && + return $SUCCESS + ;; + esac + + # Fall back to register label device as a disk and taste it + f_dprintf "Found disk device named %s" "$devname" + debug= f_struct "$p_provider_config" get \ + ident disk_ident || + debug= f_struct "$provider_config" get \ + ident disk_ident + debug= f_device_register device "$devname" "$desc" \ + "/dev/$devname" $DEVICE_TYPE_DISK 1 \ + "" "" "" "$disk_ident" "$capacity" + retval=$? + + # Detect ``dangerously dedicated'' filesystems (errors ignored) + f_device_probe_disk_fs device "$devname" "$capacity" && + retval=$SUCCESS + + return $retval + ;; + $GEOM_CLASS_FD) + f_dprintf "Found floppy device named %s" "$devname" + debug= f_device_register device "$devname" "$desc" \ + "/dev/$devname" $DEVICE_TYPE_FLOPPY 1 \ + f_media_init_floppy f_media_get_floppy \ + f_media_shutdown_floppy "" "$capacity" + return $? + ;; + $GEOM_CLASS_LABEL) + : fall through to below section # reduces indentation level + ;; + $GEOM_CLASS_MD) + f_dprintf "Found disk device named %s" "$devname" + debug= f_device_register device "$devname" "$desc" \ + "/dev/$devname" $DEVICE_TYPE_DISK 1 \ + "" "" "" "" "$capacity" + retval=$? + + # + # Attempt to get file(1) magic to potentially classify as + # alternate media type. If unable to get magic, fall back to + # md(4) characteristics (such as vnode filename). + # + [ -r "/dev/$devname" ] && + magic=$( file -bs "/dev/$devname" 2> /dev/null ) + if [ ! "$magic" ]; then + # Fall back to md(4) characteristics + if f_struct "$p_provider_config"; then + config="$p_provider_config" + else + config="$provider_config" + fi + debug= f_struct "$config" get type config_type + debug= f_struct "$config" get file config_file + + # Substitute magic for below based on type and file + case "$config_type=$config_file" in + vnode=*.iso) magic="ISO 9660" ;; + esac + fi + f_device_probe_disk_fs device \ + "$devname" "$capacity" "$magic" && + retval=$SUCCESS # Errors ignored + + return $retval + ;; + $GEOM_CLASS_PART) + if f_struct "$p_provider_config"; then + config="$p_provider_config" + else + config="$provider_config" + fi + debug= f_struct "$config" get type provider_config_type + f_device_probe_geom_part device \ + "$provider_config_type" "$devname" "$capacity" + retval=$? + device_type=$DEVICE_TYPE_NONE + [ $retval -eq $SUCCESS ] && + debug= f_struct "$device" get type device_type + + # Potentially re-classify as USB device + if [ "$device_type" = "$DEVICE_TYPE_UFS" -a \ + "$catalog_type" = "$DEVICE_TYPE_USB" ] + then + f_dprintf "Found USB device for partition %s" \ + "$devname" + debug= f_struct "$p_provider_geom" get \ + name disk_name || + debug= f_struct "$provider_geom" get \ + name disk_name + debug= f_device_register device "$devname" "$desc" \ + "/dev/$devname" $DEVICE_TYPE_USB 1 \ + f_media_init_usb f_media_get_usb \ + f_media_shutdown_usb "$disk_name" "$capacity" + retval=$? + fi + + return $retval + ;; + $GEOM_CLASS_RAID) + # Use the provider geom name as the description + if [ ! "$desc" ]; then + f_struct "$p_provider_geom" get name desc || + f_struct "$provider_geom" get name desc + fi + + f_dprintf "Found disk device named %s" "$devname" + debug= f_device_register device \ + "$devname" "${desc:-GEOM RAID device}" \ + "/dev/$devname" $DEVICE_TYPE_DISK 1 \ + "" "" "" "" "$capacity" + retval=$? + + # Detect ``dangerously dedicated'' filesystems + f_device_probe_disk_fs device "$devname" "$capacity" && + retval=$SUCCESS # Errors ignored + + return $retval + ;; + $GEOM_CLASS_ZFS_ZVOL) + f_dprintf "Found disk device named %s" "$devname" + debug= f_device_register device \ + "$devname" "${desc:-GEOM ZFS::ZVOL device}" \ + "/dev/$devname" $DEVICE_TYPE_DISK 1 \ + "" "" "" "" "$capacity" + retval=$? + + # Detect ``dangerously dedicated'' filesystems + f_device_probe_disk_fs device "$devname" "$capacity" && + retval=$SUCCESS # Errors ignored + + return $retval + ;; + *) + return $FAILURE # Unknown GEOM class + esac + + # + # Still here? Must be $GEOM_CLASS_LABEL + # + + local label_geom label_devname label_devgeom= label_devconsumer + local label_devprovider= label_devprovider_ref label_devprovider_config + local label_gpart_type + + if f_struct "$p_provider"; then + label_geom="$p_provider_geom" + else + label_geom="$provider_geom" + fi + + case "$devname" in + gpt/*|gptid/*) + # + # Attempt to get the partition type by getting the `config' + # member of the provider for our device (which is named in the + # parent geom of our current provider). + # + debug= f_struct "$label_geom" get name label_devname && + debug= f_geom_find "$label_devname" $GEOM_CLASS_DEV \ + label_devgeom + debug= f_struct "$label_devgeom" get \ + consumer1 label_devconsumer + debug= f_struct "$label_devconsumer" get \ + provider_ref label_devprovider_ref && + debug= f_geom_find_by id "$label_devprovider_ref" \ + provider label_devprovider + debug= f_struct "$label_devprovider" get \ + config label_devprovider_config + debug= f_struct "$label_devprovider_config" get \ + type label_gpart_type + + # + # Register device label based on partition type + # + f_device_probe_geom_part device \ + "$label_gpart_type" "$devname" "$capacity" + return $? + ;; + iso9660/*) + f_dprintf "Found CDROM device labeled %s" "$devname" + debug= f_device_register device \ + "$devname" "ISO9660 file system" \ + "/dev/$devname" $DEVICE_TYPE_CDROM 1 \ + f_media_init_cdrom f_media_get_cdrom \ + f_media_shutdown_cdrom "" "$capacity" + return $? + ;; + label/*) + # For generic labels, use provider geom name as real device + debug= f_struct "$label_geom" get name label_devname + + # Look up label geom device in device catalog for default desc + debug= f_device_catalog_get \ + $DEVICE_TYPE_ANY "$label_devname" catalog_struct + [ "$desc" ] || debug= f_struct \ + "catalog_device_$catalog_struct" get desc desc + + # Use device catalog entry for potential re-classification(s) + debug= f_struct "catalog_device_$catalog_struct" get \ + type catalog_type + + # First attempt to classify by device catalog (see MAIN) + case "$catalog_type" in + $DEVICE_TYPE_CDROM) + f_dprintf "Found CDROM device for disk %s" "$devname" + debug= f_device_register device "$devname" "$desc" \ + "/dev/$devname" $DEVICE_TYPE_CDROM 1 \ + f_media_init_cdrom f_media_get_cdrom \ + f_media_shutdown_cdrom "" "$capacity" && + return $SUCCESS + ;; + esac + + # Fall back to register label device as a disk and taste it + f_dprintf "Found disk device labeled %s" "$devname" + debug= f_device_register device \ + "$devname" "GEOM LABEL device" \ + "/dev/$devname" $DEVICE_TYPE_DISK 1 \ + "" "" "" "" "$capacity" + retval=$? + + # Detect ``dangerously dedicated'' filesystems (errors ignored) + f_device_probe_disk_fs device "$devname" "$capacity" && + retval=$SUCCESS + + return $retval + ;; + msdosfs/*) + f_dprintf "Found DOS partition labeled %s" "$devname" + debug= f_device_register device "$devname" "DOS file system" \ + "/dev/$devname" $DEVICE_TYPE_DOS 1 \ + f_media_init_dos f_media_get_dos \ + f_media_shutdown_dos "" "$capacity" + return $? + ;; + ufs/*|ufsid/*) + f_dprintf "Found UFS partition labeled %s" "$devname" + debug= f_device_register device "$devname" "UFS file system" \ + "/dev/$devname" $DEVICE_TYPE_UFS 1 \ + f_media_init_ufs f_media_get_ufs \ + f_media_shutdown_ufs "" "$capacity" + return $? + ;; + ext2fs/*|ntfs/*|reiserfs/*) + return $FAILURE # No media device handlers for these labels + ;; + esac + + # Unable to classify GEOM label + return $FAILURE +} + +# f_device_probe_geom_part $var_to_set $gpart_type $devname $capacity [$magic] +# +# Given a gpart(8) partition type and a device name, register the device if it +# is a known partition type that we can handle. If $var_to_set is non-NULL, +# upon success holds the DEVICE struct name of the registered device. +# +# Returns success if the device was successfully registered, failure otherwise. +# +f_device_probe_geom_part() +{ + local __var_to_set="$1" __gpart_type="$2" __devname="$3" + local __capacity="${4:--1}" __magic="$5" + + # + # Register device based on partition type + # NB: !0 equates to `unused' bsdlabel + # + case "$__gpart_type" in + fat16|fat32) + f_dprintf "Found DOS partition named %s" "$__devname" + debug= f_device_register "$__var_to_set" \ + "$__devname" "DOS file system" \ + "/dev/$__devname" $DEVICE_TYPE_DOS 1 \ + f_media_init_dos f_media_get_dos \ + f_media_shutdown_dos "" "$__capacity" + return $? + ;; + freebsd|!0) # Commonly used inappropriately, taste for FreeBSD + [ -r "/dev/$__devname" -a ! "$__magic" ] && + __magic=$( file -bs "/dev/$__devname" 2> /dev/null ) + case "$__magic" in + *"Unix Fast File system"*) + f_dprintf "Found UFS partition named %s" "$__devname" + debug= f_device_register "$__var_to_set" \ + "$__devname" "UFS file system" \ + "/dev/$__devname" $DEVICE_TYPE_UFS 1 \ + f_media_init_ufs f_media_get_ufs \ + f_media_shutdown_ufs "" "$__capacity" + return $? + esac + return $FAILURE + ;; + freebsd-ufs) + f_dprintf "Found UFS partition named %s" "$__devname" + debug= f_device_register "$__var_to_set" \ + "$__devname" "UFS file system" \ + "/dev/$__devname" $DEVICE_TYPE_UFS 1 \ + f_media_init_ufs f_media_get_ufs \ + f_media_shutdown_ufs "" "$__capacity" + return $? + ;; + apple-*|linux-*|ms-*|netbsd-*|ntfs|vmware-*) + return $FAILURE # No device types for these + ;; + bios-*|ebr|efi|mbr|freebsd-boot|freebsd-swap) + return $FAILURE # Not a source for media + ;; + freebsd-nandfs|freebsd-vinum|freebsd-zfs) + return $FAILURE # Unsupported as media source + ;; + esac + + return $FAILURE # Unknown partition type +} + +# f_device_probe_disk_fs $var_to_set $devname [$capacity [$magic]] +# +# Given a device name, taste it and register the device if it is a so-called +# ``dangerously dedicated'' file system written without a partition table. +# Tasting is done using file(1) (specifically `file -bs') but if $magic is +# present and non-NULL it is used instead. If $var_to_set is non-NULL, upon +# success holds the DEVICE struct name of the registered device. +# +# Returns success if the device was successfully registered, failure otherwise. +# +f_device_probe_disk_fs() +{ + local __var_to_set="$1" __devname="$2" __capacity="${3:--1}" + local __magic="$4" + + [ -r "/dev/${__devname#/dev/}" -a ! "$__magic" ] && + __magic=$( file -bs "/dev/$__devname" 2> /dev/null ) + + case "$__magic" in + *"ISO 9660"*) + f_dprintf "Found CDROM device for disk %s" "$__devname" + debug= f_device_register "$__var_to_set" \ + "$__devname" "ISO9660 file system" \ + "/dev/$__devname" $DEVICE_TYPE_CDROM 1 \ + f_media_init_cdrom f_media_get_cdrom \ + f_media_shutdown_cdrom "" "$__capacity" + return $? + ;; + *"Unix Fast File system"*) + f_dprintf "Found UFS device for disk %s" "$__devname" + debug= f_device_register "$__var_to_set" \ + "$__devname" "UFS file system" \ + "/dev/$__devname" $DEVICE_TYPE_UFS 1 \ + f_media_init_ufs f_media_get_ufs \ + f_media_shutdown_ufs "" "$__capacity" + return $? + ;; + *"FAT (12 bit)"*|*"FAT (16 bit)"*|*"FAT (32 bit)"*) + f_dprintf "Found DOS device for disk %s" "$__devname" + debug= f_device_register "$__var_to_set" \ + "$__devname" "DOS file system" \ + "/dev/$__devname" $DEVICE_TYPE_DOS 1 \ + f_media_init_dos f_media_get_dos \ + f_media_shutdown_dos "" "$__capacity" + return $? + ;; + esac + + return $FAILURE # Unknown file system type +} + +# f_device_catalog_get $type $name [$var_to_set] +# +# Fetch the struct name of the catalog device matching device $name. If $type +# is either NULL, missing, or set to $DEVICE_TYPE_ANY then only $name is used. +# Returns success if a match was found, otherwise failure. +# +# If $var_to_set is missing or NULL, the struct name is printed to standard out +# for capturing in a sub-shell (which is less-recommended because of +# performance degredation; for example, when called in a loop). +# +f_device_catalog_get() +{ + local __type="$1" __name="$2" __var_to_set="$3" + local __dname= + + # Return failure if no $name + [ "$__name" ] || return $FAILURE + + # Disable debugging to keep debug output light + local debug= + + # + # Attempt to create an alternate-form of $__name that contains the + # first contiguous string of numbers replaced with `%d' for comparison + # against stored pattern names (see MAIN). + # + local __left="${__name%%[0-9]*}" __right="${__name#*[0-9]}" + if [ "$__left" != "$__name" ]; then + # Chop leading digits from right 'til we hit first non-digit + while :; do + case "$__right" in + [0-9]*) __right="${__right#[0-9]}" ;; + *) break + esac + done + __dname="${__left}%d$__right" + fi + + [ "$__type" = "$DEVICE_TYPE_ANY" ] && __type= + local __dev __dev_name __dev_type + for __dev in $DEVICE_CATALOG; do + catalog_device_$__dev get name __dev_name + [ "$__dev_name" = "$__name" -o "$__dev_name" = "$__dname" ] || + continue + catalog_device_$__dev get type __dev_type + [ "${__type:-$__dev_type}" = "$__dev_type" ] || continue + if [ "$__var_to_set" ]; then + setvar "$__var_to_set" $__dev + else + echo $__dev + fi + return $? + done + + [ "$__var_to_set" ] && setvar "$__var_to_set" "" + return $FAILURE +} + +# f_device_catalog_set $type $name $desc +# +# Store a description (desc) in-association with device $type and $name. +# Returns success unless $name is NULL or missing. Use f_device_catalog_get() +# routine with the same $name and optionally $type to retrieve catalog device +# structure (see CATALOG_DEVICE struct definition in GLOBALS section). +# +f_device_catalog_set() +{ + local type="$1" name="$2" desc="$3" + local struct dev dev_type found= + + [ "$name" ] || return $FAILURE + + # Disable debugging to keep debug output light + local debug= + + f_str2varname "$name" struct + if [ ! "$DEVICE_CATALOG_APPEND_ONLY" ]; then + for dev in $DEVICE_CATALOG; do + [ "$dev" = "$struct" ] || continue + found=1 break + done + fi + if [ "$found" ]; then + f_struct_free "catalog_device_$struct" + else + DEVICE_CATALOG="$DEVICE_CATALOG $struct" + fi + f_struct_new CATALOG_DEVICE "catalog_device_$struct" || return $FAILURE + catalog_device_$struct set type "$type" + catalog_device_$struct set name "$name" + catalog_device_$struct set desc "$desc" + return $SUCCESS +} + +# f_device_desc $device_name $device_type [$var_to_set] +# +# Print a description for a device name (eg., `fxp0') given a specific device +# type/class. +# +# If $var_to_set is missing or NULL, the device description is printed to +# standard out for capturing in a sub-shell (which is less-recommended because +# of performance degredation; for example, when called in a loop). +# +f_device_desc() +{ + local __name="$1" __type="$2" __var_to_set="$3" + local __devname __devunit __cp + + # Check variables + [ "$__name" ] || return $SUCCESS + [ "$__type" = "$DEVICE_TYPE_ANY" ] && type= + [ "$__var_to_set" ] && { setvar "$__var_to_set" "" || return; } + + # + # Return sysctl MIB dev.NAME.UNIT.%desc if it exists, otherwise fall + # through to further alternate methods. + # + if f_have sysctl; then + __devname="${__name%%[0-9]*}" + __devunit="${__name#$__devname}" + __devunit="${__devunit%%[!0-9]*}" + if [ "$__var_to_set" ]; then + if __cp=$( + sysctl -n "dev.$__devname.$__devunit.%desc" \ + 2> /dev/null + ); then + setvar "$__var_to_set" "$__cp" && + return $SUCCESS + fi + else + sysctl -n "dev.$__devname.$__devunit.%desc" \ + 2> /dev/null && return $SUCCESS + fi + fi + + # Look up device in catalog for default description + local __catalog_struct + debug= f_device_catalog_get "$__type" "$__name" __catalog_struct + debug= f_struct "catalog_device_$__catalog_struct" get \ + desc "$__var_to_set" && return $SUCCESS + + # + # Sensible fall-backs for specific types + # + case "$__type" in + $DEVICE_TYPE_CDROM) __cp="<unknown cdrom device type>" ;; + $DEVICE_TYPE_DISK) __cp="<unknown disk device type>" ;; + $DEVICE_TYPE_FLOPPY) __cp="<unknown floppy device type>" ;; + $DEVICE_TYPE_USB) __cp="<unknown USB storage device type>" ;; + $DEVICE_TYPE_NETWORK) __cp="<unknown network interface type>" ;; + *) + __cp="<unknown device type>" + esac + + if [ "$__var_to_set" ]; then + setvar "$__var_to_set" "$__cp" + else + echo "$__cp" + fi + + return $FAILURE +} + +# f_device_is_ethernet $device +# +# Returns true if $device is a wired Ethernet network interface. Otherwise +# returns false. Example wired interfaces include: fxp0 em0 bge0 rl0 etc. +# +f_device_is_ethernet() +{ + local dev="$1" type flags + + # Make sure we have an actual device by that name + f_struct "$dev" || return $FAILURE + + # Make sure that the device is a network device + $dev get type type + [ "$type" = "$DEVICE_TYPE_NETWORK" ] || return $FAILURE + + # Make sure that the media flags indicate that it is Ethernet + $dev get flags flags + [ $(( ${flags:-0} & $IF_ETHERNET )) -eq $IF_ETHERNET ] +} + +# f_device_is_wireless $device +# +# Returns true if $device is a Wireless network interface. Otherwise returns +# false. Examples of wireless interfaces include: iwn0 +# +f_device_is_wireless() +{ + local dev="$1" type flags + + # Make sure we have an actual device by that name + f_struct "$dev" || return $FAILURE + + # Make sure that the device is a network device + $dev get type type + [ "$type" = "$DEVICE_TYPE_NETWORK" ] || return $FAILURE + + # Make sure that the media flags indicate that it is 802.11 wireless + $dev get flags flags + [ $(( ${flags:-0} & $IF_WIRELESS )) -eq $IF_WIRELESS ] +} + +# f_device_is_active $device +# +# Returns true if $device is active. Otherwise returns false. Currently this +# only works for network interfaces. +# +f_device_is_active() +{ + local dev="$1" type flags=0 + + # Make sure we have an actual device by that name + f_struct "$dev" || return $FAILURE + + $dev get type type + case "$type" in + $DEVICE_TYPE_NETWORK) + # Make sure that the media flags indicate that it is active + $dev get flags flags + [ $(( ${flags:-0} & $IF_ACTIVE )) -eq $IF_ACTIVE ] + ;; + *) + return $FAILURE + esac +} + +# f_device_find [-1] $name [$type [$var_to_set]] +# +# Find one or more registered devices by name, type, or both. Returns a space- +# separated list of devices matching the search criterion. +# +# If `-1' option flag is given, only the first matching device is returned. +# +# If $var_to_set is missing or NULL, the device name(s) are printed to standard +# out for capturing in a sub-shell (which is less-recommended because of +# performance degredation; for example, when called in a loop). +# +f_device_find() +{ + local OPTIND=1 OPTARG flag only_one= + while getopts 1 flag; do + case "$flag" in + 1) only_one=1 ;; + esac + done + shift $(( $OPTIND - 1 )) + + local __name="$1" __type="${2:-$DEVICE_TYPE_ANY}" __var_to_set="$3" + local __n=1 __devname __devtype __found= + while [ $__n -le $NDEVICES ]; do + device_$__n get name __devname + device_$__n get type __devtype + if [ "$__name" = "$__devname" -o ! "$__name" ] && + [ "$__type" = "$DEVICE_TYPE_ANY" -o \ + "$__type" = "$__devtype" ] + then + __found="$__found device_$__n" + [ "$only_one" ] && break + fi + __n=$(( $__n + 1 )) + done + + if [ "$__var_to_set" ]; then + setvar "$__var_to_set" "${__found# }" + else + echo $__found + fi + [ "$__found" ] # Return status +} + +# f_device_init $device +# +# Initialize a device by evaluating its `init' function. The $device argument +# is a DEVICE struct name. +# +f_device_init() +{ + local device="$1" init_func + f_struct "$device" || return $? + $device get init init_func + ${init_func:-:} "$device" +} + +# f_device_get $device $file [$probe] +# +# Read $file by evaluating the device's `get' function. The file is commonly +# produced on standard output (but it truly depends on the function called). +# The $device argument is a DEVICE struct name. +# +f_device_get() +{ + local device="$1" file="$2" probe="$3" get_func + f_struct "$device" || return $? + $device get get get_func + ${get_func:-:} "$device" "$file" ${3+"$probe"} +} + +# f_device_shutdown $device +# +# Shutdown a device by evaluating its `shutdown' function. The $device argument +# is a DEVICE struct name. +# +f_device_shutdown() +{ + local device="$1" shutdown_func + f_struct "$device" || return $? + $device get shutdown shutdown_func + ${shutdown_func:-:} "$device" +} + +# f_devices_sort_by $property $var_to_get [$var_to_set] +# +# Take list of devices from $var_to_get (separated by whitespace, newline +# included) and sort them by $property (e.g., `name'). The sorted list of +# DEVICE struct names is returned on standard output separated by whitespace +# (newline to be specific) unless $var_to_set is present and non-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_device_sort_by_awk=' +# Variables that should be defined on the invocation line: +# -v prop="property" +function _asorti(src, dest) +{ + k = nitems = 0 + for (i in src) dest[++nitems] = i + for (i = 1; i <= nitems; k = i++) { + idx = dest[i] + while ((k > 0) && (dest[k] > idx)) { + dest[k+1] = dest[k]; k-- + } + dest[k+1] = idx + } + return nitems +} +{ + split($0, devs, FS) + for (d in devs) { + name = ENVIRON["_struct_value_" devs[d] "_" prop] + devices[name] = devs[d] + } +} +END { + nitems = _asorti(devices, devices_sorted) + for (i = 1; i <= nitems; i++) print devices[devices_sorted[i]] +} +' +f_device_sort_by() +{ + local __property="${1:-name}" __var_to_get="$2" __var_to_set="$3" + + f_isset "$__var_to_get" || return $FAILURE + + local __dev + for __dev in $( f_getvar "$__var_to_get" ); do + export _struct_value_${__dev}_$__property + done + + local __cp + setvar "${__var_to_set:-__cp}" "$( + f_getvar "$__var_to_get" | + awk -v prop="$__property" "$f_device_sort_by_awk" + )" + [ "$__var_to_set" ] || echo "$__cp" +} + +# f_device_menu $title $prompt $hline $device_type [$helpfile] +# +# Display a menu listing all the devices of a certain type in the system. +# +f_device_menu() +{ + f_dialog_title "$1" + local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE" + f_dialog_title_restore + + local prompt="$2" hline="$3" type="$4" helpfile="$5" + + local devs + f_device_find "" "$type" devs || return $DIALOG_CANCEL + + local name desc menu_list= + f_device_sort_by name devs devs + for dev in $devs; do + $dev get name name + $dev get desc desc + f_shell_escape "$name" name + f_shell_escape "$desc" desc + menu_list="$menu_list + '$name' '$desc'" # END-QUOTE + done + menu_list="${menu_list#$NL}" + + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list + + local errexit= + case $- in *e*) errexit=1; esac + set +e + + local mtag + while :; do + mtag=$( eval $DIALOG \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + ${helpfile:+ \ + --help-button \ + --help-label \"\$msg_help\" \ + ${USE_XDIALOG:+--help \"\"} \ + } \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + local retval=$? + + [ $retval -ne $DIALOG_HELP ] && break + # Otherwise, the Help button was pressed + f_show_help "$helpfile" + # ...then loop back to menu + done + f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" + + [ "$errexit" ] && set -e + + if [ $retval -eq $DIALOG_OK ]; then + # Clean up the output of [X]dialog(1) + f_dialog_data_sanitize mtag + + # Map the user's choice back to a struct name + local index device + index=$( eval f_dialog_menutag2index \"\$mtag\" $menu_list ) + device=$( set -- $devs; eval echo \${$index} ) + + echo "$device" >&2 + fi + + return $retval +} + +# +# Short-hand +# +f_cdrom() { f_device_catalog_set $DEVICE_TYPE_CDROM "$1" "$2"; } +f_disk() { f_device_catalog_set $DEVICE_TYPE_DISK "$1" "$2"; } +f_floppy() { f_device_catalog_set $DEVICE_TYPE_FLOPPY "$1" "$2"; } +f_usb() { f_device_catalog_set $DEVICE_TYPE_USB "$1" "$2"; } +f_network() { f_device_catalog_set $DEVICE_TYPE_NETWORK "$1" "$2"; } + +############################################################ MAIN + +# +# The below classifications allow us to re-group the GEOM devices from the +# `DEV' GEOM class appropriately while providing fall-back descriptions both +# for making the below code more maintainable and handling the rare case the +# GEOM device lacks a description. +# + +DEVICE_CATALOG_APPEND_ONLY=1 # Make initial loading faster + +# CDROM, Disk, Floppy, and USB devices/names +f_cdrom "cd%d" "SCSI CDROM drive" +f_cdrom "mcd%d" "Mitsumi (old model) CDROM drive" +f_cdrom "scd%d" "Sony CDROM drive - CDU31/33A type" +f_disk "aacd%d" "Adaptec FSA RAID array" +f_disk "ada%d" "ATA/SATA disk device" +f_disk "amrd%d" "AMI MegaRAID drive" +f_disk "da%d" "SCSI disk device" +f_disk "idad%d" "Compaq RAID array" +f_disk "ipsd%d" "IBM ServeRAID RAID array" +f_disk "md%d" "md(4) disk device" +f_disk "mfid%d" "LSI MegaRAID SAS array" +f_disk "mlxd%d" "Mylex RAID disk" +f_disk "twed%d" "3ware ATA RAID array" +f_disk "vtbd%d" "VirtIO Block Device" +f_floppy "fd%d" "Floppy Drive unit A" +f_usb "da%da" "USB Mass Storage Device" + +# Network interfaces/names +f_network "ae%d" "Attansic/Atheros L2 Fast Ethernet" +f_network "age%d" "Attansic/Atheros L1 Gigabit Ethernet" +f_network "alc%d" "Atheros AR8131/AR8132 PCIe Ethernet" +f_network "ale%d" "Atheros AR8121/AR8113/AR8114 PCIe Ethernet" +f_network "an%d" "Aironet 4500/4800 802.11 wireless adapter" +f_network "ath%d" "Atheros IEEE 802.11 wireless adapter" +f_network "aue%d" "ADMtek USB Ethernet adapter" +f_network "axe%d" "ASIX Electronics USB Ethernet adapter" +f_network "bce%d" "Broadcom NetXtreme II Gigabit Ethernet card" +f_network "bfe%d" "Broadcom BCM440x PCI Ethernet card" +f_network "bge%d" "Broadcom BCM570x PCI Gigabit Ethernet card" +f_network "bm%d" "Apple BMAC Built-in Ethernet" +f_network "bwn%d" "Broadcom BCM43xx IEEE 802.11 wireless adapter" +f_network "cas%d" "Sun Cassini/Cassini+ or NS DP83065 Saturn Ethernet" +f_network "cc3i%d" "SDL HSSI sync serial PCI card" +f_network "cue%d" "CATC USB Ethernet adapter" +f_network "cxgb%d" "Chelsio T3 10Gb Ethernet card" +f_network "dc%d" "DEC/Intel 21143 (and clones) PCI Fast Ethernet card" +f_network "de%d" "DEC DE435 PCI NIC or other DC21040-AA based card" +f_network "disc%d" "Software discard network interface" +f_network "ed%d" "Novell NE1000/2000; 3C503; NE2000-compatible PCMCIA" +f_network "el%d" "3Com 3C501 Ethernet card" +f_network "em%d" "Intel(R) PRO/1000 Ethernet card" +f_network "ep%d" "3Com 3C509 Ethernet card/3C589 PCMCIA" +f_network "et%d" "Agere ET1310 based PCI Express Gigabit Ethernet card" +f_network "ex%d" "Intel EtherExpress Pro/10 Ethernet card" +f_network "fe%d" "Fujitsu MB86960A/MB86965A Ethernet card" +f_network "fpa%d" "DEC DEFPA PCI FDDI card" +f_network "fwe%d" "FireWire Ethernet emulation" +f_network "fwip%d" "IP over FireWire" +f_network "fxp%d" "Intel EtherExpress Pro/100B PCI Fast Ethernet card" +f_network "gem%d" "Apple GMAC or Sun ERI/GEM Ethernet adapter" +f_network "hme%d" "Sun HME (Happy Meal Ethernet) Ethernet adapter" +f_network "ie%d" "AT&T StarLAN 10 and EN100; 3Com 3C507; NI5210" +f_network "igb%d" "Intel(R) PRO/1000 PCI Express Gigabit Ethernet card" +f_network "ipw%d" "Intel PRO/Wireless 2100 IEEE 802.11 adapter" +f_network "iwi%d" "Intel PRO/Wireless 2200BG/2225BG/2915ABG adapter" +f_network "iwn%d" "Intel Wireless WiFi Link 4965AGN IEEE 802.11n adapter" +f_network "ix%d" "Intel Etherexpress Ethernet card" +f_network "ixgbe%d" "Intel(R) PRO/10Gb Ethernet card" +f_network "jme%d" "JMicron JMC250 Gigabit/JMC260 Fast Ethernet" +f_network "kue%d" "Kawasaki LSI USB Ethernet adapter" +f_network "le%d" "AMD Am7900 LANCE or Am79C9xx PCnet Ethernet adapter" +f_network "lge%d" "Level 1 LXT1001 Gigabit Ethernet card" +f_network "lnc%d" "Lance/PCnet (Isolan/Novell NE2100/NE32-VL) Ethernet" +f_network "lo%d" "Loop-back (local) network interface" +f_network "lp%d" "Parallel Port IP (PLIP) peer connection" +f_network "malo%d" "Marvell Libertas 88W8335 802.11 wireless adapter" +f_network "msk%d" "Marvell/SysKonnect Yukon II Gigabit Ethernet" +f_network "mxge%d" "Myricom Myri10GE 10Gb Ethernet card" +f_network "nfe%d" "NVIDIA nForce MCP Ethernet" +f_network "ng%d" "Vimage netgraph(4) bridged Ethernet device" +f_network "nge%d" "NatSemi PCI Gigabit Ethernet card" +f_network "nve%d" "NVIDIA nForce MCP Ethernet" +f_network "pcn%d" "AMD Am79c79x PCI Ethernet card" +f_network "plip%d" "Parallel Port IP (PLIP) peer connection" +f_network "ral%d" "Ralink Technology IEEE 802.11 wireless adapter" +f_network "ray%d" "Raytheon Raylink 802.11 wireless adapter" +f_network "re%d" "RealTek 8139C+/8169/8169S/8110S PCI Ethernet adapter" +f_network "rl%d" "RealTek 8129/8139 PCI Ethernet card" +f_network "rue%d" "RealTek USB Ethernet card" +f_network "rum%d" "Ralink Technology USB IEEE 802.11 wireless adapter" +f_network "sf%d" "Adaptec AIC-6915 PCI Ethernet card" +f_network "sge%d" "Silicon Integrated Systems SiS190/191 Ethernet" +f_network "sis%d" "SiS 900/SiS 7016 PCI Ethernet card" +f_network "sk%d" "SysKonnect PCI Gigabit Ethernet card" +f_network "sn%d" "SMC/Megahertz Ethernet card" +f_network "snc%d" "SONIC Ethernet card" +f_network "sr%d" "SDL T1/E1 sync serial PCI card" +f_network "ste%d" "Sundance ST201 PCI Ethernet card" +f_network "stge%d" "Sundance/Tamarack TC9021 Gigabit Ethernet" +f_network "ti%d" "Alteon Networks PCI Gigabit Ethernet card" +f_network "tl%d" "Texas Instruments ThunderLAN PCI Ethernet card" +f_network "tx%d" "SMC 9432TX Ethernet card" +f_network "txp%d" "3Com 3cR990 Ethernet card" +f_network "uath%d" "Atheros AR5005UG and AR5005UX USB wireless adapter" +f_network "upgt%d" "Conexant/Intersil PrismGT USB wireless adapter" +f_network "ural%d" "Ralink Technology RT2500USB 802.11 wireless adapter" +f_network "urtw%d" "Realtek 8187L USB wireless adapter" +f_network "vge%d" "VIA VT612x PCI Gigabit Ethernet card" +f_network "vlan%d" "IEEE 802.1Q VLAN network interface" +f_network "vr%d" "VIA VT3043/VT86C100A Rhine PCI Ethernet card" +f_network "vx%d" "3COM 3c590 / 3c595 Ethernet card" +f_network "wb%d" "Winbond W89C840F PCI Ethernet card" +f_network "wi%d" "Lucent WaveLAN/IEEE 802.11 wireless adapter" +f_network "wpi%d" "Intel 3945ABG IEEE 802.11 wireless adapter" +f_network "wx%d" "Intel Gigabit Ethernet (82452) card" +f_network "xe%d" "Xircom/Intel EtherExpress Pro100/16 Ethernet card" +f_network "xl%d" "3COM 3c90x / 3c90xB PCI Ethernet card" +f_network "zyd%d" "ZyDAS ZD1211/ZD1211B USB 802.11 wireless adapter" + +DEVICE_CATALOG_APPEND_ONLY= # Additional loading modifies existing devices + +f_count NCATALOG_DEVICES $DEVICE_CATALOG +f_dprintf "%s: Initialized device catalog with %u names/descriptions." \ + device.subr $NCATALOG_DEVICES + +# +# Scan for the above devices unless requeted otherwise +# +f_dprintf "%s: DEVICE_SELF_SCAN_ALL=[%s]" device.subr "$DEVICE_SELF_SCAN_ALL" +case "$DEVICE_SELF_SCAN_ALL" in +""|0|[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee]) : do nothing ;; +*) f_device_get_all +esac + +f_dprintf "%s: Successfully loaded." device.subr + +fi # ! $_DEVICE_SUBR diff --git a/bsdconfig/share/dialog.subr b/bsdconfig/share/dialog.subr new file mode 100644 index 000000000000..5b5c8a32984e --- /dev/null +++ b/bsdconfig/share/dialog.subr @@ -0,0 +1,2339 @@ +if [ ! "$_DIALOG_SUBR" ]; then _DIALOG_SUBR=1 +# +# Copyright (c) 2006-2015 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." dialog.subr +f_include $BSDCFG_SHARE/strings.subr +f_include $BSDCFG_SHARE/variable.subr + +BSDCFG_LIBE="/usr/libexec/bsdconfig" +f_include_lang $BSDCFG_LIBE/include/messages.subr + +############################################################ CONFIGURATION + +# +# Default file descriptor to link to stdout for dialog(1) passthru allowing +# execution of dialog from within a sub-shell (so-long as its standard output +# is explicitly redirected to this file descriptor). +# +: ${DIALOG_TERMINAL_PASSTHRU_FD:=${TERMINAL_STDOUT_PASSTHRU:-3}} + +############################################################ GLOBALS + +# +# Default name of dialog(1) utility +# NOTE: This is changed to "Xdialog" by the optional `-X' argument +# +DIALOG="dialog" + +# +# Default dialog(1) title and backtitle text +# +DIALOG_TITLE="$pgm" +DIALOG_BACKTITLE="bsdconfig" + +# +# Settings used while interacting with dialog(1) +# +DIALOG_MENU_TAGS="123456789ABCDEFGHIJKLMNOPQRSTUVWYZabcdefghijklmnopqrstuvwxyz" + +# +# Declare that we are fully-compliant with Xdialog(1) by unset'ing all +# compatibility settings. +# +unset XDIALOG_HIGH_DIALOG_COMPAT +unset XDIALOG_FORCE_AUTOSIZE +unset XDIALOG_INFOBOX_TIMEOUT + +# +# Exit codes for [X]dialog(1) +# +DIALOG_OK=${SUCCESS:-0} +DIALOG_CANCEL=${FAILURE:-1} +DIALOG_HELP=2 +DIALOG_EXTRA=3 +DIALOG_ITEM_HELP=4 +export DIALOG_ERROR=254 # sh(1) can't handle the default of `-1' +DIALOG_ESC=255 + +# +# Default behavior is to call f_dialog_init() automatically when loaded. +# +: ${DIALOG_SELF_INITIALIZE=1} + +# +# Default terminal size (used if/when running without a controlling terminal) +# +: ${DEFAULT_TERMINAL_SIZE:=24 80} + +# +# Minimum width(s) for various dialog(1) implementations (sensible global +# default(s) for all widgets of a given variant) +# +: ${DIALOG_MIN_WIDTH:=24} +: ${XDIALOG_MIN_WIDTH:=35} + +# +# When manually sizing Xdialog(1) widgets such as calendar and timebox, you'll +# need to know the size of the embedded GUI objects because the height passed +# to Xdialog(1) for these widgets has to be tall enough to accommodate them. +# +# These values are helpful when manually sizing with dialog(1) too, but in a +# different way. dialog(1) does not make you accommodate the custom items in the +# height (but does for width) -- a height of 3 will display three lines and a +# full calendar, for example (whereas Xdialog will truncate the calendar if +# given a height of 3). For dialog(1), use these values for making sure that +# the height does not exceed max_height (obtained by f_dialog_max_size()). +# +DIALOG_CALENDAR_HEIGHT=15 +DIALOG_TIMEBOX_HEIGHT=6 + +############################################################ GENERIC FUNCTIONS + +# f_dialog_data_sanitize $var_to_edit ... +# +# When using dialog(1) or Xdialog(1) sometimes unintended warnings or errors +# are generated from underlying libraries. For example, if $LANG is set to an +# invalid or unknown locale, the warnings from the Xdialog(1) libraries will +# clutter the output. This function helps by providing a centralied function +# that removes spurious warnings from the dialog(1) (or Xdialog(1)) response. +# +# Simply pass the name of one or more variables that need to be sanitized. +# After execution, the variables will hold their newly-sanitized data. +# +f_dialog_data_sanitize() +{ + if [ "$#" -eq 0 ]; then + f_dprintf "%s: called with zero arguments" \ + f_dialog_response_sanitize + return $FAILURE + fi + + local __var_to_edit + for __var_to_edit in $*; do + # Skip warnings and trim leading/trailing whitespace + setvar $__var_to_edit "$( f_getvar $__var_to_edit | awk ' + BEGIN { data = 0 } + { + if ( ! data ) + { + if ( $0 ~ /^$/ ) next + if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next + data = 1 + } + print + } + ' )" + done +} + +# f_dialog_line_sanitize $var_to_edit ... +# +# When using dialog(1) or Xdialog(1) sometimes unintended warnings or errors +# are generated from underlying libraries. For example, if $LANG is set to an +# invalid or unknown locale, the warnings from the Xdialog(1) libraries will +# clutter the output. This function helps by providing a centralied function +# that removes spurious warnings from the dialog(1) (or Xdialog(1)) response. +# +# Simply pass the name of one or more variables that need to be sanitized. +# After execution, the variables will hold their newly-sanitized data. +# +# This function, unlike f_dialog_data_sanitize(), also removes leading/trailing +# whitespace from each line. +# +f_dialog_line_sanitize() +{ + if [ "$#" -eq 0 ]; then + f_dprintf "%s: called with zero arguments" \ + f_dialog_response_sanitize + return $FAILURE + fi + + local __var_to_edit + for __var_to_edit in $*; do + # Skip warnings and trim leading/trailing whitespace + setvar $__var_to_edit "$( f_getvar $__var_to_edit | awk ' + BEGIN { data = 0 } + { + if ( ! data ) + { + if ( $0 ~ /^$/ ) next + if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next + data = 1 + } + sub(/^[[:space:]]*/, "") + sub(/[[:space:]]*$/, "") + print + } + ' )" + done +} + +############################################################ TITLE FUNCTIONS + +# f_dialog_title [$new_title] +# +# Set the title of future dialog(1) ($DIALOG_TITLE) or backtitle of Xdialog(1) +# ($DIALOG_BACKTITLE) invocations. If no arguments are given or the first +# argument is NULL, the current title is returned. +# +# Each time this function is called, a backup of the current values is made +# allowing a one-time (single-level) restoration of the previous title using +# the f_dialog_title_restore() function (below). +# +f_dialog_title() +{ + local new_title="$1" + + if [ "${1+set}" ]; then + if [ "$USE_XDIALOG" ]; then + _DIALOG_BACKTITLE="$DIALOG_BACKTITLE" + DIALOG_BACKTITLE="$new_title" + else + _DIALOG_TITLE="$DIALOG_TITLE" + DIALOG_TITLE="$new_title" + fi + else + if [ "$USE_XDIALOG" ]; then + echo "$DIALOG_BACKTITLE" + else + echo "$DIALOG_TITLE" + fi + fi +} + +# f_dialog_title_restore +# +# Restore the previous title set by the last call to f_dialog_title(). +# Restoration is non-recursive and only works to restore the most-recent title. +# +f_dialog_title_restore() +{ + if [ "$USE_XDIALOG" ]; then + DIALOG_BACKTITLE="$_DIALOG_BACKTITLE" + else + DIALOG_TITLE="$_DIALOG_TITLE" + fi +} + +# f_dialog_backtitle [$new_backtitle] +# +# Set the backtitle of future dialog(1) ($DIALOG_BACKTITLE) or title of +# Xdialog(1) ($DIALOG_TITLE) invocations. If no arguments are given or the +# first argument is NULL, the current backtitle is returned. +# +f_dialog_backtitle() +{ + local new_backtitle="$1" + + if [ "${1+set}" ]; then + if [ "$USE_XDIALOG" ]; then + _DIALOG_TITLE="$DIALOG_TITLE" + DIALOG_TITLE="$new_backtitle" + else + _DIALOG_BACKTITLE="$DIALOG_BACKTITLE" + DIALOG_BACKTITLE="$new_backtitle" + fi + else + if [ "$USE_XDIALOG" ]; then + echo "$DIALOG_TITLE" + else + echo "$DIALOG_BACKTITLE" + fi + fi +} + +# f_dialog_backtitle_restore +# +# Restore the previous backtitle set by the last call to f_dialog_backtitle(). +# Restoration is non-recursive and only works to restore the most-recent +# backtitle. +# +f_dialog_backtitle_restore() +{ + if [ "$USE_XDIALOG" ]; then + DIALOG_TITLE="$_DIALOG_TITLE" + else + DIALOG_BACKTITLE="$_DIALOG_BACKTITLE" + fi +} + +############################################################ SIZE FUNCTIONS + +# f_dialog_max_size $var_height $var_width +# +# Get the maximum height and width for a dialog widget and store the values in +# $var_height and $var_width (respectively). +# +f_dialog_max_size() +{ + local funcname=f_dialog_max_size + local __var_height="$1" __var_width="$2" __max_size + [ "$__var_height" -o "$__var_width" ] || return $FAILURE + if [ "$USE_XDIALOG" ]; then + __max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION + else + if __max_size=$( $DIALOG --print-maxsize \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) + then + f_dprintf "$funcname: %s --print-maxsize = [%s]" \ + "$DIALOG" "$__max_size" + # usually "MaxSize: 24, 80" + __max_size="${__max_size#*: }" + f_replaceall "$__max_size" "," "" __max_size + else + f_eval_catch -dk __max_size $funcname stty \ + 'stty size' || __max_size= + # usually "24 80" + fi + : ${__max_size:=$DEFAULT_TERMINAL_SIZE} + fi + if [ "$__var_height" ]; then + local __height="${__max_size%%[$IFS]*}" + # + # If we're not using Xdialog(1), we should assume that $DIALOG + # will render --backtitle behind the widget. In such a case, we + # should prevent a widget from obscuring the backtitle (unless + # $NO_BACKTITLE is set and non-NULL, allowing a trap-door). + # + if [ ! "$USE_XDIALOG" ] && [ ! "$NO_BACKTITLE" ]; then + # + # If use_shadow (in ~/.dialogrc) is OFF, we need to + # subtract 4, otherwise 5. However, don't check this + # every time, rely on an initialization variable set + # by f_dialog_init(). + # + local __adjust=5 + [ "$NO_SHADOW" ] && __adjust=4 + + # Don't adjust height if already too small (allowing + # obscured backtitle for small values of __height). + [ ${__height:-0} -gt 11 ] && + __height=$(( $__height - $__adjust )) + fi + setvar "$__var_height" "$__height" + fi + [ "$__var_width" ] && setvar "$__var_width" "${__max_size##*[$IFS]}" +} + +# f_dialog_size_constrain $var_height $var_width [$min_height [$min_width]] +# +# Modify $var_height to be no-less-than $min_height (if given; zero otherwise) +# and no-greater-than terminal height (or screen height if $USE_XDIALOG is +# set). +# +# Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or +# $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal +# or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by +# passing $min_width. +# +# Return status is success unless one of the passed arguments is invalid +# or all of the $var_* arguments are either NULL or missing. +# +f_dialog_size_constrain() +{ + local __var_height="$1" __var_width="$2" + local __min_height="$3" __min_width="$4" + local __retval=$SUCCESS + + # Return failure unless at least one var_* argument is passed + [ "$__var_height" -o "$__var_width" ] || return $FAILURE + + # + # Print debug warnings if any given (non-NULL) argument are invalid + # NOTE: Don't change the name of $__{var,min,}{height,width} + # + local __height __width + local __arg __cp __fname=f_dialog_size_constrain + for __arg in height width; do + debug= f_getvar __var_$__arg __cp + [ "$__cp" ] || continue + if ! debug= f_getvar "$__cp" __$__arg; then + f_dprintf "%s: var_%s variable \`%s' not set" \ + $__fname $__arg "$__cp" + __retval=$FAILURE + elif ! eval f_isinteger \$__$__arg; then + f_dprintf "%s: var_%s variable value not a number" \ + $__fname $__arg + __retval=$FAILURE + fi + done + for __arg in height width; do + debug= f_getvar __min_$__arg __cp + [ "$__cp" ] || continue + f_isinteger "$__cp" && continue + f_dprintf "%s: min_%s value not a number" $__fname $__arg + __retval=$FAILURE + setvar __min_$__arg "" + done + + # Obtain maximum height and width values + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __max_height_size_constain __max_width_size_constrain + f_dialog_max_size \ + __max_height_size_constrain __max_width_size_constrain + + # Adjust height if desired + if [ "$__var_height" ]; then + if [ $__height -lt ${__min_height:-0} ]; then + setvar "$__var_height" $__min_height + elif [ $__height -gt $__max_height_size_constrain ]; then + setvar "$__var_height" $__max_height_size_constrain + fi + fi + + # Adjust width if desired + if [ "$__var_width" ]; then + if [ "$USE_XDIALOG" ]; then + : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}} + else + : ${__min_width:=${DIALOG_MIN_WIDTH:-24}} + fi + if [ $__width -lt $__min_width ]; then + setvar "$__var_width" $__min_width + elif [ $__width -gt $__max_width_size_constrain ]; then + setvar "$__var_width" $__max_width_size_constrain + fi + fi + + if [ "$debug" ]; then + # Print final constrained values to debugging + [ "$__var_height" ] && f_quietly f_getvar "$__var_height" + [ "$__var_width" ] && f_quietly f_getvar "$__var_width" + fi + + return $__retval # success if no debug warnings were printed +} + +# f_dialog_menu_constrain $var_height $var_width $var_rows "$prompt" \ +# [$min_height [$min_width [$min_rows]]] +# +# Modify $var_height to be no-less-than $min_height (if given; zero otherwise) +# and no-greater-than terminal height (or screen height if $USE_XDIALOG is +# set). +# +# Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or +# $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal +# or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by +# passing $min_width. +# +# Last, modify $var_rows to be no-less-than $min_rows (if specified; zero +# otherwise) and no-greater-than (max_height - 8) where max_height is the +# terminal height (or screen height if $USE_XDIALOG is set). If $prompt is NULL +# or missing, dialog(1) allows $var_rows to be (max_height - 7), maximizing the +# number of visible rows. +# +# Return status is success unless one of the passed arguments is invalid +# or all of the $var_* arguments are either NULL or missing. +# +f_dialog_menu_constrain() +{ + local __var_height="$1" __var_width="$2" __var_rows="$3" __prompt="$4" + local __min_height="$5" __min_width="$6" __min_rows="$7" + + # Return failure unless at least one var_* argument is passed + [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || + return $FAILURE + + # + # Print debug warnings if any given (non-NULL) argument are invalid + # NOTE: Don't change the name of $__{var,min,}{height,width,rows} + # + local __height_menu_constrain __width_menu_constrain + local __rows_menu_constrain + local __arg __cp __fname=f_dialog_menu_constrain + for __arg in height width rows; do + debug= f_getvar __var_$__arg __cp + [ "$__cp" ] || continue + if ! debug= f_getvar "$__cp" __${__arg}_menu_constrain; then + f_dprintf "%s: var_%s variable \`%s' not set" \ + $__fname $__arg "$__cp" + __retval=$FAILURE + elif ! eval f_isinteger \$__${__arg}_menu_constrain; then + f_dprintf "%s: var_%s variable value not a number" \ + $__fname $__arg + __retval=$FAILURE + fi + done + for __arg in height width rows; do + debug= f_getvar __min_$__arg __cp + [ "$__cp" ] || continue + f_isinteger "$__cp" && continue + f_dprintf "%s: min_%s value not a number" $__fname $__arg + __retval=$FAILURE + setvar __min_$__arg "" + done + + # Obtain maximum height and width values + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __max_height_menu_constrain __max_width_menu_constrain + f_dialog_max_size \ + __max_height_menu_constrain __max_width_menu_constrain + + # Adjust height if desired + if [ "$__var_height" ]; then + if [ $__height_menu_constrain -lt ${__min_height:-0} ]; then + setvar "$__var_height" $__min_height + elif [ $__height_menu_constrain -gt \ + $__max_height_menu_constrain ] + then + setvar "$__var_height" $__max_height_menu_constrain + fi + fi + + # Adjust width if desired + if [ "$__var_width" ]; then + if [ "$USE_XDIALOG" ]; then + : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}} + else + : ${__min_width:=${DIALOG_MIN_WIDTH:-24}} + fi + if [ $__width_menu_constrain -lt $__min_width ]; then + setvar "$__var_width" $__min_width + elif [ $__width_menu_constrain -gt \ + $__max_width_menu_constrain ] + then + setvar "$__var_width" $__max_width_menu_constrain + fi + fi + + # Adjust rows if desired + if [ "$__var_rows" ]; then + if [ "$USE_XDIALOG" ]; then + : ${__min_rows:=1} + else + : ${__min_rows:=0} + fi + + local __max_rows_menu_constrain=$(( + $__max_height_menu_constrain - 7 + )) + # If prompt_len is zero (no prompt), bump the max-rows by 1 + # Default assumption is (if no argument) that there's no prompt + [ ${__prompt_len:-0} -gt 0 ] || __max_rows_menu_constrain=$(( + $__max_rows_menu_constrain + 1 + )) + + if [ $__rows_menu_constrain -lt $__min_rows ]; then + setvar "$__var_rows" $__min_rows + elif [ $__rows_menu_constrain -gt $__max_rows_menu_constrain ] + then + setvar "$__var_rows" $__max_rows_menu_constrain + fi + fi + + if [ "$debug" ]; then + # Print final constrained values to debugging + [ "$__var_height" ] && f_quietly f_getvar "$__var_height" + [ "$__var_width" ] && f_quietly f_getvar "$__var_width" + [ "$__var_rows" ] && f_quietly f_getvar "$__var_rows" + fi + + return $__retval # success if no debug warnings were printed +} + +# f_dialog_infobox_size [-n] $var_height $var_width \ +# $title $backtitle $prompt [$hline] +# +# Not all versions of dialog(1) perform auto-sizing of the width and height of +# `--infobox' boxes sensibly. +# +# This function helps solve this issue by taking two sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height and width. The second set of arguments are the +# title, backtitle, prompt, and [optionally] hline. The optimal height and +# width for the described widget (not exceeding the actual terminal height or +# width) is stored in $var_height and $var_width (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height and +# $var_width) are not constrained to minimum/maximum values. +# +# Newline character sequences (``\n'') in $prompt are expanded as-is done by +# dialog(1). +# +f_dialog_infobox_size() +{ + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" + local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" ] || return $FAILURE + + # Default height/width of zero for auto-sizing + local __height=0 __width=0 __n + + # Adjust height if desired + if [ "$__var_height" ]; then + # + # Set height based on number of rows in prompt + # + __n=$( echo -n "$__prompt" | f_number_of_lines ) + __n=$(( $__n + 2 )) + [ $__n -gt $__height ] && __height=$__n + + # + # For Xdialog(1) bump height if backtitle is enabled (displayed + # in the X11 window with a separator line between the backtitle + # and msg text). + # + if [ "$USE_XDIALOG" -a "$__btitle" ]; then + __n=$( echo "$__btitle" | f_number_of_lines ) + __height=$(( $__height + $__n + 2 )) + fi + + setvar "$__var_height" $__height + fi + + # Adjust width if desired + if [ "$__var_width" ]; then + # + # Bump width for long titles + # + __n=$(( ${#__title} + 4 )) + [ $__n -gt $__width ] && __width=$__n + + # + # If using Xdialog(1), bump width for long backtitles (which + # appear within the window). + # + if [ "$USE_XDIALOG" ]; then + __n=$(( ${#__btitle} + 4 )) + [ $__n -gt $__width ] && __width=$__n + fi + + # + # Bump width for long prompts + # + __n=$( echo "$__prompt" | f_longest_line_length ) + __n=$(( $__n + 4 )) # add width for border + [ $__n -gt $__width ] && __width=$__n + + # + # Bump width for long hlines. Xdialog(1) supports `--hline' but + # it's currently not used (so don't do anything here if using + # Xdialog(1)). + # + if [ ! "$USE_XDIALOG" ]; then + __n=$(( ${#__hline} + 12 )) + [ $__n -gt $__width ] && __width=$__n + fi + + # Bump width by 16.6% if using Xdialog(1) + [ "$USE_XDIALOG" ] && __width=$(( $__width + $__width / 6 )) + + setvar "$__var_width" $__width + fi + + # Constrain values to sensible minimums/maximums unless `-n' was passed + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || + f_dialog_size_constrain "$__var_height" "$__var_width" +} + +# f_dialog_buttonbox_size [-n] $var_height $var_width \ +# $title $backtitle $prompt [$hline] +# +# Not all versions of dialog(1) perform auto-sizing of the width and height of +# `--msgbox' and `--yesno' boxes sensibly. +# +# This function helps solve this issue by taking two sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height and width. The second set of arguments are the +# title, backtitle, prompt, and [optionally] hline. The optimal height and +# width for the described widget (not exceeding the actual terminal height or +# width) is stored in $var_height and $var_width (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height and +# $var_width) are not constrained to minimum/maximum values. +# +# Newline character sequences (``\n'') in $prompt are expanded as-is done by +# dialog(1). +# +f_dialog_buttonbox_size() +{ + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" + local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" ] || return $FAILURE + + # Calculate height/width of infobox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_bbox_size __width_bbox_size + f_dialog_infobox_size -n \ + "${__var_height:+__height_bbox_size}" \ + "${__var_width:+__width_bbox_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # Adjust height if desired + if [ "$__var_height" ]; then + # Add height to accommodate the buttons + __height_bbox_size=$(( $__height_bbox_size + 2 )) + + # Adjust for clipping with Xdialog(1) on Linux/GTK2 + [ "$USE_XDIALOG" ] && + __height_bbox_size=$(( $__height_bbox_size + 3 )) + + setvar "$__var_height" $__height_bbox_size + fi + + # No adjustemnts to width, just pass-thru the infobox width + if [ "$__var_width" ]; then + setvar "$__var_width" $__width_bbox_size + fi + + # Constrain values to sensible minimums/maximums unless `-n' was passed + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || + f_dialog_size_constrain "$__var_height" "$__var_width" +} + +# f_dialog_inputbox_size [-n] $var_height $var_width \ +# $title $backtitle $prompt $init [$hline] +# +# Not all versions of dialog(1) perform auto-sizing of the width and height of +# `--inputbox' boxes sensibly. +# +# This function helps solve this issue by taking two sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height and width. The second set of arguments are the +# title, backtitle, prompt, and [optionally] hline. The optimal height and +# width for the described widget (not exceeding the actual terminal height or +# width) is stored in $var_height and $var_width (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height and +# $var_width) are not constrained to minimum/maximum values. +# +# Newline character sequences (``\n'') in $prompt are expanded as-is done by +# dialog(1). +# +f_dialog_inputbox_size() +{ + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" + local __title="$3" __btitle="$4" __prompt="$5" __init="$6" __hline="$7" + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" ] || return $FAILURE + + # Calculate height/width of buttonbox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_ibox_size __width_ibox_size + f_dialog_buttonbox_size -n \ + "${__var_height:+__height_ibox_size}" \ + "${__var_width:+__width_ibox_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # Adjust height if desired + if [ "$__var_height" ]; then + # Add height for input box (not needed for Xdialog(1)) + [ ! "$USE_XDIALOG" ] && + __height_ibox_size=$(( $__height_ibox_size + 3 )) + + setvar "$__var_height" $__height_ibox_size + fi + + # Adjust width if desired + if [ "$__var_width" ]; then + # Bump width for initial text (something neither dialog(1) nor + # Xdialog(1) do, but worth it!; add 16.6% if using Xdialog(1)) + local __n=$(( ${#__init} + 7 )) + [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) + [ $__n -gt $__width_ibox_size ] && __width_ibox_size=$__n + + setvar "$__var_width" $__width_ibox_size + fi + + # Constrain values to sensible minimums/maximums unless `-n' was passed + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || + f_dialog_size_constrain "$__var_height" "$__var_width" +} + +# f_xdialog_2inputsbox_size [-n] $var_height $var_width \ +# $title $backtitle $prompt \ +# $label1 $init1 $label2 $init2 +# +# Xdialog(1) does not perform auto-sizing of the width and height of +# `--2inputsbox' boxes sensibly. +# +# This function helps solve this issue by taking two sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height and width. The second set of arguments are the +# title, backtitle, prompt, label for the first field, initial text for said +# field, label for the second field, and initial text for said field. The +# optimal height and width for the described widget (not exceeding the actual +# terminal height or width) is stored in $var_height and $var_width +# (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height and +# $var_width) are not constrained to minimum/maximum values. +# +# Newline character sequences (``\n'') in $prompt are expanded as-is done by +# Xdialog(1). +# +f_xdialog_2inputsbox_size() +{ + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" + local __title="$3" __btitle="$4" __prompt="$5" + local __label1="$6" __init1="$7" __label2="$8" __init2="$9" + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" ] || return $FAILURE + + # Calculate height/width of inputbox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_2ibox_size __width_2ibox_size + f_dialog_inputbox_size -n \ + "${__var_height:+__height_2ibox_size}" \ + "${__var_width:+__width_2ibox_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" "$__init1" + + # Adjust height if desired + if [ "$__var_height" ]; then + # Add height for 1st label, 2nd label, and 2nd input box + __height_2ibox_size=$(( $__height_2ibox_size + 2 + 2 + 2 )) + setvar "$__var_height" $__height_2ibox_size + fi + + # Adjust width if desired + if [ "$__var_width" ]; then + local __n + + # Bump width for first label text (+16.6% since Xdialog(1)) + __n=$(( ${#__label1} + 7 )) + __n=$(( $__n + $__n / 6 )) + [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n + + # Bump width for second label text (+16.6% since Xdialog(1)) + __n=$(( ${#__label2} + 7 )) + __n=$(( $__n + $__n / 6 )) + [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n + + # Bump width for 2nd initial text (something neither dialog(1) + # nor Xdialog(1) do, but worth it!; +16.6% since Xdialog(1)) + __n=$(( ${#__init2} + 7 )) + __n=$(( $__n + $__n / 6 )) + [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n + + setvar "$__var_width" $__width_2ibox_size + fi + + # Constrain values to sensible minimums/maximums unless `-n' was passed + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || + f_dialog_size_constrain "$__var_height" "$__var_width" +} + +# f_dialog_menu_size [-n] $var_height $var_width $var_rows \ +# $title $backtitle $prompt $hline \ +# $tag1 $item1 $tag2 $item2 ... +# +# Not all versions of dialog(1) perform auto-sizing of the width and height of +# `--menu' boxes sensibly. +# +# This function helps solve this issue by taking three sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height, width, and rows. The second set of arguments +# are the title, backtitle, prompt, and hline. The [optional] third set of +# arguments are the menu list itself (comprised of tag/item couplets). The +# optimal height, width, and rows for the described widget (not exceeding the +# actual terminal height or width) is stored in $var_height, $var_width, and +# $var_rows (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height, $var_width, +# and $var_rows) are not constrained to minimum/maximum values. +# +f_dialog_menu_size() +{ + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" __var_rows="$3" + local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" + shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || + return $FAILURE + + # Calculate height/width of infobox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_menu_size __width_menu_size + f_dialog_infobox_size -n \ + "${__var_height:+__height_menu_size}" \ + "${__var_width:+__width_menu_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # + # Always process the menu-item arguments to get the longest tag-length, + # longest item-length (both used to bump the width), and the number of + # rows (used to bump the height). + # + local __longest_tag=0 __longest_item=0 __rows=0 + while [ $# -ge 2 ]; do + local __tag="$1" __item="$2" + shift 2 # tag/item + [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} + [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} + __rows=$(( $__rows + 1 )) + done + + # Adjust rows early (for up-comning height calculation) + if [ "$__var_height" -o "$__var_rows" ]; then + # Add a row for visual aid if using Xdialog(1) + [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) + fi + + # Adjust height if desired + if [ "$__var_height" ]; then + # Add rows to height + if [ "$USE_XDIALOG" ]; then + __height_menu_size=$(( + $__height_menu_size + $__rows + 7 )) + else + __height_menu_size=$(( + $__height_menu_size + $__rows + 4 )) + fi + setvar "$__var_height" $__height_menu_size + fi + + # Adjust width if desired + if [ "$__var_width" ]; then + # The sum total between the longest tag-length and the + # longest item-length should be used to bump menu width + local __n=$(( $__longest_tag + $__longest_item + 10 )) + [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% + [ $__n -gt $__width_menu_size ] && __width_menu_size=$__n + + setvar "$__var_width" $__width_menu_size + fi + + # Store adjusted rows if desired + [ "$__var_rows" ] && setvar "$__var_rows" $__rows + + # Constrain height, width, and rows to sensible minimum/maximum values + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || f_dialog_menu_constrain \ + "$__var_height" "$__var_width" "$__var_rows" "$__prompt" +} + +# f_dialog_menu_with_help_size [-n] $var_height $var_width $var_rows \ +# $title $backtitle $prompt $hline \ +# $tag1 $item1 $help1 $tag2 $item2 $help2 ... +# +# Not all versions of dialog(1) perform auto-sizing of the width and height of +# `--menu' boxes sensibly. +# +# This function helps solve this issue by taking three sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height, width, and rows. The second set of arguments +# are the title, backtitle, prompt, and hline. The [optional] third set of +# arguments are the menu list itself (comprised of tag/item/help triplets). The +# optimal height, width, and rows for the described widget (not exceeding the +# actual terminal height or width) is stored in $var_height, $var_width, and +# $var_rows (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height, $var_width, +# and $var_rows) are not constrained to minimum/maximum values. +# +f_dialog_menu_with_help_size() +{ + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" __var_rows="$3" + local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" + shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || + return $FAILURE + + # Calculate height/width of infobox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_menu_with_help_size __width_menu_with_help_size + f_dialog_infobox_size -n \ + "${__var_height:+__height_menu_with_help_size}" \ + "${__var_width:+__width_menu_with_help_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # + # Always process the menu-item arguments to get the longest tag-length, + # longest item-length, longest help-length (help-length only considered + # if using Xdialog(1), as it places the help string in the widget) -- + # all used to bump the width -- and the number of rows (used to bump + # the height). + # + local __longest_tag=0 __longest_item=0 __longest_he |