index.subr revision 258420
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: stable/10/usr.sbin/bsdconfig/share/packages/index.subr 258420 2013-11-21 03:38:47Z 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 46258420Sdteske# 47258420Sdteske# Default path to pkg(8) repo-packagesite.sqlite database 48258420Sdteske# 49258420SdteskeSQLITE_REPO="/var/db/pkg/repo-packagesite.sqlite" 50258420Sdteske 51258420Sdteske# 52258420Sdteske# Default path to on-disk cache INDEX file 53258420Sdteske# 54258420SdteskePACKAGES_INDEX_CACHEFILE="/var/run/bsdconfig/packages_INDEX.cache" 55258420Sdteske 56258420Sdteske# 57258420Sdteske# INDEX format for FreeBSD-6.0 or higher: 58258420Sdteske# 59258420Sdteske# package|port-origin|install-prefix|comment|port-desc-file|maintainer| 60258420Sdteske# categories|build-deps|run-deps|www-site|reserve|reserve|reserve|disc 61258420Sdteske# 62258420SdteskeINDEX_FORMAT="%n-%v" # package 63258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o" # port-origin 64258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|%p" # install-prefix 65258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|%c" # comment 66258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o/pkg-descr" # port-desc-file 67258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|%m" # maintainer 68258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|@CATEGORIES@" # place-holder 69258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|" # build-deps 70258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|@RUNDEPS@" # place-holder 71258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|%w" # www-site 72258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|" # reserved 73258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|" # reserved 74258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|" # reserved 75258420SdteskeINDEX_FORMAT="$INDEX_FORMAT|" # disc 76258420Sdteske 77250323Sdteske############################################################ FUNCTIONS 78250323Sdteske 79258420Sdteske# f_index_initialize [$var_to_set] 80250323Sdteske# 81258420Sdteske# Read and initialize the global index. Returns success unless media cannot be 82258420Sdteske# initialized for any reason (e.g. user cancels media selection dialog or an 83258420Sdteske# 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{ 89258420Sdteske local __funcname=f_index_initialize 90258420Sdteske local __var_to_set="${2:-PACKAGE_INDEX}" 91250323Sdteske 92250323Sdteske [ "$_INDEX_INITTED" ] && return $SUCCESS 93250323Sdteske 94250323Sdteske # Got any media? 95250323Sdteske f_media_verify || return $FAILURE 96250323Sdteske 97250323Sdteske # Does it move when you kick it? 98250323Sdteske f_device_init media || return $FAILURE 99250323Sdteske 100258420Sdteske f_show_info "$msg_attempting_to_update_repository_catalogue" 101258420Sdteske 102258420Sdteske # 103258420Sdteske # Generate $PACKAGESITE variable for pkg(8) based on media type 104258420Sdteske # 105258420Sdteske local __type __data __site 106258420Sdteske device_media get type __type 107258420Sdteske device_media get private __data 108258420Sdteske case "$__type" in 109258420Sdteske $DEVICE_TYPE_DIRECTORY) 110258420Sdteske __site="file://$__data/packages/$PKG_ABI" ;; 111258420Sdteske $DEVICE_TYPE_FLOPPY) 112258420Sdteske __site="file://${__data:-$MOUNTPOINT}/packages/$PKG_ABI" ;; 113258420Sdteske $DEVICE_TYPE_FTP) 114258420Sdteske f_getvar $VAR_FTP_PATH __site 115258420Sdteske __site="$__site/packages/$PKG_ABI" ;; 116258420Sdteske $DEVICE_TYPE_HTTP) 117258420Sdteske f_getvar $VAR_HTTP_PATH __site 118258420Sdteske __site="$__site/$PKG_ABI/latest" ;; 119258420Sdteske $DEVICE_TYPE_HTTP_PROXY) 120258420Sdteske f_getvar $VAR_HTTP_PROXY_PATH __site 121258420Sdteske __site="$__site/packages/$PKG_ABI" ;; 122258420Sdteske *) # UFS, DISK, CDROM, USB, DOS, NFS, etc. 123258420Sdteske __site="file://$MOUNTPOINT/packages/$PKG_ABI" 124258420Sdteske esac 125258420Sdteske 126258420Sdteske export PACKAGESITE="$__site" 127258420Sdteske f_dprintf "PACKAGESITE=[%s]" "$PACKAGESITE" 128258420Sdteske if ! f_eval_catch $__funcname pkg "pkg update"; then 129258420Sdteske f_show_err "$msg_unable_to_update_pkg_from_selected_media" 130250323Sdteske f_device_shutdown media 131250323Sdteske return $FAILURE 132250323Sdteske fi 133258420Sdteske 134258420Sdteske # 135258420Sdteske # Try to get contents from validated on-disk cache 136258420Sdteske # 137258420Sdteske 138258420Sdteske # 139258420Sdteske # Calculate digest used to determine if the on-disk persistant cache 140258420Sdteske # INDEX (containing this digest on the first line) is valid and can be 141258420Sdteske # used to quickly populate the environment. 142258420Sdteske # 143258420Sdteske local __sqlite_digest 144258420Sdteske if ! __sqlite_digest=$( md5 < "$SQLITE_REPO" 2> /dev/null ); then 145258420Sdteske f_show_err "$msg_no_pkg_database_found" 146258420Sdteske f_device_shutdown media 147258420Sdteske return $FAILURE 148258420Sdteske fi 149258420Sdteske 150258420Sdteske # 151258420Sdteske # Check to see if the persistant cache INDEX file exists 152258420Sdteske # 153258420Sdteske if [ -f "$PACKAGES_INDEX_CACHEFILE" ]; then 154258420Sdteske # 155258420Sdteske # Attempt to populate the environment with the (soon to be) 156258420Sdteske # validated on-disk cache. If validation fails, fall-back to 157258420Sdteske # generating a fresh cache. 158258420Sdteske # 159258420Sdteske if eval $__var_to_set='$( 160258420Sdteske ( # Get digest as the first word on first line 161258420Sdteske read digest rest_ignored 162258420Sdteske 163258420Sdteske # 164258420Sdteske # If the stored digest matches the calculated- 165258420Sdteske # one populate the environment from the on-disk 166258420Sdteske # cache and provide success exit status. 167258420Sdteske # 168258420Sdteske if [ "$digest" = "$__sqlite_digest" ]; then 169258420Sdteske cat 170258420Sdteske exit $SUCCESS 171258420Sdteske else 172258420Sdteske # Otherwise, return the current value 173258420Sdteske eval echo \"\$__var_to_set\" 174258420Sdteske exit $FAILURE 175258420Sdteske fi 176258420Sdteske ) < "$PACKAGES_INDEX_CACHEFILE" 2> /dev/null 177258420Sdteske )'; then 178258420Sdteske f_show_info \ 179258420Sdteske "$msg_located_index_now_reading_package_data_from_it" 180258420Sdteske if ! f_index_read "$__var_to_set"; then 181258420Sdteske f_show_err \ 182258420Sdteske "$msg_io_or_format_error_on_index_file" 183258420Sdteske return $FAILURE 184258420Sdteske fi 185258420Sdteske _INDEX_INITTED=1 186258420Sdteske return $SUCCESS 187258420Sdteske fi 188258420Sdteske # Otherwise, fall-thru to create a fresh cache from scratch 189258420Sdteske fi 190258420Sdteske 191258420Sdteske # 192258420Sdteske # If we reach this point, we need to generate the data from scratch 193258420Sdteske # 194258420Sdteske 195258420Sdteske f_show_info "$msg_getting_package_categories_via_pkg_rquery" 196258420Sdteske if ! eval "$( pkg rquery "%n-%v %C" | awk ' 197258420Sdteske { categories[$1] = categories[$1] " " $2 } 198258420Sdteske END { 199258420Sdteske for (package in categories) 200258420Sdteske { 201258420Sdteske cats = categories[package] 202258420Sdteske sub(/^ /, "", cats) 203258420Sdteske gsub(/[^[:alnum:]_]/, "_", package) 204258420Sdteske printf "local _%s_categories=\"%s\";\n", package, cats 205258420Sdteske } 206258420Sdteske }' )"; then 207258420Sdteske f_show_err "$msg_unable_to_pkg_rquery_package_dependencies" 208258420Sdteske f_device_shutdown media 209258420Sdteske return $FAILURE 210258420Sdteske fi 211258420Sdteske 212258420Sdteske f_show_info "$msg_getting_package_dependencies_via_pkg_rquery" 213258420Sdteske if ! eval "$( pkg rquery "%n-%v %dn-%dv" | awk ' 214258420Sdteske { rundeps[$1] = rundeps[$1] " " $2 } 215258420Sdteske END { 216258420Sdteske for (package in rundeps) 217258420Sdteske { 218258420Sdteske deps = rundeps[package] 219258420Sdteske sub(/^ /, "", deps) 220258420Sdteske gsub(/[^[:alnum:]_]/, "_", package) 221258420Sdteske printf "local _%s_rundeps=\"%s\";\n", package, deps 222258420Sdteske } 223258420Sdteske }' )"; then 224258420Sdteske f_show_err "$msg_unable_to_pkg_rquery_package_dependencies" 225258420Sdteske f_device_shutdown media 226258420Sdteske return $FAILURE 227258420Sdteske fi 228258420Sdteske 229258420Sdteske f_show_info "$msg_generating_index_from_pkg_database" 230258420Sdteske eval "$__var_to_set"='$( pkg rquery "$INDEX_FORMAT" | 231258420Sdteske while read LINE; do 232258420Sdteske package="${LINE%%|*}"; 233258420Sdteske f_str2varname "$package" varpkg; 234258420Sdteske eval f_replaceall \"\$LINE\" \"\|@CATEGORIES@\|\" \ 235258420Sdteske \"\|\$_${varpkg}_categories\|\" LINE 236258420Sdteske eval f_replaceall \"\$LINE\" \"\|@RUNDEPS@\|\" \ 237258420Sdteske \"\|\$_${varpkg}_rundeps\|\" LINE 238258420Sdteske echo "$LINE" 239258420Sdteske done 240258420Sdteske )' # always returns true (status of last item in pipe-chain) 241251276Sdteske eval "$__var_to_set"='$( debug= f_getvar "$__var_to_set" | sort )' 242250323Sdteske 243258420Sdteske # 244258420Sdteske # Attempt to create the persistant on-disk cache 245258420Sdteske # 246258420Sdteske 247258420Sdteske # Create a new temporary file to write to 248258420Sdteske local __tmpfile="$( mktemp -t "$pgm" )" 249258420Sdteske if [ "$__tmpfile" ]; then 250258420Sdteske # Write the temporary file contents 251258420Sdteske echo "$__sqlite_digest" > "$__tmpfile" 252258420Sdteske debug= f_getvar "$__var_to_set" >> "$__tmpfile" 253258420Sdteske 254258420Sdteske # Finally, move the temporary file into place 255258420Sdteske case "$PACKAGES_INDEX_CACHEFILE" in 256258420Sdteske */*) f_quietly mkdir -p "${PACKAGES_INDEX_CACHEFILE%/*}" 257258420Sdteske esac 258258420Sdteske f_quietly mv -f "$__tmpfile" "$PACKAGES_INDEX_CACHEFILE" 259258420Sdteske fi 260258420Sdteske 261250323Sdteske f_show_info "$msg_located_index_now_reading_package_data_from_it" 262250323Sdteske if ! f_index_read "$__var_to_set"; then 263258420Sdteske f_show_err "$msg_io_or_format_error_on_index_file" 264250323Sdteske return $FAILURE 265250323Sdteske fi 266250323Sdteske 267250323Sdteske _INDEX_INITTED=1 268250323Sdteske return $SUCCESS 269250323Sdteske} 270250323Sdteske 271250323Sdteske# f_index_read [$var_to_get] 272250323Sdteske# 273250323Sdteske# Process the INDEX file (contents contained in $var_to_get) and... 274250323Sdteske# 275250323Sdteske# 1. create a list ($CATEGORY_MENU_LIST) of categories with package counts 276250323Sdteske# 2. For convenience, create $_npkgs holding the total number of all packages 277250323Sdteske# 3. extract associative categories for each package into $_categories_$varpkg 278250323Sdteske# 4. extract runtime dependencies for each package into $_rundeps_$varpkg 279250323Sdteske# 5. extract a [sorted] list of categories into $PACKAGE_CATEGORIES 280250323Sdteske# 6. create $_npkgs_$varcat holding the total number of packages in category 281250323Sdteske# 282250323Sdteske# NOTE: $varpkg is the product of f_str2varname $package varpkg 283250323Sdteske# NOTE: $package is the name as it appears in the INDEX (no archive suffix) 284250323Sdteske# NOTE: We only show categories for which there are at least one package. 285250323Sdteske# NOTE: $varcat is the product of f_str2varname $category varcat 286250323Sdteske# 287250323Sdteskef_index_read() 288250323Sdteske{ 289250323Sdteske local var_to_get="${1:-PACKAGE_INDEX}" 290250323Sdteske 291250323Sdteske # Export variables required by awk(1) below 292250323Sdteske export msg_no_description_provided 293250323Sdteske export msg_all msg_all_desc 294250323Sdteske export VALID_VARNAME_CHARS 295250538Sdteske export msg_packages 296250323Sdteske 297250323Sdteske eval "$( debug= f_getvar "$var_to_get" | awk -F'|' ' 298250323Sdteske function asorti(src, dest) 299250323Sdteske { 300250323Sdteske # Copy src indices to dest and calculate array length 301250323Sdteske nitems = 0; for (i in src) dest[++nitems] = i 302250323Sdteske 303250323Sdteske # Sort the array of indices (dest) using insertion sort method 304250323Sdteske for (i = 1; i <= nitems; k = i++) 305250323Sdteske { 306250323Sdteske idx = dest[i] 307250323Sdteske while ((k > 0) && (dest[k] > idx)) 308250323Sdteske { 309250323Sdteske dest[k+1] = dest[k] 310250323Sdteske k-- 311250323Sdteske } 312250323Sdteske dest[k+1] = idx 313250323Sdteske } 314250323Sdteske 315250323Sdteske return nitems 316250323Sdteske } 317250323Sdteske function print_category(category, npkgs, desc) 318250323Sdteske { 319250323Sdteske cat = category 320250323Sdteske # Accent the category if the first page has been 321250323Sdteske # cached (also acting as a visitation indicator) 322250323Sdteske if ( ENVIRON["_index_page_" varcat "_1"] ) 323250323Sdteske cat = cat "*" 324250538Sdteske printf "'\''%s'\'' '\''%s " packages "'\'' '\''%s'\''\n", 325250323Sdteske cat, npkgs, desc 326250323Sdteske } 327250323Sdteske BEGIN { 328250323Sdteske valid_chars = ENVIRON["VALID_VARNAME_CHARS"] 329250323Sdteske default_desc = ENVIRON["msg_no_description_provided"] 330250538Sdteske packages = ENVIRON["msg_packages"] 331250410Sdteske tpkgs = 0 332250323Sdteske prefix = "" 333250323Sdteske } 334250323Sdteske { 335250410Sdteske tpkgs++ 336250323Sdteske varpkg = $1 337250323Sdteske gsub("[^" valid_chars "]", "_", varpkg) 338250323Sdteske print "_categories_" varpkg "=\"" $7 "\"" 339250323Sdteske split($7, pkg_categories, /[[:space:]]+/) 340250323Sdteske for (pkg_category in pkg_categories) 341250323Sdteske categories[pkg_categories[pkg_category]]++ 342250323Sdteske print "_rundeps_" varpkg "=\"" $9 "\"" 343250323Sdteske } 344250323Sdteske END { 345250410Sdteske print "_npkgs=" tpkgs # For convenience, total package count 346250323Sdteske 347250323Sdteske n = asorti(categories, categories_sorted) 348250323Sdteske 349250323Sdteske # Produce package counts for each category 350250323Sdteske for (i = 1; i <= n; i++) 351250323Sdteske { 352250323Sdteske cat = varcat = categories_sorted[i] 353250323Sdteske npkgs = categories[cat] 354250323Sdteske gsub("[^" valid_chars "]", "_", varcat) 355250323Sdteske print "_npkgs_" varcat "=\"" npkgs "\"" 356250323Sdteske } 357250323Sdteske 358250323Sdteske # Create menu list and generate list of categories at same time 359250323Sdteske print "CATEGORY_MENU_LIST=\"" 360250410Sdteske print_category(ENVIRON["msg_all"], tpkgs, 361250323Sdteske ENVIRON["msg_all_desc"]) 362250323Sdteske category_list = "" 363250323Sdteske for (i = 1; i <= n; i++) 364250323Sdteske { 365250323Sdteske cat = varcat = categories_sorted[i] 366250323Sdteske npkgs = categories[cat] 367250323Sdteske cur_prefix = tolower(substr(cat, 1, 1)) 368250323Sdteske if ( prefix != cur_prefix ) 369250323Sdteske prefix = cur_prefix 370250323Sdteske else 371250323Sdteske cat = " " cat 372250323Sdteske gsub("[^" valid_chars "]", "_", varcat) 373250323Sdteske desc = ENVIRON["_category_" varcat] 374250323Sdteske if ( ! desc ) desc = default_desc 375250323Sdteske print_category(cat, npkgs, desc) 376250323Sdteske category_list = category_list " " cat 377250323Sdteske } 378250323Sdteske print "\"" 379250323Sdteske 380250323Sdteske # Produce the list of categories (calculated in above block) 381250323Sdteske sub(/^ /, "", category_list) 382250323Sdteske print "PACKAGE_CATEGORIES=\"" category_list "\"" 383250323Sdteske 384250323Sdteske }' )" # End-Quote 385250323Sdteske} 386250323Sdteske 387250323Sdteske# f_index_extract_pages $var_to_get $var_basename $pagesize [$category] 388250323Sdteske# 389252738Sdteske# Extracts the package INDEX ($PACKAGE_INDEX by default if/when $var_to_get is 390252738Sdteske# NULL; but should not be missing) into a series of sequential variables 391250323Sdteske# corresponding to "pages" containing up to $pagesize packages. The package 392250323Sdteske# INDEX data must be contained in the variable $var_to_get. The extracted pages 393250323Sdteske# are stored in variables ${var_basename}_# -- where "#" is a the page number. 394250323Sdteske# If $category is set, only packages for that category are extracted. 395250323Sdteske# Otherwise, if $category is "All", missing, or NULL, all packages are 396250323Sdteske# extracted and no filtering is done. 397250323Sdteske# 398250323Sdteskef_index_extract_pages() 399250323Sdteske{ 400252738Sdteske local var_to_get="${1:-PACKAGE_INDEX}" var_basename="$2" pagesize="$3" 401250323Sdteske local category="$4" # Optional 402250323Sdteske 403250323Sdteske eval "$( 404250323Sdteske debug= f_getvar "$var_to_get" | awk -F'|' \ 405250323Sdteske -v cat="$category" \ 406250323Sdteske -v pagesize="$pagesize" \ 407250538Sdteske -v var_basename="$var_basename" \ 408250538Sdteske -v i18n_all="$msg_all" ' 409250323Sdteske BEGIN { n = page = 0 } 410250323Sdteske /'\''/{ gsub(/'\''/, "'\''\\'\'\''") } 411250323Sdteske { 412250538Sdteske if ( cat !~ "(^$|^" i18n_all "$)" && $7 !~ \ 413250323Sdteske "(^|[[:space:]])" cat "([[:space:]]|$)" ) next 414250323Sdteske starting_new_page = (n++ == (pagesize * page)) 415250323Sdteske if ( starting_new_page ) 416250323Sdteske printf "%s%s", ( n > 1 ? "'\''\n" : "" ), 417250323Sdteske var_basename "_" ++page "='\''" 418250323Sdteske printf "%s%s", ( starting_new_page ? "" : "\n" ), $0 419250323Sdteske } 420250323Sdteske END { if ( n > 0 ) print "'\''" }' 421250323Sdteske )" 422250323Sdteske} 423250323Sdteske 424252745Sdteske# f_index_search $var_to_get $name [$var_to_set] 425252745Sdteske# 426252753Sdteske# Search the package INDEX ($PACKAGE_INDEX by default if/when $var_to_get is 427252745Sdteske# NULL; but should not be missing) for $name, returning the first match. 428252745Sdteske# Matches are strict (not regular expressions) and must match the beginning 429252745Sdteske# portion of the package name to be considered a match. If $var_to_set is 430252745Sdteske# missing or NULL, output is sent to standard output. If a match is found, 431252745Sdteske# returns success; otherwise failure. 432252745Sdteske# 433252745Sdteskef_index_search() 434252745Sdteske{ 435252745Sdteske local __var_to_get="${1:-PACKAGE_INDEX}" __pkg_basename="$2" 436252745Sdteske local __var_to_set="$3" 437252745Sdteske 438252745Sdteske f_dprintf "f_index_search: Searching package data (in %s) for %s" \ 439252745Sdteske "$__var_to_get" "$__pkg_basename" 440252745Sdteske 441252745Sdteske local __pkg= 442252745Sdteske __pkg=$( debug= f_getvar "$__var_to_get" | 443252745Sdteske awk -F'|' -v basename="$__pkg_basename" ' 444252745Sdteske BEGIN { n = length(basename) } 445252745Sdteske substr($1, 0, n) == basename { print $1; exit } 446252745Sdteske ' ) 447252745Sdteske if [ ! "$__pkg" ]; then 448252745Sdteske f_dprintf "f_index_search: No packages matching %s found" \ 449252745Sdteske "$__pkg_basename" 450252745Sdteske return $FAILURE 451252745Sdteske fi 452252745Sdteske 453252745Sdteske f_dprintf "f_index_search: Found package %s" "$__pkg" 454252745Sdteske if [ "$__var_to_set" ]; then 455252745Sdteske setvar "$__var_to_set" "$__pkg" 456252745Sdteske else 457252745Sdteske echo "$__pkg" 458252745Sdteske fi 459252745Sdteske return $SUCCESS 460252745Sdteske} 461252745Sdteske 462250323Sdteske############################################################ MAIN 463250323Sdteske 464250323Sdteskef_dprintf "%s: Successfully loaded." packages/index.subr 465250323Sdteske 466250323Sdteskefi # ! $_PACKAGES_INDEX_SUBR 467