1if [ ! "$_PACKAGES_INDEX_SUBR" ]; then _PACKAGES_INDEX_SUBR=1
2#
3# Copyright (c) 2013 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
--- 10 unchanged lines hidden (view full) ---
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD: head/usr.sbin/bsdconfig/share/packages/index.subr 252987 2013-07-07 18:51:44Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." packages/index.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/media/common.subr
36f_include $BSDCFG_SHARE/strings.subr
37
38BSDCFG_LIBE="/usr/libexec/bsdconfig"
39f_include_lang $BSDCFG_LIBE/include/messages.subr
40
41############################################################ GLOBALS
42
43PACKAGE_INDEX=
44_INDEX_INITTED=
45
46############################################################ FUNCTIONS
47
48# f_index_initialize $path [$var_to_set]
49#
50# Read and initialize the global index. $path is to be relative to the chosen
51# media (not necessarily the filesystem; e.g. FTP) -- this is usually going to
52# be `packages/INDEX'. Returns success unless media cannot be initialized for
53# any reason (e.g. user cancels media selection dialog) or an error occurs. The
54# index is sorted before being loaded into $var_to_set.
55#
56# NOTE: The index is processed with f_index_read() [below] after being loaded.
57#
58f_index_initialize()
59{
60 local __path="$1" __var_to_set="${2:-PACKAGE_INDEX}"
61
62 [ "$_INDEX_INITTED" ] && return $SUCCESS
63 [ "$__path" ] || return $FAILURE
64
65 # Got any media?
66 f_media_verify || return $FAILURE
67
68 # Does it move when you kick it?
69 f_device_init media || return $FAILURE
70
71 f_show_info "$msg_attempting_to_fetch_file_from_selected_media" \
72 "$__path"
73 eval "$__var_to_set"='$( f_device_get media "$__path" )'
74 if [ $? -ne $SUCCESS ]; then
75 f_show_msg "$msg_unable_to_get_file_from_selected_media" \
76 "$__path"
77 f_device_shutdown media
78 return $FAILURE
79 fi
80 eval "$__var_to_set"='$( debug= f_getvar "$__var_to_set" | sort )'
81
82 f_show_info "$msg_located_index_now_reading_package_data_from_it"
83 if ! f_index_read "$__var_to_set"; then
84 f_show_msg "$msg_io_or_format_error_on_index_file" "$__path"
85 return $FAILURE
86 fi
87
88 _INDEX_INITTED=1
89 return $SUCCESS
90}
91
92# f_index_read [$var_to_get]
--- 195 unchanged lines hidden ---
2#
3# Copyright (c) 2013 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
--- 10 unchanged lines hidden (view full) ---
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD: head/usr.sbin/bsdconfig/share/packages/index.subr 252987 2013-07-07 18:51:44Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." packages/index.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/media/common.subr
36f_include $BSDCFG_SHARE/strings.subr
37
38BSDCFG_LIBE="/usr/libexec/bsdconfig"
39f_include_lang $BSDCFG_LIBE/include/messages.subr
40
41############################################################ GLOBALS
42
43PACKAGE_INDEX=
44_INDEX_INITTED=
45
46############################################################ FUNCTIONS
47
48# f_index_initialize $path [$var_to_set]
49#
50# Read and initialize the global index. $path is to be relative to the chosen
51# media (not necessarily the filesystem; e.g. FTP) -- this is usually going to
52# be `packages/INDEX'. Returns success unless media cannot be initialized for
53# any reason (e.g. user cancels media selection dialog) or an error occurs. The
54# index is sorted before being loaded into $var_to_set.
55#
56# NOTE: The index is processed with f_index_read() [below] after being loaded.
57#
58f_index_initialize()
59{
60 local __path="$1" __var_to_set="${2:-PACKAGE_INDEX}"
61
62 [ "$_INDEX_INITTED" ] && return $SUCCESS
63 [ "$__path" ] || return $FAILURE
64
65 # Got any media?
66 f_media_verify || return $FAILURE
67
68 # Does it move when you kick it?
69 f_device_init media || return $FAILURE
70
71 f_show_info "$msg_attempting_to_fetch_file_from_selected_media" \
72 "$__path"
73 eval "$__var_to_set"='$( f_device_get media "$__path" )'
74 if [ $? -ne $SUCCESS ]; then
75 f_show_msg "$msg_unable_to_get_file_from_selected_media" \
76 "$__path"
77 f_device_shutdown media
78 return $FAILURE
79 fi
80 eval "$__var_to_set"='$( debug= f_getvar "$__var_to_set" | sort )'
81
82 f_show_info "$msg_located_index_now_reading_package_data_from_it"
83 if ! f_index_read "$__var_to_set"; then
84 f_show_msg "$msg_io_or_format_error_on_index_file" "$__path"
85 return $FAILURE
86 fi
87
88 _INDEX_INITTED=1
89 return $SUCCESS
90}
91
92# f_index_read [$var_to_get]
--- 195 unchanged lines hidden ---