index.subr revision 257817
1250323Sdteskeif [ ! "$_PACKAGES_INDEX_SUBR" ]; then _PACKAGES_INDEX_SUBR=1 2250323Sdteske# 3250323Sdteske# Copyright (c) 2013 Devin Teske 4252980Sdteske# All rights reserved. 5250323Sdteske# 6250323Sdteske# Redistribution and use in source and binary forms, with or without 7250323Sdteske# modification, are permitted provided that the following conditions 8250323Sdteske# are met: 9250323Sdteske# 1. Redistributions of source code must retain the above copyright 10250323Sdteske# notice, this list of conditions and the following disclaimer. 11250323Sdteske# 2. Redistributions in binary form must reproduce the above copyright 12250323Sdteske# notice, this list of conditions and the following disclaimer in the 13250323Sdteske# documentation and/or other materials provided with the distribution. 14250323Sdteske# 15250323Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16252987Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17250323Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18250323Sdteske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19250323Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20252987Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21250323Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22250323Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23250323Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24250323Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25250323Sdteske# SUCH DAMAGE. 26250323Sdteske# 27250323Sdteske# $FreeBSD: head/usr.sbin/bsdconfig/share/packages/index.subr 257817 2013-11-07 21:16:32Z dteske $ 28250323Sdteske# 29250323Sdteske############################################################ INCLUDES 30250323Sdteske 31250323SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 32250323Sdteske. $BSDCFG_SHARE/common.subr || exit 1 33250323Sdteskef_dprintf "%s: loading includes..." packages/index.subr 34250323Sdteskef_include $BSDCFG_SHARE/device.subr 35250323Sdteskef_include $BSDCFG_SHARE/media/common.subr 36250323Sdteskef_include $BSDCFG_SHARE/strings.subr 37250323Sdteske 38250323SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" 39250323Sdteskef_include_lang $BSDCFG_LIBE/include/messages.subr 40250323Sdteske 41250323Sdteske############################################################ GLOBALS 42250323Sdteske 43250323SdteskePACKAGE_INDEX= 44250323Sdteske_INDEX_INITTED= 45250323Sdteske 46257795Sdteske# 47257795Sdteske# Default path to pkg(8) repo-packagesite.sqlite database 48257795Sdteske# 49257795SdteskeSQLITE_REPO="/var/db/pkg/repo-packagesite.sqlite" 50257795Sdteske 51257795Sdteske# 52257795Sdteske# Default path to on-disk cache INDEX file 53257795Sdteske# 54257795SdteskePACKAGES_INDEX_CACHEFILE="/var/run/bsdconfig/packages_INDEX.cache" 55257795Sdteske 56257795Sdteske# 57257795Sdteske# INDEX format for FreeBSD-6.0 or higher: 58257795Sdteske# 59257795Sdteske# package|port-origin|install-prefix|comment|port-desc-file|maintainer| 60257795Sdteske# categories|build-deps|run-deps|www-site|reserve|reserve|reserve|disc 61257795Sdteske# 62257795SdteskeINDEX_FORMAT="%n-%v" # package 63257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o" # port-origin 64257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|%p" # install-prefix 65257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|%c" # comment 66257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o/pkg-descr" # port-desc-file 67257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|%m" # maintainer 68257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|@CATEGORIES@" # place-holder 69257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|" # build-deps 70257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|@RUNDEPS@" # place-holder 71257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|%w" # www-site 72257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|" # reserved 73257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|" # reserved 74257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|" # reserved 75257795SdteskeINDEX_FORMAT="$INDEX_FORMAT|" # disc 76257795Sdteske 77250323Sdteske############################################################ FUNCTIONS 78250323Sdteske 79257795Sdteske# f_index_initialize [$var_to_set] 80250323Sdteske# 81257795Sdteske# Read and initialize the global index. Returns success unless media cannot be 82257795Sdteske# initialized for any reason (e.g. user cancels media selection dialog or an 83257795Sdteske# error occurs). The index is sorted before being loaded into $var_to_set. 84250323Sdteske# 85250323Sdteske# NOTE: The index is processed with f_index_read() [below] after being loaded. 86250323Sdteske# 87250323Sdteskef_index_initialize() 88250323Sdteske{ 89257795Sdteske local __var_to_set="${2:-PACKAGE_INDEX}" 90250323Sdteske 91250323Sdteske [ "$_INDEX_INITTED" ] && return $SUCCESS 92250323Sdteske 93250323Sdteske # Got any media? 94250323Sdteske f_media_verify || return $FAILURE 95250323Sdteske 96250323Sdteske # Does it move when you kick it? 97250323Sdteske f_device_init media || return $FAILURE 98250323Sdteske 99257795Sdteske f_show_info "$msg_attempting_to_update_repository_catalogue" 100257795Sdteske 101257795Sdteske # 102257795Sdteske # Generate $PACKAGESITE variable for pkg(8) based on media type 103257795Sdteske # 104257795Sdteske local __type __data __site 105257795Sdteske device_media get type __type 106257795Sdteske device_media get private __data 107257795Sdteske case "$__type" in 108257795Sdteske $DEVICE_TYPE_UFS|$DEVICE_TYPE_DISK) __site="file://$MOUNTPOINT" ;; 109257795Sdteske $DEVICE_TYPE_DIRECTORY) __site="file://$__data" ;; 110257795Sdteske $DEVICE_TYPE_FLOPPY) __site="file://${__data:-$MOUNTPOINT}" ;; 111257795Sdteske $DEVICE_TYPE_FTP) f_getvar $VAR_FTP_PATH __site ;; 112257795Sdteske $DEVICE_TYPE_HTTP_PROXY) f_getvar $VAR_HTTP_PROXY_PATH __site ;; 113257795Sdteske $DEVICE_TYPE_HTTP) f_getvar $VAR_HTTP_PATH __site ;; 114257795Sdteske $DEVICE_TYPE_CDROM) __site="file://$MOUNTPOINT" ;; 115257795Sdteske $DEVICE_TYPE_USB) __site="file://$MOUNTPOINT" ;; 116257795Sdteske $DEVICE_TYPE_DOS) __site="file://$MOUNTPOINT" ;; 117257795Sdteske $DEVICE_TYPE_NFS) __site="file://$MOUNTPOINT" ;; 118257795Sdteske esac 119257795Sdteske 120257795Sdteske if ! PACKAGESITE="$__site" f_quietly pkg update; then 121257795Sdteske f_show_err "$msg_unable_to_update_pkg_from_selected_media" 122250323Sdteske f_device_shutdown media 123250323Sdteske return $FAILURE 124250323Sdteske fi 125257795Sdteske 126257795Sdteske # 127257795Sdteske # Try to get contents from validated on-disk cache 128257795Sdteske # 129257795Sdteske 130257795Sdteske # 131257795Sdteske # Calculate digest used to determine if the on-disk persistant cache 132257795Sdteske # INDEX (containing this digest on the first line) is valid and can be 133257795Sdteske # used to quickly populate the environment. 134257795Sdteske # 135257795Sdteske local __sqlite_digest 136257795Sdteske if ! __sqlite_digest=$( md5 < "$SQLITE_REPO" 2> /dev/null ); then 137257795Sdteske f_show_err "$msg_no_pkg_database_found" 138257795Sdteske f_device_shutdown media 139257795Sdteske return $FAILURE 140257795Sdteske fi 141257795Sdteske 142257795Sdteske # 143257795Sdteske # Check to see if the persistant cache INDEX file exists 144257795Sdteske # 145257795Sdteske if [ -f "$PACKAGES_INDEX_CACHEFILE" ]; then 146257795Sdteske # 147257795Sdteske # Attempt to populate the environment with the (soon to be) 148257795Sdteske # validated on-disk cache. If validation fails, fall-back to 149257795Sdteske # generating a fresh cache. 150257795Sdteske # 151257795Sdteske if eval $__var_to_set='$( 152257795Sdteske ( # Get digest as the first word on first line 153257795Sdteske read digest rest_ignored 154257795Sdteske 155257795Sdteske # 156257795Sdteske # If the stored digest matches the calculated- 157257795Sdteske # one populate the environment from the on-disk 158257795Sdteske # cache and provide success exit status. 159257795Sdteske # 160257795Sdteske if [ "$digest" = "$__sqlite_digest" ]; then 161257795Sdteske cat 162257795Sdteske exit $SUCCESS 163257795Sdteske else 164257795Sdteske # Otherwise, return the current value 165257795Sdteske eval echo \"\$__var_to_set\" 166257795Sdteske exit $FAILURE 167257795Sdteske fi 168257795Sdteske ) < "$PACKAGES_INDEX_CACHEFILE" 2> /dev/null 169257795Sdteske )'; then 170257795Sdteske f_show_info \ 171257795Sdteske "$msg_located_index_now_reading_package_data_from_it" 172257795Sdteske if ! f_index_read "$__var_to_set"; then 173257795Sdteske f_show_err \ 174257795Sdteske "$msg_io_or_format_error_on_index_file" 175257795Sdteske return $FAILURE 176257795Sdteske fi 177257795Sdteske _INDEX_INITTED=1 178257795Sdteske return $SUCCESS 179257795Sdteske fi 180257795Sdteske # Otherwise, fall-thru to create a fresh cache from scratch 181257795Sdteske fi 182257795Sdteske 183257795Sdteske # 184257795Sdteske # If we reach this point, we need to generate the data from scratch 185257795Sdteske # 186257795Sdteske 187257795Sdteske f_show_info "$msg_getting_package_categories_via_pkg_rquery" 188257795Sdteske if ! eval "$( pkg rquery "%n-%v %C" | awk ' 189257795Sdteske { categories[$1] = categories[$1] " " $2 } 190257795Sdteske END { 191257795Sdteske for (package in categories) 192257795Sdteske { 193257795Sdteske cats = categories[package] 194257795Sdteske sub(/^ /, "", cats) 195257795Sdteske gsub(/[^[:alnum:]_]/, "_", package) 196257795Sdteske printf "local _%s_categories=\"%s\";\n", package, cats 197257795Sdteske } 198257795Sdteske }' )"; then 199257817Sdteske f_show_err "$msg_unable_to_pkg_rquery_package_dependencies" 200257795Sdteske f_device_shutdown media 201257795Sdteske return $FAILURE 202257795Sdteske fi 203257795Sdteske 204257795Sdteske f_show_info "$msg_getting_package_dependencies_via_pkg_rquery" 205257795Sdteske if ! eval "$( pkg rquery "%n-%v %dn-%dv" | awk ' 206257795Sdteske { rundeps[$1] = rundeps[$1] " " $2 } 207257795Sdteske END { 208257795Sdteske for (package in rundeps) 209257795Sdteske { 210257795Sdteske deps = rundeps[package] 211257795Sdteske sub(/^ /, "", deps) 212257795Sdteske gsub(/[^[:alnum:]_]/, "_", package) 213257795Sdteske printf "local _%s_rundeps=\"%s\";\n", package, deps 214257795Sdteske } 215257795Sdteske }' )"; then 216257817Sdteske f_show_err "$msg_unable_to_pkg_rquery_package_dependencies" 217257795Sdteske f_device_shutdown media 218257795Sdteske return $FAILURE 219257795Sdteske fi 220257795Sdteske 221257795Sdteske f_show_info "$msg_generating_index_from_pkg_database" 222257795Sdteske eval "$__var_to_set"='$( pkg rquery "$INDEX_FORMAT" | 223257795Sdteske while read LINE; do 224257795Sdteske package="${LINE%%|*}"; 225257795Sdteske f_str2varname "$package" varpkg; 226257795Sdteske eval f_replaceall \"\$LINE\" \"\|@CATEGORIES@\|\" \ 227257795Sdteske \"\|\$_${varpkg}_categories\|\" LINE 228257795Sdteske eval f_replaceall \"\$LINE\" \"\|@RUNDEPS@\|\" \ 229257795Sdteske \"\|\$_${varpkg}_rundeps\|\" LINE 230257795Sdteske echo "$LINE" 231257795Sdteske done 232257795Sdteske )' # always returns true (status of last item in pipe-chain) 233251276Sdteske eval "$__var_to_set"='$( debug= f_getvar "$__var_to_set" | sort )' 234250323Sdteske 235257795Sdteske # 236257795Sdteske # Attempt to create the persistant on-disk cache 237257795Sdteske # 238257795Sdteske 239257795Sdteske # Create a new temporary file to write to 240257795Sdteske local __tmpfile="$( mktemp -t "$pgm" )" 241257795Sdteske if [ "$__tmpfile" ]; then 242257795Sdteske # Write the temporary file contents 243257795Sdteske echo "$__sqlite_digest" > "$__tmpfile" 244257795Sdteske debug= f_getvar "$__var_to_set" >> "$__tmpfile" 245257795Sdteske 246257795Sdteske # Finally, move the temporary file into place 247257795Sdteske case "$PACKAGES_INDEX_CACHEFILE" in 248257795Sdteske */*) f_quietly mkdir -p "${PACKAGES_INDEX_CACHEFILE%/*}" 249257795Sdteske esac 250257795Sdteske f_quietly mv -f "$__tmpfile" "$PACKAGES_INDEX_CACHEFILE" 251257795Sdteske fi 252257795Sdteske 253250323Sdteske f_show_info "$msg_located_index_now_reading_package_data_from_it" 254250323Sdteske if ! f_index_read "$__var_to_set"; then 255257795Sdteske f_show_err "$msg_io_or_format_error_on_index_file" 256250323Sdteske return $FAILURE 257250323Sdteske fi 258250323Sdteske 259250323Sdteske _INDEX_INITTED=1 260250323Sdteske return $SUCCESS 261250323Sdteske} 262250323Sdteske 263250323Sdteske# f_index_read [$var_to_get] 264250323Sdteske# 265250323Sdteske# Process the INDEX file (contents contained in $var_to_get) and... 266250323Sdteske# 267250323Sdteske# 1. create a list ($CATEGORY_MENU_LIST) of categories with package counts 268250323Sdteske# 2. For convenience, create $_npkgs holding the total number of all packages 269250323Sdteske# 3. extract associative categories for each package into $_categories_$varpkg 270250323Sdteske# 4. extract runtime dependencies for each package into $_rundeps_$varpkg 271250323Sdteske# 5. extract a [sorted] list of categories into $PACKAGE_CATEGORIES 272250323Sdteske# 6. create $_npkgs_$varcat holding the total number of packages in category 273250323Sdteske# 274250323Sdteske# NOTE: $varpkg is the product of f_str2varname $package varpkg 275250323Sdteske# NOTE: $package is the name as it appears in the INDEX (no archive suffix) 276250323Sdteske# NOTE: We only show categories for which there are at least one package. 277250323Sdteske# NOTE: $varcat is the product of f_str2varname $category varcat 278250323Sdteske# 279250323Sdteskef_index_read() 280250323Sdteske{ 281250323Sdteske local var_to_get="${1:-PACKAGE_INDEX}" 282250323Sdteske 283250323Sdteske # Export variables required by awk(1) below 284250323Sdteske export msg_no_description_provided 285250323Sdteske export msg_all msg_all_desc 286250323Sdteske export VALID_VARNAME_CHARS 287250538Sdteske export msg_packages 288250323Sdteske 289250323Sdteske eval "$( debug= f_getvar "$var_to_get" | awk -F'|' ' 290250323Sdteske function asorti(src, dest) 291250323Sdteske { 292250323Sdteske # Copy src indices to dest and calculate array length 293250323Sdteske nitems = 0; for (i in src) dest[++nitems] = i 294250323Sdteske 295250323Sdteske # Sort the array of indices (dest) using insertion sort method 296250323Sdteske for (i = 1; i <= nitems; k = i++) 297250323Sdteske { 298250323Sdteske idx = dest[i] 299250323Sdteske while ((k > 0) && (dest[k] > idx)) 300250323Sdteske { 301250323Sdteske dest[k+1] = dest[k] 302250323Sdteske k-- 303250323Sdteske } 304250323Sdteske dest[k+1] = idx 305250323Sdteske } 306250323Sdteske 307250323Sdteske return nitems 308250323Sdteske } 309250323Sdteske function print_category(category, npkgs, desc) 310250323Sdteske { 311250323Sdteske cat = category 312250323Sdteske # Accent the category if the first page has been 313250323Sdteske # cached (also acting as a visitation indicator) 314250323Sdteske if ( ENVIRON["_index_page_" varcat "_1"] ) 315250323Sdteske cat = cat "*" 316250538Sdteske printf "'\''%s'\'' '\''%s " packages "'\'' '\''%s'\''\n", 317250323Sdteske cat, npkgs, desc 318250323Sdteske } 319250323Sdteske BEGIN { 320250323Sdteske valid_chars = ENVIRON["VALID_VARNAME_CHARS"] 321250323Sdteske default_desc = ENVIRON["msg_no_description_provided"] 322250538Sdteske packages = ENVIRON["msg_packages"] 323250410Sdteske tpkgs = 0 324250323Sdteske prefix = "" 325250323Sdteske } 326250323Sdteske { 327250410Sdteske tpkgs++ 328250323Sdteske varpkg = $1 329250323Sdteske gsub("[^" valid_chars "]", "_", varpkg) 330250323Sdteske print "_categories_" varpkg "=\"" $7 "\"" 331250323Sdteske split($7, pkg_categories, /[[:space:]]+/) 332250323Sdteske for (pkg_category in pkg_categories) 333250323Sdteske categories[pkg_categories[pkg_category]]++ 334250323Sdteske print "_rundeps_" varpkg "=\"" $9 "\"" 335250323Sdteske } 336250323Sdteske END { 337250410Sdteske print "_npkgs=" tpkgs # For convenience, total package count 338250323Sdteske 339250323Sdteske n = asorti(categories, categories_sorted) 340250323Sdteske 341250323Sdteske # Produce package counts for each category 342250323Sdteske for (i = 1; i <= n; i++) 343250323Sdteske { 344250323Sdteske cat = varcat = categories_sorted[i] 345250323Sdteske npkgs = categories[cat] 346250323Sdteske gsub("[^" valid_chars "]", "_", varcat) 347250323Sdteske print "_npkgs_" varcat "=\"" npkgs "\"" 348250323Sdteske } 349250323Sdteske 350250323Sdteske # Create menu list and generate list of categories at same time 351250323Sdteske print "CATEGORY_MENU_LIST=\"" 352250410Sdteske print_category(ENVIRON["msg_all"], tpkgs, 353250323Sdteske ENVIRON["msg_all_desc"]) 354250323Sdteske category_list = "" 355250323Sdteske for (i = 1; i <= n; i++) 356250323Sdteske { 357250323Sdteske cat = varcat = categories_sorted[i] 358250323Sdteske npkgs = categories[cat] 359250323Sdteske cur_prefix = tolower(substr(cat, 1, 1)) 360250323Sdteske if ( prefix != cur_prefix ) 361250323Sdteske prefix = cur_prefix 362250323Sdteske else 363250323Sdteske cat = " " cat 364250323Sdteske gsub("[^" valid_chars "]", "_", varcat) 365250323Sdteske desc = ENVIRON["_category_" varcat] 366250323Sdteske if ( ! desc ) desc = default_desc 367250323Sdteske print_category(cat, npkgs, desc) 368250323Sdteske category_list = category_list " " cat 369250323Sdteske } 370250323Sdteske print "\"" 371250323Sdteske 372250323Sdteske # Produce the list of categories (calculated in above block) 373250323Sdteske sub(/^ /, "", category_list) 374250323Sdteske print "PACKAGE_CATEGORIES=\"" category_list "\"" 375250323Sdteske 376250323Sdteske }' )" # End-Quote 377250323Sdteske} 378250323Sdteske 379250323Sdteske# f_index_extract_pages $var_to_get $var_basename $pagesize [$category] 380250323Sdteske# 381252738Sdteske# Extracts the package INDEX ($PACKAGE_INDEX by default if/when $var_to_get is 382252738Sdteske# NULL; but should not be missing) into a series of sequential variables 383250323Sdteske# corresponding to "pages" containing up to $pagesize packages. The package 384250323Sdteske# INDEX data must be contained in the variable $var_to_get. The extracted pages 385250323Sdteske# are stored in variables ${var_basename}_# -- where "#" is a the page number. 386250323Sdteske# If $category is set, only packages for that category are extracted. 387250323Sdteske# Otherwise, if $category is "All", missing, or NULL, all packages are 388250323Sdteske# extracted and no filtering is done. 389250323Sdteske# 390250323Sdteskef_index_extract_pages() 391250323Sdteske{ 392252738Sdteske local var_to_get="${1:-PACKAGE_INDEX}" var_basename="$2" pagesize="$3" 393250323Sdteske local category="$4" # Optional 394250323Sdteske 395250323Sdteske eval "$( 396250323Sdteske debug= f_getvar "$var_to_get" | awk -F'|' \ 397250323Sdteske -v cat="$category" \ 398250323Sdteske -v pagesize="$pagesize" \ 399250538Sdteske -v var_basename="$var_basename" \ 400250538Sdteske -v i18n_all="$msg_all" ' 401250323Sdteske BEGIN { n = page = 0 } 402250323Sdteske /'\''/{ gsub(/'\''/, "'\''\\'\'\''") } 403250323Sdteske { 404250538Sdteske if ( cat !~ "(^$|^" i18n_all "$)" && $7 !~ \ 405250323Sdteske "(^|[[:space:]])" cat "([[:space:]]|$)" ) next 406250323Sdteske starting_new_page = (n++ == (pagesize * page)) 407250323Sdteske if ( starting_new_page ) 408250323Sdteske printf "%s%s", ( n > 1 ? "'\''\n" : "" ), 409250323Sdteske var_basename "_" ++page "='\''" 410250323Sdteske printf "%s%s", ( starting_new_page ? "" : "\n" ), $0 411250323Sdteske } 412250323Sdteske END { if ( n > 0 ) print "'\''" }' 413250323Sdteske )" 414250323Sdteske} 415250323Sdteske 416252745Sdteske# f_index_search $var_to_get $name [$var_to_set] 417252745Sdteske# 418252753Sdteske# Search the package INDEX ($PACKAGE_INDEX by default if/when $var_to_get is 419252745Sdteske# NULL; but should not be missing) for $name, returning the first match. 420252745Sdteske# Matches are strict (not regular expressions) and must match the beginning 421252745Sdteske# portion of the package name to be considered a match. If $var_to_set is 422252745Sdteske# missing or NULL, output is sent to standard output. If a match is found, 423252745Sdteske# returns success; otherwise failure. 424252745Sdteske# 425252745Sdteskef_index_search() 426252745Sdteske{ 427252745Sdteske local __var_to_get="${1:-PACKAGE_INDEX}" __pkg_basename="$2" 428252745Sdteske local __var_to_set="$3" 429252745Sdteske 430252745Sdteske f_dprintf "f_index_search: Searching package data (in %s) for %s" \ 431252745Sdteske "$__var_to_get" "$__pkg_basename" 432252745Sdteske 433252745Sdteske local __pkg= 434252745Sdteske __pkg=$( debug= f_getvar "$__var_to_get" | 435252745Sdteske awk -F'|' -v basename="$__pkg_basename" ' 436252745Sdteske BEGIN { n = length(basename) } 437252745Sdteske substr($1, 0, n) == basename { print $1; exit } 438252745Sdteske ' ) 439252745Sdteske if [ ! "$__pkg" ]; then 440252745Sdteske f_dprintf "f_index_search: No packages matching %s found" \ 441252745Sdteske "$__pkg_basename" 442252745Sdteske return $FAILURE 443252745Sdteske fi 444252745Sdteske 445252745Sdteske f_dprintf "f_index_search: Found package %s" "$__pkg" 446252745Sdteske if [ "$__var_to_set" ]; then 447252745Sdteske setvar "$__var_to_set" "$__pkg" 448252745Sdteske else 449252745Sdteske echo "$__pkg" 450252745Sdteske fi 451252745Sdteske return $SUCCESS 452252745Sdteske} 453252745Sdteske 454250323Sdteske############################################################ MAIN 455250323Sdteske 456250323Sdteskef_dprintf "%s: Successfully loaded." packages/index.subr 457250323Sdteske 458250323Sdteskefi # ! $_PACKAGES_INDEX_SUBR 459