2013-01-05 02:08:47 +00:00
|
|
|
if [ ! "$_SCRIPT_SUBR" ]; then _SCRIPT_SUBR=1
|
|
|
|
#
|
Import media selection/preparation framework (sysinstall inspired). Makes
accessing files from various types of media nice and abstracted away from
the wet-work involved in preparing, validating, and initializing those
types of media. This will be used for the package management system module
and other modules that need access to files and want to allow the user to
decide where those files come from (either in a scripted fashion, prompted
fashion, or any combination thereof).
Heavily inspired by sysinstall and even uses the same reserved words so
that scripts are portable. Coded over months, tested continuously through-
out, and reviewed several times.
Some notes about the changes:
- Move network-setting acquisition/validation routines to media/tcpip.subr
- The options screen from sysinstall has been converted to a dialog menu
- The "UFS" media choice is renamed to "Directory" to reflect how sysinstall
treats the choice and a new [true] "UFS" media choice has been added that
acts on real UFS partitions (such as external disks with disklabels).
- Many more help files have been resurrected from sysinstall (I noticed that
some of the content seems a bit dated; I gave them a once-over but they
could really use an update).
- A total of 10 media choices are presented (via mediaGetType) including:
CD/DVD, FTP, FTP Passive, HTTP Proxy, Directory, NFS, DOS, UFS, Floppy, USB
- Novel struct/device management layer for managing the issue of passing
more information than can comfortably fit in an argument list.
2013-02-25 19:55:32 +00:00
|
|
|
# Copyright (c) 2012-2013 Devin Teske
|
2013-07-07 18:21:30 +00:00
|
|
|
# All rights reserved.
|
2013-01-05 02:08:47 +00:00
|
|
|
#
|
|
|
|
# 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
|
2013-07-07 18:51:44 +00:00
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
2013-01-05 02:08:47 +00:00
|
|
|
# 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
|
2013-07-07 18:51:44 +00:00
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
2013-01-05 02:08:47 +00:00
|
|
|
# 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..." script.subr
|
Import media selection/preparation framework (sysinstall inspired). Makes
accessing files from various types of media nice and abstracted away from
the wet-work involved in preparing, validating, and initializing those
types of media. This will be used for the package management system module
and other modules that need access to files and want to allow the user to
decide where those files come from (either in a scripted fashion, prompted
fashion, or any combination thereof).
Heavily inspired by sysinstall and even uses the same reserved words so
that scripts are portable. Coded over months, tested continuously through-
out, and reviewed several times.
Some notes about the changes:
- Move network-setting acquisition/validation routines to media/tcpip.subr
- The options screen from sysinstall has been converted to a dialog menu
- The "UFS" media choice is renamed to "Directory" to reflect how sysinstall
treats the choice and a new [true] "UFS" media choice has been added that
acts on real UFS partitions (such as external disks with disklabels).
- Many more help files have been resurrected from sysinstall (I noticed that
some of the content seems a bit dated; I gave them a once-over but they
could really use an update).
- A total of 10 media choices are presented (via mediaGetType) including:
CD/DVD, FTP, FTP Passive, HTTP Proxy, Directory, NFS, DOS, UFS, Floppy, USB
- Novel struct/device management layer for managing the issue of passing
more information than can comfortably fit in an argument list.
2013-02-25 19:55:32 +00:00
|
|
|
f_include $BSDCFG_SHARE/device.subr
|
|
|
|
f_include $BSDCFG_SHARE/media/any.subr
|
|
|
|
f_include $BSDCFG_SHARE/media/tcpip.subr
|
2013-07-05 01:37:35 +00:00
|
|
|
f_include $BSDCFG_SHARE/mustberoot.subr
|
2013-07-05 01:49:20 +00:00
|
|
|
f_include $BSDCFG_SHARE/networking/services.subr
|
2013-05-07 05:40:20 +00:00
|
|
|
f_include $BSDCFG_SHARE/packages/packages.subr
|
2013-06-19 17:13:16 +00:00
|
|
|
f_include $BSDCFG_SHARE/variable.subr
|
2013-01-05 02:08:47 +00:00
|
|
|
|
|
|
|
############################################################ GLOBALS
|
|
|
|
|
|
|
|
RESWORDS=
|
|
|
|
|
|
|
|
############################################################ FUNCTIONS
|
|
|
|
|
|
|
|
# f_resword_new $resword $function
|
|
|
|
#
|
|
|
|
# Create a new `reserved' word for scripting purposes. Reswords call pre-
|
|
|
|
# defined functions but differ from those functions in the following ways:
|
|
|
|
#
|
|
|
|
# + Reswords do not take arguments but instead get all their data from
|
|
|
|
# the environment variable namespace.
|
|
|
|
# + Unless noError is set (must be non-NULL), if calling the resword
|
|
|
|
# results in failure, the application will terminate prematurely.
|
|
|
|
# + noError is unset after each/every resword is called.
|
|
|
|
#
|
|
|
|
# Reswords should not be used in bsdconfig itself (hence the name `reserved
|
|
|
|
# word') but instead only in scripts loaded through f_script_load()).
|
|
|
|
#
|
|
|
|
f_resword_new()
|
|
|
|
{
|
|
|
|
local resword="$1" func="$2"
|
|
|
|
[ "$resword" ] || return $FAILURE
|
|
|
|
f_dprintf "script.subr: New resWord %s -> %s" "$resword" "$func"
|
|
|
|
eval $resword\(\){ f_dispatch $func $resword\; }
|
|
|
|
RESWORDS="$RESWORDS${RESWORDS:+ }$resword"
|
|
|
|
}
|
|
|
|
|
|
|
|
# f_dispatch $func [$resword]
|
|
|
|
#
|
|
|
|
# Wrapper function used by `reserved words' (reswords) to call other functions.
|
|
|
|
# If $noError is set and non-NULL, a failure result from $func is ignored,
|
|
|
|
# otherwise the application is prematurely terminated using f_die().
|
|
|
|
#
|
|
|
|
# NOTE: $noError is unset after every call.
|
|
|
|
#
|
|
|
|
f_dispatch()
|
|
|
|
{
|
|
|
|
local func="$1" resword="${2:-$1}"
|
|
|
|
f_dprintf "f_dispatch: calling resword \`%s'" "$resword"
|
|
|
|
eval $func
|
Import media selection/preparation framework (sysinstall inspired). Makes
accessing files from various types of media nice and abstracted away from
the wet-work involved in preparing, validating, and initializing those
types of media. This will be used for the package management system module
and other modules that need access to files and want to allow the user to
decide where those files come from (either in a scripted fashion, prompted
fashion, or any combination thereof).
Heavily inspired by sysinstall and even uses the same reserved words so
that scripts are portable. Coded over months, tested continuously through-
out, and reviewed several times.
Some notes about the changes:
- Move network-setting acquisition/validation routines to media/tcpip.subr
- The options screen from sysinstall has been converted to a dialog menu
- The "UFS" media choice is renamed to "Directory" to reflect how sysinstall
treats the choice and a new [true] "UFS" media choice has been added that
acts on real UFS partitions (such as external disks with disklabels).
- Many more help files have been resurrected from sysinstall (I noticed that
some of the content seems a bit dated; I gave them a once-over but they
could really use an update).
- A total of 10 media choices are presented (via mediaGetType) including:
CD/DVD, FTP, FTP Passive, HTTP Proxy, Directory, NFS, DOS, UFS, Floppy, USB
- Novel struct/device management layer for managing the issue of passing
more information than can comfortably fit in an argument list.
2013-02-25 19:55:32 +00:00
|
|
|
local retval=$?
|
|
|
|
if [ $retval -ne $SUCCESS ]; then
|
|
|
|
local _ignore_this_error
|
|
|
|
f_getvar $VAR_NO_ERROR _ignore_this_error
|
2013-01-05 02:08:47 +00:00
|
|
|
[ "$_ignore_this_error" ] || f_die $retval \
|
Import media selection/preparation framework (sysinstall inspired). Makes
accessing files from various types of media nice and abstracted away from
the wet-work involved in preparing, validating, and initializing those
types of media. This will be used for the package management system module
and other modules that need access to files and want to allow the user to
decide where those files come from (either in a scripted fashion, prompted
fashion, or any combination thereof).
Heavily inspired by sysinstall and even uses the same reserved words so
that scripts are portable. Coded over months, tested continuously through-
out, and reviewed several times.
Some notes about the changes:
- Move network-setting acquisition/validation routines to media/tcpip.subr
- The options screen from sysinstall has been converted to a dialog menu
- The "UFS" media choice is renamed to "Directory" to reflect how sysinstall
treats the choice and a new [true] "UFS" media choice has been added that
acts on real UFS partitions (such as external disks with disklabels).
- Many more help files have been resurrected from sysinstall (I noticed that
some of the content seems a bit dated; I gave them a once-over but they
could really use an update).
- A total of 10 media choices are presented (via mediaGetType) including:
CD/DVD, FTP, FTP Passive, HTTP Proxy, Directory, NFS, DOS, UFS, Floppy, USB
- Novel struct/device management layer for managing the issue of passing
more information than can comfortably fit in an argument list.
2013-02-25 19:55:32 +00:00
|
|
|
"$msg_command_failed_rest_of_script_aborted" "$resword"
|
|
|
|
fi
|
2013-01-05 02:08:47 +00:00
|
|
|
unset $VAR_NO_ERROR
|
|
|
|
}
|
|
|
|
|
|
|
|
# f_script_load [$file]
|
|
|
|
#
|
|
|
|
# Load a script (usually filled with reswords). If $file is missing or NULL,
|
|
|
|
# use one of the following instead (in order):
|
|
|
|
#
|
|
|
|
# $configFile
|
|
|
|
# install.cfg
|
|
|
|
# /stand/install.fg
|
|
|
|
# /tmp/install.cfg
|
|
|
|
#
|
|
|
|
# Unknown/unregistered reswords will generate sh(1) syntax errors but not cause
|
|
|
|
# premature termination.
|
|
|
|
#
|
|
|
|
# Returns success if a script was loaded and itself returned success.
|
|
|
|
#
|
|
|
|
f_script_load()
|
|
|
|
{
|
2013-01-20 17:48:56 +00:00
|
|
|
local script="$1" config_file retval=$SUCCESS
|
2013-01-05 02:08:47 +00:00
|
|
|
|
|
|
|
f_dprintf "f_script_load: script=[%s]" "$script"
|
|
|
|
if [ ! "$script" ]; then
|
|
|
|
f_getvar $VAR_CONFIG_FILE config_file
|
|
|
|
for script in \
|
|
|
|
$config_file \
|
|
|
|
install.cfg \
|
|
|
|
/stand/install.cfg \
|
|
|
|
/tmp/install.cfg \
|
|
|
|
; do
|
|
|
|
[ -e "$script" ] && break
|
|
|
|
done
|
2013-01-20 17:48:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
local old_interactive=
|
|
|
|
f_getvar $VAR_NONINTERACTIVE old_interactive # save a copy
|
|
|
|
|
|
|
|
# Hint to others that we're running from a script, should they care
|
|
|
|
setvar $VAR_NONINTERACTIVE yes
|
|
|
|
|
|
|
|
if [ "$script" = "-" ]; then
|
2013-01-05 02:08:47 +00:00
|
|
|
f_dprintf "f_script_load: Loading script from stdin"
|
|
|
|
eval "$( cat )"
|
2013-01-20 17:48:56 +00:00
|
|
|
retval=$?
|
2013-01-05 02:08:47 +00:00
|
|
|
else
|
|
|
|
f_dprintf "f_script_load: Loading script \`%s'" "$script"
|
|
|
|
if [ ! -e "$script" ]; then
|
|
|
|
f_show_msg "$msg_unable_to_open" "$script"
|
|
|
|
return $FAILURE
|
|
|
|
fi
|
|
|
|
. "$script"
|
2013-01-20 17:48:56 +00:00
|
|
|
retval=$?
|
2013-01-05 02:08:47 +00:00
|
|
|
fi
|
2013-01-20 17:48:56 +00:00
|
|
|
|
|
|
|
[ "$old_interactive" ] &&
|
|
|
|
setvar $VAR_NONINTERACTIVE "$old_interactive"
|
|
|
|
|
|
|
|
return $retval
|
2013-01-05 02:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
############################################################ MAIN
|
|
|
|
|
|
|
|
#
|
|
|
|
# Reserved words meant for scripting
|
|
|
|
#
|
2013-05-07 04:03:59 +00:00
|
|
|
|
|
|
|
# this file
|
|
|
|
f_resword_new loadConfig f_script_load
|
|
|
|
|
|
|
|
# device.subr
|
|
|
|
f_resword_new deviceRescan f_device_rescan
|
|
|
|
|
|
|
|
# media/common.subr
|
|
|
|
f_resword_new mediaOpen f_media_open
|
|
|
|
f_resword_new mediaClose f_media_close
|
|
|
|
|
|
|
|
# media includes
|
|
|
|
f_resword_new mediaGetType f_media_get_type # media/any.subr
|
|
|
|
f_resword_new mediaSetCDROM f_media_set_cdrom # media/cdrom.subr
|
|
|
|
f_resword_new mediaSetDOS f_media_set_dos # media/dos.subr
|
|
|
|
f_resword_new mediaSetDirectory f_media_set_directory # media/directory.subr
|
|
|
|
f_resword_new mediaSetFloppy f_media_set_floppy # media/floppy.subr
|
|
|
|
f_resword_new mediaSetNFS f_media_set_nfs # media/nfs.subr
|
|
|
|
f_resword_new mediaSetUFS f_media_set_ufs # media/ufs.subr
|
|
|
|
f_resword_new mediaSetUSB f_media_set_usb # media/usb.subr
|
|
|
|
f_resword_new optionsEditor f_media_options_menu # media/options.subr
|
|
|
|
f_resword_new tcpMenuSelect f_dialog_menu_select_tcp # media/tcp.subr
|
|
|
|
|
|
|
|
# media/ftp.subr
|
Import media selection/preparation framework (sysinstall inspired). Makes
accessing files from various types of media nice and abstracted away from
the wet-work involved in preparing, validating, and initializing those
types of media. This will be used for the package management system module
and other modules that need access to files and want to allow the user to
decide where those files come from (either in a scripted fashion, prompted
fashion, or any combination thereof).
Heavily inspired by sysinstall and even uses the same reserved words so
that scripts are portable. Coded over months, tested continuously through-
out, and reviewed several times.
Some notes about the changes:
- Move network-setting acquisition/validation routines to media/tcpip.subr
- The options screen from sysinstall has been converted to a dialog menu
- The "UFS" media choice is renamed to "Directory" to reflect how sysinstall
treats the choice and a new [true] "UFS" media choice has been added that
acts on real UFS partitions (such as external disks with disklabels).
- Many more help files have been resurrected from sysinstall (I noticed that
some of the content seems a bit dated; I gave them a once-over but they
could really use an update).
- A total of 10 media choices are presented (via mediaGetType) including:
CD/DVD, FTP, FTP Passive, HTTP Proxy, Directory, NFS, DOS, UFS, Floppy, USB
- Novel struct/device management layer for managing the issue of passing
more information than can comfortably fit in an argument list.
2013-02-25 19:55:32 +00:00
|
|
|
f_resword_new mediaSetFTP f_media_set_ftp
|
|
|
|
f_resword_new mediaSetFTPActive f_media_set_ftp_active
|
|
|
|
f_resword_new mediaSetFTPPassive f_media_set_ftp_passive
|
|
|
|
f_resword_new mediaSetFTPUserPass f_media_set_ftp_userpass
|
2013-05-07 04:03:59 +00:00
|
|
|
|
2013-06-23 10:48:26 +00:00
|
|
|
# media/http.subr
|
|
|
|
f_resword_new mediaSetHTTP f_media_set_http
|
|
|
|
|
2013-05-07 04:03:59 +00:00
|
|
|
# media/httpproxy.subr
|
|
|
|
f_resword_new mediaSetHTTPProxy f_media_set_http_proxy
|
2013-01-05 02:08:47 +00:00
|
|
|
|
2013-07-05 01:49:20 +00:00
|
|
|
# networking/services.subr
|
|
|
|
f_resword_new configPCNFSD f_config_pcnfsd
|
|
|
|
|
2013-05-07 05:40:20 +00:00
|
|
|
# packages/packages.subr
|
|
|
|
f_resword_new configPackages f_package_config
|
2013-07-05 01:44:59 +00:00
|
|
|
f_resword_new packageAdd f_package_add
|
2013-07-05 06:52:07 +00:00
|
|
|
f_resword_new packageDelete f_package_delete
|
2013-07-05 21:40:31 +00:00
|
|
|
f_resword_new packageReinstall f_package_reinstall
|
2013-05-07 05:40:20 +00:00
|
|
|
|
2013-06-19 17:14:59 +00:00
|
|
|
# variable.subr
|
|
|
|
f_resword_new installVarDefaults f_variable_set_defaults
|
|
|
|
f_resword_new dumpVariables f_dump_variables
|
|
|
|
|
2013-01-05 02:08:47 +00:00
|
|
|
f_dprintf "%s: Successfully loaded." script.subr
|
|
|
|
|
|
|
|
fi # ! $_SCRIPT_SUBR
|