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 267680 2014-06-20 17:40:38Z 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=
--- 4 unchanged lines hidden (view full) ---
48#
49SQLITE_REPO="/var/db/pkg/repo-packagesite.sqlite"
50
51#
52# Default path to on-disk cache INDEX file
53#
54PACKAGES_INDEX_CACHEFILE="/var/run/bsdconfig/packages_INDEX.cache"
55
56#
57# INDEX format for FreeBSD-6.0 or higher:
58#
59# package|port-origin|install-prefix|comment|port-desc-file|maintainer|
60# categories|build-deps|run-deps|www-site|reserve|reserve|reserve|disc
61#
62INDEX_FORMAT="%n-%v" # package
63INDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o" # port-origin
64INDEX_FORMAT="$INDEX_FORMAT|%p" # install-prefix
65INDEX_FORMAT="$INDEX_FORMAT|%c" # comment
66INDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o/pkg-descr" # port-desc-file
67INDEX_FORMAT="$INDEX_FORMAT|%m" # maintainer
68INDEX_FORMAT="$INDEX_FORMAT|@CATEGORIES@" # place-holder
69INDEX_FORMAT="$INDEX_FORMAT|" # build-deps
70INDEX_FORMAT="$INDEX_FORMAT|@RUNDEPS@" # place-holder
71INDEX_FORMAT="$INDEX_FORMAT|%w" # www-site
72INDEX_FORMAT="$INDEX_FORMAT|" # reserved
73INDEX_FORMAT="$INDEX_FORMAT|" # reserved
74INDEX_FORMAT="$INDEX_FORMAT|" # reserved
75INDEX_FORMAT="$INDEX_FORMAT|" # disc
76
77############################################################ FUNCTIONS
78
79# f_index_initialize [$var_to_set]
80#
81# Read and initialize the global index. Returns success unless media cannot be
82# initialized for any reason (e.g. user cancels media selection dialog or an
83# error occurs). The index is sorted before being loaded into $var_to_set.
84#
85# NOTE: The index is processed with f_index_read() [below] after being loaded.
86#
87f_index_initialize()
88{
89 local __funcname=f_index_initialize
90 local __var_to_set="${2:-PACKAGE_INDEX}"
91
92 [ "$_INDEX_INITTED" ] && return $SUCCESS
93
94 # Got any media?
95 f_media_verify || return $FAILURE
96
97 # Does it move when you kick it?
98 f_device_init device_media || return $FAILURE
99
100 f_show_info "$msg_attempting_to_update_repository_catalogue"
101
102 #
103 # Generate $PACKAGESITE variable for pkg(8) based on media type
104 #
--- 16 unchanged lines hidden (view full) ---
121 __site="$__site/packages/$PKG_ABI" ;;
122 $DEVICE_TYPE_CDROM)
123 __site="file://$MOUNTPOINT/packages/$PKG_ABI"
124 export REPOS_DIR="$MOUNTPOINT/packages/repos" ;;
125 *) # UFS, DISK, CDROM, USB, DOS, NFS, etc.
126 __site="file://$MOUNTPOINT/packages/$PKG_ABI"
127 esac
128
129 export PACKAGESITE="$__site"
130 f_dprintf "PACKAGESITE=[%s]" "$PACKAGESITE"
131 if ! f_eval_catch $__funcname pkg "pkg update"; then
132 f_show_err "$msg_unable_to_update_pkg_from_selected_media"
133 f_device_shutdown device_media
134 return $FAILURE
135 fi
136
137 #
138 # Try to get contents from validated on-disk cache
139 #
--- 50 unchanged lines hidden (view full) ---
190 fi
191 # Otherwise, fall-thru to create a fresh cache from scratch
192 fi
193
194 #
195 # If we reach this point, we need to generate the data from scratch
196 #
197
198 f_show_info "$msg_getting_package_categories_via_pkg_rquery"
199 if ! eval "$( pkg rquery "%n-%v %C" | awk '
200 { categories[$1] = categories[$1] " " $2 }
201 END {
202 for (package in categories)
203 {
204 cats = categories[package]
205 sub(/^ /, "", cats)
206 gsub(/[^[:alnum:]_]/, "_", package)
207 printf "local _%s_categories=\"%s\";\n", package, cats
208 }
209 }' )"; then
210 f_show_err "$msg_unable_to_pkg_rquery_package_dependencies"
211 f_device_shutdown device_media
212 return $FAILURE
213 fi
214
215 f_show_info "$msg_getting_package_dependencies_via_pkg_rquery"
216 if ! eval "$( pkg rquery "%n-%v %dn-%dv" | awk '
217 { rundeps[$1] = rundeps[$1] " " $2 }
218 END {
219 for (package in rundeps)
220 {
221 deps = rundeps[package]
222 sub(/^ /, "", deps)
223 gsub(/[^[:alnum:]_]/, "_", package)
224 printf "local _%s_rundeps=\"%s\";\n", package, deps
225 }
226 }' )"; then
227 f_show_err "$msg_unable_to_pkg_rquery_package_dependencies"
228 f_device_shutdown device_media
229 return $FAILURE
230 fi
231
232 f_show_info "$msg_generating_index_from_pkg_database"
233 eval "$__var_to_set"='$( pkg rquery "$INDEX_FORMAT" |
234 while read LINE; do
235 package="${LINE%%|*}";
236 f_str2varname "$package" varpkg;
237 eval f_replaceall \"\$LINE\" \"\|@CATEGORIES@\|\" \
238 \"\|\$_${varpkg}_categories\|\" LINE
239 eval f_replaceall \"\$LINE\" \"\|@RUNDEPS@\|\" \
240 \"\|\$_${varpkg}_rundeps\|\" LINE
241 echo "$LINE"
242 done
243 )' # always returns true (status of last item in pipe-chain)
244 eval "$__var_to_set"='$( debug= f_getvar "$__var_to_set" | sort )'
245
246 #
247 # Attempt to create the persistant on-disk cache
248 #
249
250 # Create a new temporary file to write to
251 local __tmpfile
252 if f_eval_catch -dk __tmpfile $__funcname mktemp \
--- 221 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 267680 2014-06-20 17:40:38Z 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=
--- 4 unchanged lines hidden (view full) ---
48#
49SQLITE_REPO="/var/db/pkg/repo-packagesite.sqlite"
50
51#
52# Default path to on-disk cache INDEX file
53#
54PACKAGES_INDEX_CACHEFILE="/var/run/bsdconfig/packages_INDEX.cache"
55
56#
57# INDEX format for FreeBSD-6.0 or higher:
58#
59# package|port-origin|install-prefix|comment|port-desc-file|maintainer|
60# categories|build-deps|run-deps|www-site|reserve|reserve|reserve|disc
61#
62INDEX_FORMAT="%n-%v" # package
63INDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o" # port-origin
64INDEX_FORMAT="$INDEX_FORMAT|%p" # install-prefix
65INDEX_FORMAT="$INDEX_FORMAT|%c" # comment
66INDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o/pkg-descr" # port-desc-file
67INDEX_FORMAT="$INDEX_FORMAT|%m" # maintainer
68INDEX_FORMAT="$INDEX_FORMAT|@CATEGORIES@" # place-holder
69INDEX_FORMAT="$INDEX_FORMAT|" # build-deps
70INDEX_FORMAT="$INDEX_FORMAT|@RUNDEPS@" # place-holder
71INDEX_FORMAT="$INDEX_FORMAT|%w" # www-site
72INDEX_FORMAT="$INDEX_FORMAT|" # reserved
73INDEX_FORMAT="$INDEX_FORMAT|" # reserved
74INDEX_FORMAT="$INDEX_FORMAT|" # reserved
75INDEX_FORMAT="$INDEX_FORMAT|" # disc
76
77############################################################ FUNCTIONS
78
79# f_index_initialize [$var_to_set]
80#
81# Read and initialize the global index. Returns success unless media cannot be
82# initialized for any reason (e.g. user cancels media selection dialog or an
83# error occurs). The index is sorted before being loaded into $var_to_set.
84#
85# NOTE: The index is processed with f_index_read() [below] after being loaded.
86#
87f_index_initialize()
88{
89 local __funcname=f_index_initialize
90 local __var_to_set="${2:-PACKAGE_INDEX}"
91
92 [ "$_INDEX_INITTED" ] && return $SUCCESS
93
94 # Got any media?
95 f_media_verify || return $FAILURE
96
97 # Does it move when you kick it?
98 f_device_init device_media || return $FAILURE
99
100 f_show_info "$msg_attempting_to_update_repository_catalogue"
101
102 #
103 # Generate $PACKAGESITE variable for pkg(8) based on media type
104 #
--- 16 unchanged lines hidden (view full) ---
121 __site="$__site/packages/$PKG_ABI" ;;
122 $DEVICE_TYPE_CDROM)
123 __site="file://$MOUNTPOINT/packages/$PKG_ABI"
124 export REPOS_DIR="$MOUNTPOINT/packages/repos" ;;
125 *) # UFS, DISK, CDROM, USB, DOS, NFS, etc.
126 __site="file://$MOUNTPOINT/packages/$PKG_ABI"
127 esac
128
129 export PACKAGESITE="$__site"
130 f_dprintf "PACKAGESITE=[%s]" "$PACKAGESITE"
131 if ! f_eval_catch $__funcname pkg "pkg update"; then
132 f_show_err "$msg_unable_to_update_pkg_from_selected_media"
133 f_device_shutdown device_media
134 return $FAILURE
135 fi
136
137 #
138 # Try to get contents from validated on-disk cache
139 #
--- 50 unchanged lines hidden (view full) ---
190 fi
191 # Otherwise, fall-thru to create a fresh cache from scratch
192 fi
193
194 #
195 # If we reach this point, we need to generate the data from scratch
196 #
197
198 f_show_info "$msg_getting_package_categories_via_pkg_rquery"
199 if ! eval "$( pkg rquery "%n-%v %C" | awk '
200 { categories[$1] = categories[$1] " " $2 }
201 END {
202 for (package in categories)
203 {
204 cats = categories[package]
205 sub(/^ /, "", cats)
206 gsub(/[^[:alnum:]_]/, "_", package)
207 printf "local _%s_categories=\"%s\";\n", package, cats
208 }
209 }' )"; then
210 f_show_err "$msg_unable_to_pkg_rquery_package_dependencies"
211 f_device_shutdown device_media
212 return $FAILURE
213 fi
214
215 f_show_info "$msg_getting_package_dependencies_via_pkg_rquery"
216 if ! eval "$( pkg rquery "%n-%v %dn-%dv" | awk '
217 { rundeps[$1] = rundeps[$1] " " $2 }
218 END {
219 for (package in rundeps)
220 {
221 deps = rundeps[package]
222 sub(/^ /, "", deps)
223 gsub(/[^[:alnum:]_]/, "_", package)
224 printf "local _%s_rundeps=\"%s\";\n", package, deps
225 }
226 }' )"; then
227 f_show_err "$msg_unable_to_pkg_rquery_package_dependencies"
228 f_device_shutdown device_media
229 return $FAILURE
230 fi
231
232 f_show_info "$msg_generating_index_from_pkg_database"
233 eval "$__var_to_set"='$( pkg rquery "$INDEX_FORMAT" |
234 while read LINE; do
235 package="${LINE%%|*}";
236 f_str2varname "$package" varpkg;
237 eval f_replaceall \"\$LINE\" \"\|@CATEGORIES@\|\" \
238 \"\|\$_${varpkg}_categories\|\" LINE
239 eval f_replaceall \"\$LINE\" \"\|@RUNDEPS@\|\" \
240 \"\|\$_${varpkg}_rundeps\|\" LINE
241 echo "$LINE"
242 done
243 )' # always returns true (status of last item in pipe-chain)
244 eval "$__var_to_set"='$( debug= f_getvar "$__var_to_set" | sort )'
245
246 #
247 # Attempt to create the persistant on-disk cache
248 #
249
250 # Create a new temporary file to write to
251 local __tmpfile
252 if f_eval_catch -dk __tmpfile $__funcname mktemp \
--- 221 unchanged lines hidden ---