MFC revisions 268999, 269027, 269351-269352, 269354, 269460, 270283,

270505, 270954, and 270989:
r268999: Add new bsdconfig example scripts; remove obsolete ones
r269027: Update bsdconfig dot module; fixes and enhancements
r269351: Add setvar() for non-FreeBSD platforms using bash as /bin/sh
r269352: Fix syntax error when run under bash
r269354: Update setvar() function introduced in r269351
r269460: Update f_xdialog_info() in bsdconfig's dialog.subr include
r270283: Add `-A' flag to pkg-install(8) when installing dependencies
r270505: Optimize f_which() to be slightly faster still (common.subr)
r270954: Update f_dialog_init() for safer getopts usage (dialog.subr)
r270989: Fix for previously mentioned r270954

Approved by:	re (gjb)
This commit is contained in:
dteske 2014-09-27 23:57:21 +00:00
parent 881bf9eca2
commit faff28354b
16 changed files with 236 additions and 178 deletions

View File

@ -249,6 +249,7 @@ if [ "$SHOW_INCLUDES" ]; then
$menu_program_list \
$submenu_program_list \
$cmd_program_list \
$BSDCFG_SHARE/script.subr \
; do
[ -e "$file" ] && echo $file
done | sort -u
@ -298,12 +299,6 @@ if [ "$SHOW_INCLUDES" ]; then
done
fi
#
# Add script.subr to includes if it exists
#
[ -f $BSDCFG_SHARE/script.subr ] &&
include_file_list="$include_file_list script.subr"
#
# Start the directional-graph (digraph) output
#
@ -352,7 +347,7 @@ 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, // turn minimum width into exact width\n'
printf '\t\tfixedsize = true, // turn minimum width into exact width\n'
printf '\t];\n'
#
@ -546,34 +541,36 @@ 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
printf '\t\tsubgraph "cluster_includes" {\n'
printf '\t\t\tbgcolor = "%s";\n' "$bgcolor_includes"
printf '\t\t\tlabel = "%s";\n' "$msg_includes"
for include_file in $include_file_list; do
echo $include_file
done | awk -v bgcolor="$bgcolor_bsdconfig" '
BEGIN { created = 0 }
function end_subgraph() { printf "\t\t\t};\n" }
( $0 !~ "/" ) {
if ( ! created )
{
printf "\t\t\tsubgraph \"%s\" {\n",
"cluster_bsdconfig_includes"
printf "\t\t\t\tbgcolor = \"%s\";\n", bgcolor
printf "\t\t\t\tlabel = \"bsdconfig\";\n"
created++
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
}
printf "\t\t\t\t\"%s\";\n", $1
}
END { created && end_subgraph() }'
END { created && end_subgraph() }
' # END-QUOTE
for include_file in $include_file_list; do
echo $include_file
done | awk '
done | awk -v msg_subroutines="$msg_subroutines" '
BEGIN { created = 0 }
function end_subgraph() { printf "\t\t\t};\n" }
function end_subgraph() { printf "\t};\n" }
( $0 ~ "/" ) {
include_dir_tmp = $1
sub("/[^/]*$", "", include_dir_tmp)
@ -588,20 +585,18 @@ if [ "$SHOW_INCLUDES" ]; then
if ( ! created )
{
include_dir = include_dir_tmp
printf "\t\t\tsubgraph \"cluster_%s_includes\" {\n",
printf "\tsubgraph \"cluster_%s_includes\" {\n",
include_dir
printf "\t\t\t\tbgcolor = \"white\";\n"
printf "\t\t\t\tlabel = \"%s\";\n", include_dir
printf "\t\tbgcolor = \"thistle\";\n"
printf "\t\tlabel = \"%s %s\";\n", include_dir,
msg_subroutines
created++
}
printf "\t\t\t\t\"%s\";\n", $1
printf "\t\t\"%s\";\n", $1
}
END { created && end_subgraph() }'
printf '\t\t};\n'
fi
end_nodelist
for INDEX in */INDEX; do
menu_title=
menu_help=
@ -676,7 +671,7 @@ for INDEX in */INDEX; do
end_nodelist
done
printf '\n};\n'
printf '\n}\n'
################################################################################
# END

View File

@ -28,3 +28,4 @@ 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"

View File

@ -3,7 +3,7 @@
NO_OBJ=
FILESDIR= ${SHAREDIR}/examples/bsdconfig
FILES= browse_packages_ftp.sh browse_packages_http.sh bsdconfigrc
FILES= add_some_packages.sh browse_packages_http.sh bsdconfigrc
beforeinstall:
mkdir -p ${DESTDIR}${FILESDIR}

View File

@ -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

View File

@ -1,25 +0,0 @@
#!/bin/sh
# $FreeBSD$
#
# This sample downloads the package INDEX file from FTP to /tmp (if it doesn't
# already exist) and then displays the package configuration/management screen
# using the local INDEX file (results in faster browsing of packages from-start
# since the INDEX can be loaded from local media).
#
# NOTE: Packages cannot be installed unless staged to /tmp/packages/All
#
. /usr/share/bsdconfig/script.subr
nonInteractive=1
TMPDIR=/tmp
if [ ! -e "$TMPDIR/packages/INDEX" ]; then
[ -d "$TMPDIR/packages" ] || mkdir -p "$TMPDIR/packages" || exit 1
_ftpPath=ftp://ftp.freebsd.org
# For older releases, use ftp://ftp-archive.freebsd.org
mediaSetFTP
mediaOpen
f_show_info "Downloading packages/INDEX from\n %s" "$_ftpPath"
f_device_get device_media packages/INDEX > $TMPDIR/packages/INDEX
fi
_directoryPath=$TMPDIR
mediaSetDirectory
configPackages

View File

@ -1,25 +1,32 @@
#!/bin/sh
# $FreeBSD$
#
# This sample downloads the package INDEX file from HTTP to /tmp (if it doesn't
# already exist) and then displays the package configuration/management screen
# using the local INDEX file (results in faster browsing of packages from-start
# since the INDEX can be loaded from local media).
# 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/All
# NOTE: Packages cannot be installed unless staged to
# /tmp/packages/$PKG_ABI/All
#
. /usr/share/bsdconfig/script.subr
[ "$_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
if [ ! -e "$TMPDIR/packages/INDEX" ]; then
[ -d "$TMPDIR/packages" ] || mkdir -p "$TMPDIR/packages" || exit 1
_httpPath=http://ftp.freebsd.org
# For older releases, use http://ftp-archive.freebsd.org
mediaSetHTTP
mediaOpen
f_show_info "Downloading packages/INDEX from\n %s" "$_httpPath"
f_device_get device_media packages/INDEX > $TMPDIR/packages/INDEX
fi
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

View File

@ -57,6 +57,7 @@ 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_cad_desc="Computer Aided Design utilities."
@ -142,8 +143,6 @@ msg_generating_index_from_pkg_database="Generating INDEX from pkg(8) database\n(
msg_geography_desc="Geography-related software."
msg_german_desc="Ported software for Germanic countries."
msg_germany="Germany"
msg_getting_package_categories_via_pkg_rquery="Getting package categories via pkg-rquery(8)..."
msg_getting_package_dependencies_via_pkg_rquery="Getting package dependencies via pkg-rquery(8)\n(this can take a while)..."
msg_gnome_desc="Components of the Gnome Desktop environment."
msg_gnustep_desc="Software for GNUstep desktop environment."
msg_graphics_desc="Graphics libraries and utilities."
@ -219,6 +218,7 @@ 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."
@ -274,6 +274,7 @@ msg_perl5_desc="Utilities/modules for the PERL5 language."
msg_permission_denied="%s: %s: Permission denied"
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):"
@ -376,15 +377,13 @@ msg_unable_to_get_proper_ftp_path="Unable to get proper FTP path. FTP media not
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_pkg_rquery_package_categories="Unable to pkg-rquery(8) package categories!"
msg_unable_to_pkg_rquery_package_dependencies="Unable to pkg-rquery(8) package dependencies!"
msg_unable_to_update_pkg_from_selected_media="Unable to update pkg(8) from selected media."
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, maybe directory or release-version are wrong?"
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"

View File

@ -62,12 +62,6 @@ 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)
if [ ! "${PKG_ABI+set}" ]; then
export PKG_ABI="$(
ASSUME_ALWAYS_YES=1 pkg -vv 2> /dev/null |
awk '$1=="ABI"{print $3;exit}'
)"
fi
#
# Default behavior is to call f_debug_init() automatically when loaded.
@ -226,6 +220,36 @@ 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
@ -239,10 +263,10 @@ f_which()
{
local __name="$1" __var_to_set="$2"
case "$__name" in */*|'') return $FAILURE; esac
local __p IFS=":" __found=
local __p __exec IFS=":" __found=
for __p in $PATH; do
local __exec="$__p/$__name"
[ -f "$__exec" -a -x "$__exec" ] && __found=1 && break
__exec="$__p/$__name"
[ -f "$__exec" -a -x "$__exec" ] && __found=1 break
done
if [ "$__found" ]; then
if [ "$__var_to_set" ]; then

View File

@ -1557,12 +1557,22 @@ f_dialog_info()
# EOF. This implies that you must execute this either as an rvalue to a pipe,
# lvalue to indirection or in a sub-shell that provides data on stdin.
#
# To open an Xdialog(1) infobox that does not disappear until expeclitly dis-
# missed, use the following:
#
# f_xdialog_info "$info_text" < /dev/tty &
# pid=$!
# # Perform some lengthy actions
# kill $pid
#
# NB: Check $USE_XDIALOG if you need to support both dialog(1) and Xdialog(1).
#
f_xdialog_info()
{
local info_text="$*" height width
f_dialog_infobox_size height width \
"$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$info_text"
$DIALOG \
exec $DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--no-close --no-buttons \
@ -2099,9 +2109,14 @@ f_dialog_init()
#
# Process stored command-line arguments
#
# NB: Using backticks instead of $(...) for portability since Linux
# bash(1) balks at the right parentheses encountered in the case-
# statement (incorrectly interpreting it as the close of $(...)).
#
f_dprintf "f_dialog_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \
"$ARGV" "$GETOPTS_STDARGS"
SECURE=$( set -- $ARGV
SECURE=`set -- $ARGV
OPTIND=1
while getopts \
"$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" \
flag > /dev/null; do
@ -2109,8 +2124,9 @@ f_dialog_init()
S) echo 1 ;;
esac
done
)
USE_XDIALOG=$( set -- $ARGV
` # END-BACKTICK
USE_XDIALOG=`set -- $ARGV
OPTIND=1
while getopts \
"$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" \
flag > /dev/null; do
@ -2118,7 +2134,7 @@ f_dialog_init()
S|X) echo 1 ;;
esac
done
)
` # END-BACKTICK
f_dprintf "f_dialog_init: SECURE=[%s] USE_XDIALOG=[%s]" \
"$SECURE" "$USE_XDIALOG"

View File

@ -515,10 +515,7 @@ f_media_init_http()
fi
esac
if [ $http_found -eq $SUCCESS ]; then
HTTP_INITIALIZED=YES
break
fi
[ $http_found -eq $SUCCESS ] && HTTP_INITIALIZED=YES break
f_getvar $VAR_HTTP_PATH http_path
f_show_msg "$msg_please_check_the_url_and_try_again" \
@ -668,7 +665,7 @@ f_media_get_http()
44) f_show_msg "$msg_url_was_not_found" "$url" ;;
4) f_show_msg "$msg_client_error" ;;
*) f_show_msg "$msg_error_when_requesting_url" "$url" ;;
esac
esac 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
return $FAILURE
}

View File

@ -452,7 +452,7 @@ f_media_get_http_proxy()
44) f_show_msg "$msg_url_was_not_found" "$url" ;;
4) f_show_msg "$msg_client_error" ;;
*) f_show_msg "$msg_error_when_requesting_url" "$url" ;;
esac
esac 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
return $FAILURE
}

View File

@ -3,7 +3,7 @@
NO_OBJ=
FILESDIR= ${SHAREDIR}/bsdconfig/packages
FILES= categories.subr index.subr packages.subr
FILES= categories.subr index.subr musthavepkg.subr packages.subr
beforeinstall:
mkdir -p ${DESTDIR}${FILESDIR}

0
usr.sbin/bsdconfig/share/packages/categories.subr Executable file → Normal file
View File

81
usr.sbin/bsdconfig/share/packages/index.subr Executable file → Normal file
View File

@ -33,6 +33,7 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
f_dprintf "%s: loading includes..." packages/index.subr
f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/media/common.subr
f_include $BSDCFG_SHARE/packages/musthavepkg.subr
f_include $BSDCFG_SHARE/strings.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
@ -53,27 +54,6 @@ SQLITE_REPO="/var/db/pkg/repo-packagesite.sqlite"
#
PACKAGES_INDEX_CACHEFILE="/var/run/bsdconfig/packages_INDEX.cache"
#
# INDEX format for FreeBSD-6.0 or higher:
#
# package|port-origin|install-prefix|comment|port-desc-file|maintainer|
# categories|build-deps|run-deps|www-site|reserve|reserve|reserve|disc
#
INDEX_FORMAT="%n-%v" # package
INDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o" # port-origin
INDEX_FORMAT="$INDEX_FORMAT|%p" # install-prefix
INDEX_FORMAT="$INDEX_FORMAT|%c" # comment
INDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o/pkg-descr" # port-desc-file
INDEX_FORMAT="$INDEX_FORMAT|%m" # maintainer
INDEX_FORMAT="$INDEX_FORMAT|@CATEGORIES@" # place-holder
INDEX_FORMAT="$INDEX_FORMAT|" # build-deps
INDEX_FORMAT="$INDEX_FORMAT|@RUNDEPS@" # place-holder
INDEX_FORMAT="$INDEX_FORMAT|%w" # www-site
INDEX_FORMAT="$INDEX_FORMAT|" # reserved
INDEX_FORMAT="$INDEX_FORMAT|" # reserved
INDEX_FORMAT="$INDEX_FORMAT|" # reserved
INDEX_FORMAT="$INDEX_FORMAT|" # disc
############################################################ FUNCTIONS
# f_index_initialize [$var_to_set]
@ -87,13 +67,16 @@ INDEX_FORMAT="$INDEX_FORMAT|" # disc
f_index_initialize()
{
local __funcname=f_index_initialize
local __var_to_set="${2:-PACKAGE_INDEX}"
local __var_to_set="${1:-PACKAGE_INDEX}"
[ "$_INDEX_INITTED" ] && return $SUCCESS
# Got any media?
f_media_verify || return $FAILURE
# Make sure we have a usable pkg(8) with $PKG_ABI
f_musthavepkg_init
# Does it move when you kick it?
f_device_init device_media || return $FAILURE
@ -126,9 +109,10 @@ f_index_initialize()
__site="file://$MOUNTPOINT/packages/$PKG_ABI"
esac
export PACKAGESITE="$__site"
f_dprintf "PACKAGESITE=[%s]" "$PACKAGESITE"
if ! f_eval_catch $__funcname pkg "pkg update"; then
f_dprintf "PACKAGESITE=[%s]" "$__site"
if ! f_eval_catch $__funcname pkg \
'PACKAGESITE="%s" pkg update' "$__site"
then
f_show_err "$msg_unable_to_update_pkg_from_selected_media"
f_device_shutdown device_media
return $FAILURE
@ -195,53 +179,8 @@ f_index_initialize()
# If we reach this point, we need to generate the data from scratch
#
f_show_info "$msg_getting_package_categories_via_pkg_rquery"
if ! eval "$( pkg rquery "%n-%v %C" | awk '
{ categories[$1] = categories[$1] " " $2 }
END {
for (package in categories)
{
cats = categories[package]
sub(/^ /, "", cats)
gsub(/[^[:alnum:]_]/, "_", package)
printf "local _%s_categories=\"%s\";\n", package, cats
}
}' )"; then
f_show_err "$msg_unable_to_pkg_rquery_package_dependencies"
f_device_shutdown device_media
return $FAILURE
fi
f_show_info "$msg_getting_package_dependencies_via_pkg_rquery"
if ! eval "$( pkg rquery "%n-%v %dn-%dv" | awk '
{ rundeps[$1] = rundeps[$1] " " $2 }
END {
for (package in rundeps)
{
deps = rundeps[package]
sub(/^ /, "", deps)
gsub(/[^[:alnum:]_]/, "_", package)
printf "local _%s_rundeps=\"%s\";\n", package, deps
}
}' )"; then
f_show_err "$msg_unable_to_pkg_rquery_package_dependencies"
f_device_shutdown device_media
return $FAILURE
fi
f_show_info "$msg_generating_index_from_pkg_database"
eval "$__var_to_set"='$( pkg rquery "$INDEX_FORMAT" |
while read LINE; do
package="${LINE%%|*}";
f_str2varname "$package" varpkg;
eval f_replaceall \"\$LINE\" \"\|@CATEGORIES@\|\" \
\"\|\$_${varpkg}_categories\|\" LINE
eval f_replaceall \"\$LINE\" \"\|@RUNDEPS@\|\" \
\"\|\$_${varpkg}_rundeps\|\" LINE
echo "$LINE"
done
)' # always returns true (status of last item in pipe-chain)
eval "$__var_to_set"='$( debug= f_getvar "$__var_to_set" | sort )'
eval "$__var_to_set"='$( pkg rquery -I | sort )'
#
# Attempt to create the persistant on-disk cache

View File

@ -0,0 +1,87 @@
if [ ! "$_PACKAGES_MUSTHAVEPKG_SUBR" ]; then _PACKAGES_MUSTHAVEPKG_SUBR=1
#
# Copyright (c) 2014 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..." packages/musthavepkg.subr
f_include $BSDCFG_SHARE/dialog.subr
f_include $BSDCFG_SHARE/mustberoot.subr
############################################################ FUNCTIONS
# f_musthavepkg_init
#
# Validate pkg(8) is installed and set $PKG_ABI global if not already set.
# Returns success unless pkg(8) is not installed and user refuses to install
# it (upon prompt when running interactively).
#
f_musthavepkg_init()
{
local funcname=f_musthavepkg_init
local pkg_abi_awk='$1~/^ABI/{print $NF; exit}'
if [ "$PKG_ABI" ]; then # Already set
f_dprintf "PKG_ABI=[%s]" "$PKG_ABI"
export PKG_ABI
f_quietly pkg -N -vv # return status (pkg(8) functional?)
return $?
fi
# Attempt to get PKG_ABI without prematurely bootstrapping pkg(8)
if f_eval_catch -k PKG_ABI $funcname pkg \
"pkg -N -vv | awk '%s'" "$pkg_abi_awk"
then
f_dprintf "PKG_ABI=[%s]" "$PKG_ABI"
export PKG_ABI
return $SUCCESS
fi
# pkg(8) not yet bootstrapped; ask for permission unless nonInteractive
f_dialog_yesno "$msg_pkg_not_yet_installed_install_now" ||
f_die 1 "$msg_must_have_pkg_to_execute" "$pgm"
f_mustberoot_init # Have to be root to install pkg(8)
# Bootstrap pkg(8)
f_dialog_info "$msg_bootstrapping_pkg"
f_eval_catch -k PKG_ABI $funcname pkg \
"ASSUME_ALWAYS_YES=1 pkg -vv | awk '%s'" "$pkg_abi_awk" ||
f_die 1 "$msg_must_have_pkg_to_execute" "$pgm"
f_dprintf "PKG_ABI=[%s]" "$PKG_ABI"
export PKG_ABI
return $SUCCESS
}
############################################################ MAIN
f_dprintf "%s: Successfully loaded." packages/musthavepkg.subr
fi # ! $_PACKAGES_MUSTHAVEPKG_SUBR

15
usr.sbin/bsdconfig/share/packages/packages.subr Executable file → Normal file
View File

@ -36,6 +36,7 @@ f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/media/common.subr
f_include $BSDCFG_SHARE/packages/categories.subr
f_include $BSDCFG_SHARE/packages/index.subr
f_include $BSDCFG_SHARE/packages/musthavepkg.subr
f_include $BSDCFG_SHARE/strings.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
@ -662,7 +663,7 @@ f_package_review()
f_package_config()
{
# Did we get an INDEX?
f_index_initialize packages/INDEX || return $FAILURE
f_index_initialize || return $FAILURE
# Creates following variables (indirectly via f_index_read())
# CATEGORY_MENU_LIST _categories_{varpkg} _rundeps_{varpkg}
# PACKAGE_CATEGORIES _npkgs
@ -839,7 +840,7 @@ f_package_add()
{ # Verify and initialize device media if-defined
f_media_verify &&
f_device_init device_media &&
f_index_initialize packages/INDEX
f_index_initialize
} || return $FAILURE
# Now we have (indirectly via f_index_read()):
@ -946,6 +947,8 @@ f_package_extract()
local device="$1" name="$2" depended="$3"
local devname=
f_musthavepkg_init # Make sure we have a usable pkg(8) with $PKG_ABI
$device get name devname
f_dprintf "$funcname: device=[%s] name=[%s] depended=[%s]" \
"$devname" "$name" "$depended"
@ -1026,9 +1029,11 @@ f_package_extract()
# Request the package be added via pkg-install(8)
if f_debugging; then
f_eval_catch $funcname pkg 'pkg -d install -y "%s"' "$name"
f_eval_catch $funcname pkg \
'pkg -d install -${depended:+A}y "%s"' "$name"
else
f_eval_catch $funcname pkg 'pkg install -y "%s"' "$name"
f_eval_catch $funcname pkg \
'pkg install -${depended:+A}y "%s"' "$name"
fi
if [ $? -ne $SUCCESS ]; then
$alert "$msg_pkg_install_apparently_did_not_like_the_package" \
@ -1065,7 +1070,7 @@ f_package_delete()
{ # Verify and initialize device media if-defined
f_media_verify &&
f_device_init device_media &&
f_index_initialize packages/INDEX
f_index_initialize
} || return $FAILURE
# Now we have (indirectly via f_index_read()):