1if [ ! "$_PACKAGES_PACKAGES_SUBR" ]; then _PACKAGES_PACKAGES_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: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INLUDING, 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#
| 1if [ ! "$_PACKAGES_PACKAGES_SUBR" ]; then _PACKAGES_PACKAGES_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: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INLUDING, 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/packages.subr 252742 2013-07-05 01:32:39Z dteske $
| 27# $FreeBSD: head/usr.sbin/bsdconfig/share/packages/packages.subr 252745 2013-07-05 01:44:59Z dteske $
|
28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." "$0" 34f_include $BSDCFG_SHARE/dialog.subr
| 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." "$0" 34f_include $BSDCFG_SHARE/dialog.subr
|
| 35f_include $BSDCFG_SHARE/device.subr 36f_include $BSDCFG_SHARE/media/common.subr
|
35f_include $BSDCFG_SHARE/packages/categories.subr 36f_include $BSDCFG_SHARE/packages/index.subr 37f_include $BSDCFG_SHARE/strings.subr 38 39BSDCFG_LIBE="/usr/libexec/bsdconfig" 40f_include_lang $BSDCFG_LIBE/include/messages.subr 41 42############################################################ CONFIGURATION 43 44# 45# How many packages to display (maximum) per dialog menubox. 46# 47: ${PACKAGE_MENU_PAGESIZE:=2000} 48 49############################################################ GLOBALS 50 51#
| 37f_include $BSDCFG_SHARE/packages/categories.subr 38f_include $BSDCFG_SHARE/packages/index.subr 39f_include $BSDCFG_SHARE/strings.subr 40 41BSDCFG_LIBE="/usr/libexec/bsdconfig" 42f_include_lang $BSDCFG_LIBE/include/messages.subr 43 44############################################################ CONFIGURATION 45 46# 47# How many packages to display (maximum) per dialog menubox. 48# 49: ${PACKAGE_MENU_PAGESIZE:=2000} 50 51############################################################ GLOBALS 52 53#
|
| 54# Package extensions to try 55# 56PACKAGE_EXTENSIONS=".tbz .tbz2 .tgz" 57 58#
|
52# Variables used to track runtime states 53#
| 59# Variables used to track runtime states 60#
|
| 61PACKAGES_DETECTED= # Boolean (NULL/non-NULL); detected installed packages?
|
54PACKAGE_CATEGORIES= # List of package categories parsed from INDEX 55SELECTED_PACKAGES= # Packages selected by user in [X]dialog(1) interface 56 57# 58# Options 59# 60[ "${SHOW_DESC+set}" ] || SHOW_DESC=1 61 62############################################################ FUNCTIONS 63 64# eval f_package_accent_category_menu $var_to_set $CATEGORY_MENU_LIST 65# 66# Accent the CATEGORY_MENU_LIST produced by f_index_read() (see 67# packages/index.subr). Accented information includes adding an asterisk to the 68# category name if its index has been cached, adding the number of installed 69# packages for each category, and adding the number _selected_ packages for 70# each category. 71# 72# NOTE: The reason `eval' is recommended/shown for the syntax above is because 73# the $CATEGORY_MENU_LIST generated by f_index_read() is meant to be expanded 74# prior to execution (it contains a series of pre-quoted strings which act as 75# the interpolated command arguments). 76# 77f_package_accent_category_menu() 78{ 79 local var_to_set="$1" category cat desc help varcat menu_buf n 80 shift 1 # var_to_set 81 while [ $# -gt 0 ]; do 82 category="${1%\*}" desc="${2%%; *}" help="$3" 83 shift 3 # cat/desc/help 84 85 cat="${category# }" # Trim lead space inserted by sort-method 86 f_str2varname "$cat" varcat 87 88 # Add number of installed packages for this category (if any) 89 n=0 90 case "$cat" in 91 "$msg_all") debug= f_getvar "_All_ninstalled" n ;; 92 *) debug= f_getvar "_${varcat}_ninstalled" n ;; 93 esac && 94 [ $n -ge 1 ] && desc="$desc; $n $msg_installed_lc" 95 96 # Add number of selected packages for this category (if any) 97 n=0 98 case "$cat" in 99 "$msg_all") debug= f_getvar "_All_nselected" n ;; 100 *) debug= f_getvar "_${varcat}_nselected" n ;; 101 esac && 102 [ $n -ge 1 ] && desc="$desc; $n $msg_selected" 103 104 # Re-Add asterisk to the category if its index has been cached 105 f_isset _index_page_${varcat}_1 && category="$category*" 106 107 # Update buffer with modified elements 108 menu_buf="$menu_buf 109 '$category' '$desc' '$help'" # End-Quote 110 done 111 setvar "$var_to_set" "$menu_buf" # return our buffer 112} 113 114# f_package_select $package ... 115# 116# Add $package to the list of tracked/selected packages. If $package is already 117# being tracked (already apears in $SELECTED_PACKAGES), this function amounts 118# to having no effect. 119# 120f_package_select() 121{ 122 local package pkgsel 123 while [ $# -gt 0 ]; do 124 package="$1" 125 shift 1 # package 126 for pkgsel in $SELECTED_PACKAGES; do 127 [ "$package" = "$pkgsel" ] && return 128 done 129 SELECTED_PACKAGES="$SELECTED_PACKAGES $package" 130 done 131 SELECTED_PACKAGES="${SELECTED_PACKAGES# }" # Trim leading space 132} 133 134# f_package_deselect $package ... 135# 136# Remove $package from teh list of tracked/selected packages. If $package is 137# not being tracked (doesn't appear in $SELECTED_PACKAGES), this function 138# amounts to having no effet. 139# 140f_package_deselect() 141{ 142 local package pkgsel 143 while [ $# -gt 1 ]; do 144 local new_list="" 145 package="$1" 146 shift 1 # package 147 for pkgsel in $SELECTED_PACKAGES; do 148 [ "$pkgsel" = "$package" ] && continue 149 new_list="$new_list${new_list:+ }$pkgsel" 150 done 151 SELECTED_PACKAGES="$new_list" 152 done 153} 154 155# f_package_detect_installed 156# 157# Detect installed packages. Currently this searches /var/db/pkg for directory 158# entries and marks each entry as an installed/selected package. 159# 160f_package_detect_installed() 161{ 162 local installed package varpkg 163 # 164 # XXX KLUDGE ALERT! This makes evil assumptions about how XXX 165 # packages register themselves and should *really* be done with 166 # `pkg_info -e <name>' except that this is too slow for an 167 # item check routine.. :-( 168 # 169 # NOTE: When transitioning to pkgng, make a single fork to `pkg' to 170 # produce a list of all installed packages and parse _that_ 171 # 172 installed=$( find -s /var/db/pkg -mindepth 1 -maxdepth 1 -type d | 173 sed -e 's:/var/db/pkg/::' ) 174 for package in $installed; do 175 f_str2varname $package varpkg 176 export _mark_$varpkg=X # exported for awk(1) ENVIRON[] 177 f_package_select $package 178 done 179} 180 181# f_package_calculate_totals 182# 183# Calculate number of installed/selected packages for each category listed in 184# $PACKAGE_CATEGORIES (the number of installed packages for $category is stored 185# as $_${varcat}_ninstalled -- where $varcat is the product of `f_str2varname 186# $category varcat' -- and number selected packages as $_${varcat}_nselected). 187# Also calculates the total number of installed/selected packages stored as 188# $_All_ninstalled and $_All_nselected. 189# 190# Calculations are peformed by checking "marks". A "mark" is stored as 191# $_mark_$varpkg -- where $varpkg is the product of `f_str2varname $package 192# varpkg'. A mark can be "X" for an installed package, `I' for a package that 193# is marked for installation, "R" for a package that is marked for re-install, 194# and "U" for a package that is marked for uninstallation. If a package mark is 195# NULL or a single space (e.g., " "), the package is considered to be NOT 196# selected (and therefore does not increment the counts calculated herein). 197# 198f_package_calculate_totals() 199{ 200 local pkg varpkg mark cat varcat pkgcat n tselected=0 tinstalled=0 201 for cat in $PACKAGE_CATEGORIES; do 202 f_str2varname $cat varcat 203 setvar _${varcat}_ninstalled=0 204 setvar _${varcat}_nselected=0 205 done 206 for pkg in $SELECTED_PACKAGES; do 207 f_str2varname $pkg varpkg 208 mark= 209 f_getvar _mark_$varpkg mark 210 case "$mark" in 211 ""|" ") : ;; 212 X) tinstalled=$(( $tinstalled + 1 )) ;; 213 *) tselected=$(( $tselected + 1 )) 214 esac 215 f_getvar _categories_$varpkg pkgcat 216 for cat in $pkgcat; do 217 f_str2varname $cat varcat 218 case "$mark" in 219 ""|" ") : ;; 220 X) debug= f_getvar _${varcat}_ninstalled n 221 setvar _${varcat}_ninstalled $(( $n + 1 )) ;; 222 *) debug= f_getvar _${varcat}_nselected n 223 setvar _${varcat}_nselected $(( $n + 1 )) 224 esac 225 done 226 done 227 _All_nselected=$tselected 228 _All_ninstalled=$tinstalled 229} 230 231# f_package_calculate_rundeps 232# 233# Update package dependencies by first unmarking all dependencies and then 234# re-marking all dependencies of packages marked for either install ("I") or 235# re-install ("R"). 236# 237f_package_calculate_rundeps() 238{ 239 local pkg varpkg mark rundeps dep vardep 240 241 # 242 # First unmark all the existing run-dependencies 243 # 244 f_dprintf "Unselecting package run-dependencies..." 245 for pkg in $SELECTED_PACKAGES; do 246 f_str2varname $pkg varpkg 247 mark= 248 debug= f_getvar _mark_$varpkg mark 249 # Only unmark if it's marked as a Dependency 250 if [ "$mark" = "D" ]; then 251 f_dprintf "%s unselected" $pkg 252 unset _mark_$varpkg 253 f_package_deselect $pkg 254 fi 255 done 256 257 # 258 # Processes selected packages, adding dependencies 259 # 260 f_dprintf "Re-selecting package run-dependencies..." 261 for pkg in $SELECTED_PACKAGES; do 262 f_str2varname $pkg varpkg 263 mark= 264 debug= f_getvar _mark_$varpkg mark 265 # Skip pkg unless marked for [Re-]Install 266 [ "$mark" = "I" -o "$mark" = "R" ] || continue 267 f_getvar _rundeps_$varpkg rundeps 268 for dep in $rundeps; do 269 f_str2varname $dep vardep 270 mark= 271 debug= f_getvar _mark_$vardep mark 272 # Skip dep if already marked 273 [ "${mark:- }" = " " ] || continue 274 export _mark_$vardep="D" 275 f_package_select $dep 276 done 277 done 278 279 f_dprintf "Finished recalculating dependencies." 280} 281 282# f_package_menu_categories $var_to_set $defaultitem 283# 284# Dislay the menu of package categories, complete with package counts for each 285# category, accents, and other miscellany. If $defaultitem is non-NULL and 286# matches one of the existing menu-items, it will be pre-highlighted in the 287# menu dialog (HINT: Use f_dialog_menutag_fetch() to populate a local variable 288# that is passed as $defaultitem to highlight the user's last selection). 289# 290f_package_menu_categories() 291{ 292 local var_to_get="$1" defaultitem="$2" 293 local prompt="$msg_please_select_a_category_to_display" 294 local menu_list=" 295 '> $msg_review' '$msg_review_desc' '$msg_review_help' 296 " # End-Quote 297 local hline= 298 299 f_package_calculate_rundeps 300 # updates package mark variables and SELECTED_PACKAGES 301 f_package_calculate_totals 302 # creates _{varcat}_ninstalled and _{varcat}_nselected 303 304 local category_list 305 debug= f_getvar "$var_to_get" category_list || return $FAILURE 306 307 # Accent the category menu list with ninstalled/nselected 308 eval f_package_accent_category_menu category_list $category_list 309 310 # Add list of categories to menu list 311 menu_list="$menu_list $category_list" 312 313 local height width rows 314 eval f_dialog_menu_with_help_size height width rows \ 315 \"\$DIALOG_TITLE\" \ 316 \"\$DIALOG_BACKTITLE\" \ 317 \"\$prompt\" \ 318 \"\$hline\" \ 319 $menu_list 320 local menu_choice 321 menu_choice=$( eval $DIALOG \ 322 --title \"\$DIALOG_TITLE\" \ 323 --backtitle \"\$DIALOG_BACKTITLE\" \ 324 --hline \"\$hline\" \ 325 --item-help \ 326 --default-item \"\$defaultitem\" \ 327 --ok-label \"$msg_select\" \ 328 --cancel-label \"$msg_cancel\" \ 329 --menu \"\$prompt\" \ 330 $height $width $rows \ 331 $menu_list \ 332 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 333 ) 334 local retval=$? 335 f_dialog_menutag_store -s "$menu_choice" 336 return $retval 337} 338 339# f_package_index_get_page $category $page [$var_to_set [$var_to_get]] 340# 341# Obtain a [potentially cached] page of the INDEX file for a given $category. 342# If $page is 1 and the cache has not yet been generated, the cache-generating 343# function f_index_extract_pages() (above) is called to generate all pages 344# (not just the requested page) in cache before returning the requested page. 345# If $page is not 1 and there is no cached page, failure status is returned. 346# 347f_package_index_get_page() 348{ 349 local category="$1" page="$2" var_to_set="$3" var_to_get="$4" varcat 350 f_str2varname "$category" varcat 351 if ! debug= f_getvar "_index_page_${varcat}_$page" $var_to_set && 352 [ "$page" = "1" ] 353 then 354 f_show_info "$msg_building_package_menus" 355 local pagesize="$PACKAGE_MENU_PAGESIZE" 356 f_index_extract_pages "${var_to_get:-PACKAGE_INDEX}" \ 357 _index_page_${varcat} "$pagesize" "$category" 358 debug= f_getvar _index_page_${varcat}_$page $var_to_set 359 360 # Update category default-item because now we're cached 361 [ $page -eq 1 ] && 362 category_defaultitem="${category_defaultitem%\*}*" 363 else 364 return $FAILURE 365 fi 366} 367 368# f_package_menu_select $category [$page [$defaultitem]] 369# 370# Display list of packages for $category, optionally $page N and with a default 371# item selected. If $page is omitted, the first page is displayed (but this 372# only matters if there are multiple pages; which is determined by the global 373# maximum $PACKAGE_MENU_PAGESIZE). 374# 375# On success, if the user doesn't press ESC or choose Cancel, use 376# f_dialog_menuitem_fetch() to populate a local variable with the item (not 377# tag) corresponding to the user's selection. The tag portion of the user's 378# selection is available through f_dialog_menutag_fetch(). 379# 380f_package_menu_select() 381{ 382 local category="$1" page="${2:-1}" 383 local prompt= # Calculated below 384 local menu_list # Calculated below 385 local defaultitem="$3" 386 local hline="$hline_arrows_tab_punc_enter" 387 388 f_isinteger "$page" || return $FAILURE 389 390 local varcat 391 f_str2varname "$category" varcat 392 393 # Get number of packages for this category 394 local npkgs=0 395 case "$category" in 396 "$msg_all"|"") npkgs="${_npkgs:-0}" ;; 397 *) f_getvar _npkgs_$varcat npkgs 398 esac 399 400 # Calculate number of pages 401 local npages=$(( ${npkgs:=0} / $PACKAGE_MENU_PAGESIZE )) 402 403 # Add a page to the pagecount if not evenly divisible 404 [ $(( $npages * $PACKAGE_MENU_PAGESIZE )) -lt $npkgs ] && 405 npages=$(( $npages + 1 )) 406 407 # Print some debugging information 408 f_dprintf "f_package_menu_select: category=[%s] npkgs=%u npages=%u" \ 409 "$category" "$npkgs" "$npages" 410 411 local add_prev="" add_next="" 412 local previous_page="$msg_previous_page" next_page="$msg_next_page" 413 if [ $page -gt 1 ]; then 414 add_prev=1 415 # Accent the `Previous Page' item with an asterisk 416 # if the page-before-previous is loaded/cached 417 f_isset _index_page_${varcat}_$(( $page - 1 )) && 418 previous_page="$previous_page*" 419 fi 420 if [ $page -lt $npages ]; then 421 add_next=1 422 # Accent the `Next Page' item with an asterisk 423 # if the page-after-next is loaded/cached 424 f_isset _index_page_${varcat}_$(( $page + 1 )) && 425 next_page="$next_page*" 426 fi 427 428 local index_page 429 f_package_index_get_page "$category" $page index_page 430 431 menu_list=" 432 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}} 433 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}} 434 $( 435 export SHOW_DESC 436 export VALID_VARNAME_CHARS 437 echo "$index_page" | awk -F'|' -v view="port" ' 438 BEGIN { 439 valid_chars = ENVIRON["VALID_VARNAME_CHARS"] 440 prefix = "" 441 } 442 { 443 cur_prefix = tolower(substr($1, 1, 1)) 444 printf "'\''" 445 if ( prefix != cur_prefix ) 446 prefix = cur_prefix 447 else 448 printf " " 449 package = $1 450 if ( view == "port" ) 451 desc = $2 452 varpkg = package 453 gsub("[^" valid_chars "]", "_", varpkg) 454 mark = ENVIRON["_mark_" varpkg] 455 if ( ! mark ) mark = " " 456 printf "%s'\'' '\''[%c] %s'\''", 457 package, mark, desc 458 if ( ENVIRON["SHOW_DESC"] ) { 459 help = $4 460 gsub(/'\''/, "'\''\\'\'\''", help) 461 printf " '\''%s'\''", help 462 } 463 printf "\n" 464 }' 465 ) 466 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}} 467 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}} 468 " # End-Quote 469 470 # Accept/Translate i18n "All" but other category names must 471 # match tree definitions from INDEX, ports, FTP, etc. 472 case "$category" in 473 "$msg_all"|"") f_category_desc_get "All" prompt ;; 474 *) f_category_desc_get "$category" prompt ;; 475 esac 476 prompt="$prompt $( printf "$msg_page_of_npages" \ 477 "$page" "$npages" )" 478 479 local mheight mwidth mrows 480 eval f_dialog_menu${SHOW_DESC:+_with_help}_size mheight mwidth mrows \ 481 \"\$DIALOG_TITLE\" \"\$DIALOG_BACKTITLE\" \ 482 \"\$prompt\" \"\$hline\" $menu_list 483 local iheight iwidth 484 f_dialog_infobox_size iheight iwidth \ 485 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" \ 486 "$msg_processing_selection" 487 488 local menu_choice 489 menu_choice=$( eval $DIALOG \ 490 --title \"\$DIALOG_TITLE\" \ 491 --backtitle \"\$DIALOG_BACKTITLE\" \ 492 --hline \"\$hline\" \ 493 --keep-tite \ 494 --ok-label \"$msg_select\" \ 495 --cancel-label \"$msg_back\" \ 496 ${SHOW_DESC:+--item-help} \ 497 --default-item \"\$defaultitem\" \ 498 --menu \"\$prompt\" \ 499 $mheight $mwidth $mrows \ 500 $menu_list \ 501 --and-widget \ 502 ${USE_XDIALOG:+--no-buttons} \ 503 --infobox \"\$msg_processing_selection\" \ 504 $iheight $iwidth \ 505 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 506 ) 507 local retval=$? 508 f_dialog_data_sanitize menu_choice 509 f_dialog_menutag_store "$menu_choice" 510 511 if [ $retval -eq $SUCCESS ]; then 512 local item 513 item=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \ 514 \"\$menu_choice\" $menu_list ) 515 f_dialog_menuitem_store "$item" 516 fi 517 518 return $retval 519} 520 521# f_package_menu_deselect $package 522# 523# Display a menu, asking the user what they would like to do with $package 524# with regard to "deselecting" an already installed package. Choices include 525# uninstall, re-install, or cancel (leave $package marked as installed). 526# Returns success if the user does not press ESC or choose Cnacel. Use the 527# f_dialog_menutag_fetch() function upon success to retrieve the user's choice. 528# 529f_package_menu_deselect() 530{ 531 local package="$1" 532 local prompt # Calculated below 533 local menu_list=" 534 'X $msg_installed' '$msg_installed_desc' 535 'R $msg_reinstall' '$msg_reinstall_desc' 536 'U $msg_uninstall' '$msg_uninstall_desc' 537 " # End-Quote 538 local hline="$hline_alnum_arrows_punc_tab_enter" 539 540 prompt=$( printf "$msg_what_would_you_like_to_do_with" "$package" ) 541 542 local height width rows 543 eval f_dialog_menu_size height width rows \ 544 \"\$DIALOG_TITLE\" \ 545 \"\$DIALOG_BACKTITLE\" \ 546 \"\$prompt\" \ 547 \"\$hline\" \ 548 $menu_list 549 local menu_choice 550 menu_choice=$( eval $DIALOG \ 551 --title \"\$DIALOG_TITLE\" \ 552 --backtitle \"\$DIALOG_BACKTITLE\" \ 553 --hline \"\$hline\" \ 554 --ok-label \"$msg_select\" \ 555 --cancel-label \"$msg_cancel\" \ 556 --menu \"\$prompt\" \ 557 $height $width $rows \ 558 $menu_list \ 559 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 560 ) 561 local retval=$? 562 f_dialog_menutag_store -s "$menu_choice" 563 return $retval 564} 565 566# f_package_review 567# 568# Display a review screen, showing selected packages and what they are marked 569# for, before proceeding (if the user does not press ESC or choose Cancel) to 570# operate on each selection. Returns error if no packages have been selected, 571# or the user has pressed ESC, or if they have chosen Cancel. 572# 573f_package_review() 574{ 575 local prompt # Calculated below 576 local menu_list # Calculated below 577 local hline="$hline_alnum_arrows_punc_tab_enter" 578 579 f_dprintf "f_package_review: SELECTED_PACKAGES=[%s]" \ 580 "$SELECTED_PACKAGES" 581 582 prompt=$( printf "$msg_reviewing_selected_packages" "$_All_nselected" ) 583 584 local package varpkg mark 585 for package in $SELECTED_PACKAGES; do 586 mark= 587 f_str2varname "$package" varpkg 588 f_getvar _mark_$varpkg mark 589 [ "$mark" -a ! "${mark#[IRUD]}" ] || continue 590 menu_list="$menu_list 591 '$mark' '$package' 592 " # End-Quote 593 done 594 if [ ! "$menu_list" ]; then 595 f_show_msg "$msg_no_packages_were_selected_for_extraction" 596 return $FAILURE # They might have selected this by accident 597 fi 598 menu_list=$( echo "$menu_list" | sort ) 599 600 local height width rows 601 eval f_dialog_menu_size height width rows \ 602 \"\$DIALOG_TITLE\" \ 603 \"\$DIALOG_BACKTITLE\" \ 604 \"\$prompt\" \ 605 \"\$hline\" \ 606 $menu_list 607 608 # Show the review menu (ignore menu choice) 609 eval $DIALOG \ 610 --title \"\$DIALOG_TITLE\" \ 611 --backtitle \"\$DIALOG_BACKTITLE\" \ 612 --hline \"\$hline\" \ 613 --ok-label \"\$msg_proceed\" \ 614 --cancel-label \"\$msg_cancel\" \ 615 --menu \"\$prompt\" \ 616 $height $width $rows \ 617 $menu_list \ 618 2> /dev/null || return $? 619 # Return if the user pressed ESC or chose Cancel/No 620 621 # 622 # Process each of the selected packages: 623 # + First, process packages marked for Install. 624 # + Second, process packages marked for Re-install. 625 # + Finally, process packages marked for Uninstall. 626 # 627 for package in $SELECTED_PACKAGES; do 628 mark= 629 f_str2varname "$package" varpkg 630 f_getvar _mark_$varpkg mark 631 [ "$mark" = "I" ] || continue
| 62PACKAGE_CATEGORIES= # List of package categories parsed from INDEX 63SELECTED_PACKAGES= # Packages selected by user in [X]dialog(1) interface 64 65# 66# Options 67# 68[ "${SHOW_DESC+set}" ] || SHOW_DESC=1 69 70############################################################ FUNCTIONS 71 72# eval f_package_accent_category_menu $var_to_set $CATEGORY_MENU_LIST 73# 74# Accent the CATEGORY_MENU_LIST produced by f_index_read() (see 75# packages/index.subr). Accented information includes adding an asterisk to the 76# category name if its index has been cached, adding the number of installed 77# packages for each category, and adding the number _selected_ packages for 78# each category. 79# 80# NOTE: The reason `eval' is recommended/shown for the syntax above is because 81# the $CATEGORY_MENU_LIST generated by f_index_read() is meant to be expanded 82# prior to execution (it contains a series of pre-quoted strings which act as 83# the interpolated command arguments). 84# 85f_package_accent_category_menu() 86{ 87 local var_to_set="$1" category cat desc help varcat menu_buf n 88 shift 1 # var_to_set 89 while [ $# -gt 0 ]; do 90 category="${1%\*}" desc="${2%%; *}" help="$3" 91 shift 3 # cat/desc/help 92 93 cat="${category# }" # Trim lead space inserted by sort-method 94 f_str2varname "$cat" varcat 95 96 # Add number of installed packages for this category (if any) 97 n=0 98 case "$cat" in 99 "$msg_all") debug= f_getvar "_All_ninstalled" n ;; 100 *) debug= f_getvar "_${varcat}_ninstalled" n ;; 101 esac && 102 [ $n -ge 1 ] && desc="$desc; $n $msg_installed_lc" 103 104 # Add number of selected packages for this category (if any) 105 n=0 106 case "$cat" in 107 "$msg_all") debug= f_getvar "_All_nselected" n ;; 108 *) debug= f_getvar "_${varcat}_nselected" n ;; 109 esac && 110 [ $n -ge 1 ] && desc="$desc; $n $msg_selected" 111 112 # Re-Add asterisk to the category if its index has been cached 113 f_isset _index_page_${varcat}_1 && category="$category*" 114 115 # Update buffer with modified elements 116 menu_buf="$menu_buf 117 '$category' '$desc' '$help'" # End-Quote 118 done 119 setvar "$var_to_set" "$menu_buf" # return our buffer 120} 121 122# f_package_select $package ... 123# 124# Add $package to the list of tracked/selected packages. If $package is already 125# being tracked (already apears in $SELECTED_PACKAGES), this function amounts 126# to having no effect. 127# 128f_package_select() 129{ 130 local package pkgsel 131 while [ $# -gt 0 ]; do 132 package="$1" 133 shift 1 # package 134 for pkgsel in $SELECTED_PACKAGES; do 135 [ "$package" = "$pkgsel" ] && return 136 done 137 SELECTED_PACKAGES="$SELECTED_PACKAGES $package" 138 done 139 SELECTED_PACKAGES="${SELECTED_PACKAGES# }" # Trim leading space 140} 141 142# f_package_deselect $package ... 143# 144# Remove $package from teh list of tracked/selected packages. If $package is 145# not being tracked (doesn't appear in $SELECTED_PACKAGES), this function 146# amounts to having no effet. 147# 148f_package_deselect() 149{ 150 local package pkgsel 151 while [ $# -gt 1 ]; do 152 local new_list="" 153 package="$1" 154 shift 1 # package 155 for pkgsel in $SELECTED_PACKAGES; do 156 [ "$pkgsel" = "$package" ] && continue 157 new_list="$new_list${new_list:+ }$pkgsel" 158 done 159 SELECTED_PACKAGES="$new_list" 160 done 161} 162 163# f_package_detect_installed 164# 165# Detect installed packages. Currently this searches /var/db/pkg for directory 166# entries and marks each entry as an installed/selected package. 167# 168f_package_detect_installed() 169{ 170 local installed package varpkg 171 # 172 # XXX KLUDGE ALERT! This makes evil assumptions about how XXX 173 # packages register themselves and should *really* be done with 174 # `pkg_info -e <name>' except that this is too slow for an 175 # item check routine.. :-( 176 # 177 # NOTE: When transitioning to pkgng, make a single fork to `pkg' to 178 # produce a list of all installed packages and parse _that_ 179 # 180 installed=$( find -s /var/db/pkg -mindepth 1 -maxdepth 1 -type d | 181 sed -e 's:/var/db/pkg/::' ) 182 for package in $installed; do 183 f_str2varname $package varpkg 184 export _mark_$varpkg=X # exported for awk(1) ENVIRON[] 185 f_package_select $package 186 done 187} 188 189# f_package_calculate_totals 190# 191# Calculate number of installed/selected packages for each category listed in 192# $PACKAGE_CATEGORIES (the number of installed packages for $category is stored 193# as $_${varcat}_ninstalled -- where $varcat is the product of `f_str2varname 194# $category varcat' -- and number selected packages as $_${varcat}_nselected). 195# Also calculates the total number of installed/selected packages stored as 196# $_All_ninstalled and $_All_nselected. 197# 198# Calculations are peformed by checking "marks". A "mark" is stored as 199# $_mark_$varpkg -- where $varpkg is the product of `f_str2varname $package 200# varpkg'. A mark can be "X" for an installed package, `I' for a package that 201# is marked for installation, "R" for a package that is marked for re-install, 202# and "U" for a package that is marked for uninstallation. If a package mark is 203# NULL or a single space (e.g., " "), the package is considered to be NOT 204# selected (and therefore does not increment the counts calculated herein). 205# 206f_package_calculate_totals() 207{ 208 local pkg varpkg mark cat varcat pkgcat n tselected=0 tinstalled=0 209 for cat in $PACKAGE_CATEGORIES; do 210 f_str2varname $cat varcat 211 setvar _${varcat}_ninstalled=0 212 setvar _${varcat}_nselected=0 213 done 214 for pkg in $SELECTED_PACKAGES; do 215 f_str2varname $pkg varpkg 216 mark= 217 f_getvar _mark_$varpkg mark 218 case "$mark" in 219 ""|" ") : ;; 220 X) tinstalled=$(( $tinstalled + 1 )) ;; 221 *) tselected=$(( $tselected + 1 )) 222 esac 223 f_getvar _categories_$varpkg pkgcat 224 for cat in $pkgcat; do 225 f_str2varname $cat varcat 226 case "$mark" in 227 ""|" ") : ;; 228 X) debug= f_getvar _${varcat}_ninstalled n 229 setvar _${varcat}_ninstalled $(( $n + 1 )) ;; 230 *) debug= f_getvar _${varcat}_nselected n 231 setvar _${varcat}_nselected $(( $n + 1 )) 232 esac 233 done 234 done 235 _All_nselected=$tselected 236 _All_ninstalled=$tinstalled 237} 238 239# f_package_calculate_rundeps 240# 241# Update package dependencies by first unmarking all dependencies and then 242# re-marking all dependencies of packages marked for either install ("I") or 243# re-install ("R"). 244# 245f_package_calculate_rundeps() 246{ 247 local pkg varpkg mark rundeps dep vardep 248 249 # 250 # First unmark all the existing run-dependencies 251 # 252 f_dprintf "Unselecting package run-dependencies..." 253 for pkg in $SELECTED_PACKAGES; do 254 f_str2varname $pkg varpkg 255 mark= 256 debug= f_getvar _mark_$varpkg mark 257 # Only unmark if it's marked as a Dependency 258 if [ "$mark" = "D" ]; then 259 f_dprintf "%s unselected" $pkg 260 unset _mark_$varpkg 261 f_package_deselect $pkg 262 fi 263 done 264 265 # 266 # Processes selected packages, adding dependencies 267 # 268 f_dprintf "Re-selecting package run-dependencies..." 269 for pkg in $SELECTED_PACKAGES; do 270 f_str2varname $pkg varpkg 271 mark= 272 debug= f_getvar _mark_$varpkg mark 273 # Skip pkg unless marked for [Re-]Install 274 [ "$mark" = "I" -o "$mark" = "R" ] || continue 275 f_getvar _rundeps_$varpkg rundeps 276 for dep in $rundeps; do 277 f_str2varname $dep vardep 278 mark= 279 debug= f_getvar _mark_$vardep mark 280 # Skip dep if already marked 281 [ "${mark:- }" = " " ] || continue 282 export _mark_$vardep="D" 283 f_package_select $dep 284 done 285 done 286 287 f_dprintf "Finished recalculating dependencies." 288} 289 290# f_package_menu_categories $var_to_set $defaultitem 291# 292# Dislay the menu of package categories, complete with package counts for each 293# category, accents, and other miscellany. If $defaultitem is non-NULL and 294# matches one of the existing menu-items, it will be pre-highlighted in the 295# menu dialog (HINT: Use f_dialog_menutag_fetch() to populate a local variable 296# that is passed as $defaultitem to highlight the user's last selection). 297# 298f_package_menu_categories() 299{ 300 local var_to_get="$1" defaultitem="$2" 301 local prompt="$msg_please_select_a_category_to_display" 302 local menu_list=" 303 '> $msg_review' '$msg_review_desc' '$msg_review_help' 304 " # End-Quote 305 local hline= 306 307 f_package_calculate_rundeps 308 # updates package mark variables and SELECTED_PACKAGES 309 f_package_calculate_totals 310 # creates _{varcat}_ninstalled and _{varcat}_nselected 311 312 local category_list 313 debug= f_getvar "$var_to_get" category_list || return $FAILURE 314 315 # Accent the category menu list with ninstalled/nselected 316 eval f_package_accent_category_menu category_list $category_list 317 318 # Add list of categories to menu list 319 menu_list="$menu_list $category_list" 320 321 local height width rows 322 eval f_dialog_menu_with_help_size height width rows \ 323 \"\$DIALOG_TITLE\" \ 324 \"\$DIALOG_BACKTITLE\" \ 325 \"\$prompt\" \ 326 \"\$hline\" \ 327 $menu_list 328 local menu_choice 329 menu_choice=$( eval $DIALOG \ 330 --title \"\$DIALOG_TITLE\" \ 331 --backtitle \"\$DIALOG_BACKTITLE\" \ 332 --hline \"\$hline\" \ 333 --item-help \ 334 --default-item \"\$defaultitem\" \ 335 --ok-label \"$msg_select\" \ 336 --cancel-label \"$msg_cancel\" \ 337 --menu \"\$prompt\" \ 338 $height $width $rows \ 339 $menu_list \ 340 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 341 ) 342 local retval=$? 343 f_dialog_menutag_store -s "$menu_choice" 344 return $retval 345} 346 347# f_package_index_get_page $category $page [$var_to_set [$var_to_get]] 348# 349# Obtain a [potentially cached] page of the INDEX file for a given $category. 350# If $page is 1 and the cache has not yet been generated, the cache-generating 351# function f_index_extract_pages() (above) is called to generate all pages 352# (not just the requested page) in cache before returning the requested page. 353# If $page is not 1 and there is no cached page, failure status is returned. 354# 355f_package_index_get_page() 356{ 357 local category="$1" page="$2" var_to_set="$3" var_to_get="$4" varcat 358 f_str2varname "$category" varcat 359 if ! debug= f_getvar "_index_page_${varcat}_$page" $var_to_set && 360 [ "$page" = "1" ] 361 then 362 f_show_info "$msg_building_package_menus" 363 local pagesize="$PACKAGE_MENU_PAGESIZE" 364 f_index_extract_pages "${var_to_get:-PACKAGE_INDEX}" \ 365 _index_page_${varcat} "$pagesize" "$category" 366 debug= f_getvar _index_page_${varcat}_$page $var_to_set 367 368 # Update category default-item because now we're cached 369 [ $page -eq 1 ] && 370 category_defaultitem="${category_defaultitem%\*}*" 371 else 372 return $FAILURE 373 fi 374} 375 376# f_package_menu_select $category [$page [$defaultitem]] 377# 378# Display list of packages for $category, optionally $page N and with a default 379# item selected. If $page is omitted, the first page is displayed (but this 380# only matters if there are multiple pages; which is determined by the global 381# maximum $PACKAGE_MENU_PAGESIZE). 382# 383# On success, if the user doesn't press ESC or choose Cancel, use 384# f_dialog_menuitem_fetch() to populate a local variable with the item (not 385# tag) corresponding to the user's selection. The tag portion of the user's 386# selection is available through f_dialog_menutag_fetch(). 387# 388f_package_menu_select() 389{ 390 local category="$1" page="${2:-1}" 391 local prompt= # Calculated below 392 local menu_list # Calculated below 393 local defaultitem="$3" 394 local hline="$hline_arrows_tab_punc_enter" 395 396 f_isinteger "$page" || return $FAILURE 397 398 local varcat 399 f_str2varname "$category" varcat 400 401 # Get number of packages for this category 402 local npkgs=0 403 case "$category" in 404 "$msg_all"|"") npkgs="${_npkgs:-0}" ;; 405 *) f_getvar _npkgs_$varcat npkgs 406 esac 407 408 # Calculate number of pages 409 local npages=$(( ${npkgs:=0} / $PACKAGE_MENU_PAGESIZE )) 410 411 # Add a page to the pagecount if not evenly divisible 412 [ $(( $npages * $PACKAGE_MENU_PAGESIZE )) -lt $npkgs ] && 413 npages=$(( $npages + 1 )) 414 415 # Print some debugging information 416 f_dprintf "f_package_menu_select: category=[%s] npkgs=%u npages=%u" \ 417 "$category" "$npkgs" "$npages" 418 419 local add_prev="" add_next="" 420 local previous_page="$msg_previous_page" next_page="$msg_next_page" 421 if [ $page -gt 1 ]; then 422 add_prev=1 423 # Accent the `Previous Page' item with an asterisk 424 # if the page-before-previous is loaded/cached 425 f_isset _index_page_${varcat}_$(( $page - 1 )) && 426 previous_page="$previous_page*" 427 fi 428 if [ $page -lt $npages ]; then 429 add_next=1 430 # Accent the `Next Page' item with an asterisk 431 # if the page-after-next is loaded/cached 432 f_isset _index_page_${varcat}_$(( $page + 1 )) && 433 next_page="$next_page*" 434 fi 435 436 local index_page 437 f_package_index_get_page "$category" $page index_page 438 439 menu_list=" 440 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}} 441 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}} 442 $( 443 export SHOW_DESC 444 export VALID_VARNAME_CHARS 445 echo "$index_page" | awk -F'|' -v view="port" ' 446 BEGIN { 447 valid_chars = ENVIRON["VALID_VARNAME_CHARS"] 448 prefix = "" 449 } 450 { 451 cur_prefix = tolower(substr($1, 1, 1)) 452 printf "'\''" 453 if ( prefix != cur_prefix ) 454 prefix = cur_prefix 455 else 456 printf " " 457 package = $1 458 if ( view == "port" ) 459 desc = $2 460 varpkg = package 461 gsub("[^" valid_chars "]", "_", varpkg) 462 mark = ENVIRON["_mark_" varpkg] 463 if ( ! mark ) mark = " " 464 printf "%s'\'' '\''[%c] %s'\''", 465 package, mark, desc 466 if ( ENVIRON["SHOW_DESC"] ) { 467 help = $4 468 gsub(/'\''/, "'\''\\'\'\''", help) 469 printf " '\''%s'\''", help 470 } 471 printf "\n" 472 }' 473 ) 474 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}} 475 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}} 476 " # End-Quote 477 478 # Accept/Translate i18n "All" but other category names must 479 # match tree definitions from INDEX, ports, FTP, etc. 480 case "$category" in 481 "$msg_all"|"") f_category_desc_get "All" prompt ;; 482 *) f_category_desc_get "$category" prompt ;; 483 esac 484 prompt="$prompt $( printf "$msg_page_of_npages" \ 485 "$page" "$npages" )" 486 487 local mheight mwidth mrows 488 eval f_dialog_menu${SHOW_DESC:+_with_help}_size mheight mwidth mrows \ 489 \"\$DIALOG_TITLE\" \"\$DIALOG_BACKTITLE\" \ 490 \"\$prompt\" \"\$hline\" $menu_list 491 local iheight iwidth 492 f_dialog_infobox_size iheight iwidth \ 493 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" \ 494 "$msg_processing_selection" 495 496 local menu_choice 497 menu_choice=$( eval $DIALOG \ 498 --title \"\$DIALOG_TITLE\" \ 499 --backtitle \"\$DIALOG_BACKTITLE\" \ 500 --hline \"\$hline\" \ 501 --keep-tite \ 502 --ok-label \"$msg_select\" \ 503 --cancel-label \"$msg_back\" \ 504 ${SHOW_DESC:+--item-help} \ 505 --default-item \"\$defaultitem\" \ 506 --menu \"\$prompt\" \ 507 $mheight $mwidth $mrows \ 508 $menu_list \ 509 --and-widget \ 510 ${USE_XDIALOG:+--no-buttons} \ 511 --infobox \"\$msg_processing_selection\" \ 512 $iheight $iwidth \ 513 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 514 ) 515 local retval=$? 516 f_dialog_data_sanitize menu_choice 517 f_dialog_menutag_store "$menu_choice" 518 519 if [ $retval -eq $SUCCESS ]; then 520 local item 521 item=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \ 522 \"\$menu_choice\" $menu_list ) 523 f_dialog_menuitem_store "$item" 524 fi 525 526 return $retval 527} 528 529# f_package_menu_deselect $package 530# 531# Display a menu, asking the user what they would like to do with $package 532# with regard to "deselecting" an already installed package. Choices include 533# uninstall, re-install, or cancel (leave $package marked as installed). 534# Returns success if the user does not press ESC or choose Cnacel. Use the 535# f_dialog_menutag_fetch() function upon success to retrieve the user's choice. 536# 537f_package_menu_deselect() 538{ 539 local package="$1" 540 local prompt # Calculated below 541 local menu_list=" 542 'X $msg_installed' '$msg_installed_desc' 543 'R $msg_reinstall' '$msg_reinstall_desc' 544 'U $msg_uninstall' '$msg_uninstall_desc' 545 " # End-Quote 546 local hline="$hline_alnum_arrows_punc_tab_enter" 547 548 prompt=$( printf "$msg_what_would_you_like_to_do_with" "$package" ) 549 550 local height width rows 551 eval f_dialog_menu_size height width rows \ 552 \"\$DIALOG_TITLE\" \ 553 \"\$DIALOG_BACKTITLE\" \ 554 \"\$prompt\" \ 555 \"\$hline\" \ 556 $menu_list 557 local menu_choice 558 menu_choice=$( eval $DIALOG \ 559 --title \"\$DIALOG_TITLE\" \ 560 --backtitle \"\$DIALOG_BACKTITLE\" \ 561 --hline \"\$hline\" \ 562 --ok-label \"$msg_select\" \ 563 --cancel-label \"$msg_cancel\" \ 564 --menu \"\$prompt\" \ 565 $height $width $rows \ 566 $menu_list \ 567 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 568 ) 569 local retval=$? 570 f_dialog_menutag_store -s "$menu_choice" 571 return $retval 572} 573 574# f_package_review 575# 576# Display a review screen, showing selected packages and what they are marked 577# for, before proceeding (if the user does not press ESC or choose Cancel) to 578# operate on each selection. Returns error if no packages have been selected, 579# or the user has pressed ESC, or if they have chosen Cancel. 580# 581f_package_review() 582{ 583 local prompt # Calculated below 584 local menu_list # Calculated below 585 local hline="$hline_alnum_arrows_punc_tab_enter" 586 587 f_dprintf "f_package_review: SELECTED_PACKAGES=[%s]" \ 588 "$SELECTED_PACKAGES" 589 590 prompt=$( printf "$msg_reviewing_selected_packages" "$_All_nselected" ) 591 592 local package varpkg mark 593 for package in $SELECTED_PACKAGES; do 594 mark= 595 f_str2varname "$package" varpkg 596 f_getvar _mark_$varpkg mark 597 [ "$mark" -a ! "${mark#[IRUD]}" ] || continue 598 menu_list="$menu_list 599 '$mark' '$package' 600 " # End-Quote 601 done 602 if [ ! "$menu_list" ]; then 603 f_show_msg "$msg_no_packages_were_selected_for_extraction" 604 return $FAILURE # They might have selected this by accident 605 fi 606 menu_list=$( echo "$menu_list" | sort ) 607 608 local height width rows 609 eval f_dialog_menu_size height width rows \ 610 \"\$DIALOG_TITLE\" \ 611 \"\$DIALOG_BACKTITLE\" \ 612 \"\$prompt\" \ 613 \"\$hline\" \ 614 $menu_list 615 616 # Show the review menu (ignore menu choice) 617 eval $DIALOG \ 618 --title \"\$DIALOG_TITLE\" \ 619 --backtitle \"\$DIALOG_BACKTITLE\" \ 620 --hline \"\$hline\" \ 621 --ok-label \"\$msg_proceed\" \ 622 --cancel-label \"\$msg_cancel\" \ 623 --menu \"\$prompt\" \ 624 $height $width $rows \ 625 $menu_list \ 626 2> /dev/null || return $? 627 # Return if the user pressed ESC or chose Cancel/No 628 629 # 630 # Process each of the selected packages: 631 # + First, process packages marked for Install. 632 # + Second, process packages marked for Re-install. 633 # + Finally, process packages marked for Uninstall. 634 # 635 for package in $SELECTED_PACKAGES; do 636 mark= 637 f_str2varname "$package" varpkg 638 f_getvar _mark_$varpkg mark 639 [ "$mark" = "I" ] || continue
|
632 # XXX Install package
| 640 f_package_add "$package" || continue
|
633 f_package_deselect "$package" 634 done 635 for package in $SELECTED_PACKAGES; do 636 mark= 637 f_str2varname "$package" varpkg 638 f_getvar _mark_$varpkg mark 639 [ "$mark" = "R" ] || continue 640 # XXX Re-install package 641 f_package_deselect "$package" 642 done 643 for package in $SELECTED_PACKAGES; do 644 mark= 645 f_str2varname "$package" varpkg 646 f_getvar _mark_$varpkg mark 647 [ "$mark" = "U" ] || continue 648 # XXX Uninstall package 649 f_package_deselect "$package" 650 done 651 652 return $SUCCESS 653} 654 655# f_package_config 656# 657# Allow the user to configure packages and install them. Initially, a list of 658# package categories is loaded/displayed. When the user selects a category, 659# the menus for that category are built (unlike sysinstall which built all 660# category menus up-front -- which also took forever, despite the fact that 661# few people visit more than a couple of categories each time). 662# 663f_package_config() 664{ 665 # Did we get an INDEX? 666 f_index_initialize packages/INDEX || return $FAILURE 667 # Creates following variables (indirectly via f_index_read()) 668 # CATEGORY_MENU_LIST _categories_{varpkg} _rundeps_{varpkg} 669 # PACKAGE_CATEGORIES _npkgs 670 671 # Detect installed packages (updates marks/SELECTED_PACKAGES) 672 f_package_detect_installed 673 674 local retval category varcat defaultitem category_defaultitem="" 675 while :; do 676 # Display the list of package categories 677 f_package_menu_categories \ 678 CATEGORY_MENU_LIST "$category_defaultitem" 679 retval=$? 680 f_dialog_menutag_fetch category 681 f_dprintf "retval=%u mtag=[%s]" $retval "$category" 682 category_defaultitem="$category" 683 684 [ $retval -eq $SUCCESS ] || break 685 686 # Maybe the user chose an action (like `Review') 687 case "$category" in 688 "> $msg_review") 689 f_package_review && break 690 continue ;; 691 "> "*) 692 continue 693 esac 694 695 # Anything else is a package category 696 697 category=${category# } # Trim leading space if present 698 category=${category%\*} # Trim trailing asterisk if present 699 700 f_str2varname "$category" varcat 701 702 local page package varpkg mark menu_choice 703 while :; do 704 # Display the list of packages for selected category 705 page=1 defaultitem="" 706 f_getvar _defaultitem_$varcat defaultitem 707 f_getvar _defaultpage_$varcat page 708 f_package_menu_select \ 709 "$category" "${page:=1}" "$defaultitem" 710 retval=$? 711 f_dialog_menutag_fetch menu_choice 712 f_dprintf "retval=%u mtag=[%s]" $retval "$menu_choice" 713 714 # NOTE: When --and-widget is used only ESC will cause 715 # dialog(1) to return without going to the next widget. 716 # This is alright in our case as we can still detect 717 # the Cancel button because stdout will be NULL. 718 # Alternatively, Xdialog(1) will terminate with 1 719 # if/when Cancel is chosen on any widget. 720 if [ $retval -eq 255 -o ! "$menu_choice" ]; then 721 # User pressed ESC or chose Cancel 722 break 723 elif [ $retval -eq 1 ]; then 724 # Using X11, Xdialog(1) returned 1 for Cancel 725 f_show_msg "%s" "$menu_choice" 726 break 727 elif [ $retval -ne $SUCCESS ]; then 728 # X11-related error occurred using Xdialog(1) 729 f_show_msg "%s" "$menu_choice" 730 break 731 fi 732 733 defaultitem="$menu_choice" 734 735 # NOTE: f_package_menu_select() does not show the 736 # `Previous Page' or `Next Page' items unless needed 737 case "$menu_choice" in 738 "> $msg_previous_page"|"> $msg_previous_page*") 739 page=$(( $page - 1 )) 740 setvar _defaultpage_$varcat $page 741 # Update default-item to match accent that will 742 # be applied by f_package_menu_select(); if the 743 # page-before-prev is cached, add an asterisk. 744 if f_isset \ 745 _index_page_${varcat}_$(( $page - 1 )) 746 then 747 defaultitem="${defaultitem%\*}*" 748 else 749 defaultitem="${defaultitem%\*}" 750 fi 751 setvar _defaultitem_$varcat "$defaultitem" 752 continue ;; 753 "> $msg_next_page"|"> $msg_next_page*") 754 page=$(( $page + 1 )) 755 setvar _defaultpage_$varcat $page 756 # Update default-item to match accent that will 757 # be applied by f_package_menu_select(); if the 758 # page-after-next is cached, add an asterisk. 759 if f_isset \ 760 _index_page_${varcat}_$(( $page + 1 )) 761 then 762 defaultitem="${defaultitem%\*}*" 763 else 764 defaultitem="${defaultitem%\*}" 765 fi 766 setvar _defaultitem_$varcat "$defaultitem" 767 continue ;; 768 "> "*) # Unknown navigation/action item 769 setvar _defaultpage_$varcat $page 770 continue ;; # Do not treat as a package 771 *) 772 setvar _defaultitem_$varcat "$defaultitem" 773 esac 774 775 # Treat any other selection as a package 776 package="${menu_choice# }" # Trim leading space 777 f_str2varname $package varpkg 778 f_dialog_menuitem_fetch mark 779 mark="${mark#?}" 780 mark="${mark%%\] *}" 781 case "$mark" in 782 "I") 783 mark=" " 784 f_package_deselect $package 785 ;; 786 " "|"D") 787 mark="I" 788 f_package_select $package 789 ;; 790 "X"|"R"|"U") 791 f_package_menu_deselect $package || continue 792 f_dialog_menutag_fetch menu_choice 793 case "$menu_choice" in 794 "X $msg_installed") 795 f_package_deselect "$package" 796 mark="X" 797 ;; 798 "R $msg_reinstall") 799 f_package_select "$package" 800 mark="R" 801 ;; 802 "U $msg_uninstall") 803 f_package_select "$package" 804 mark="U" 805 ;; 806 esac 807 ;; 808 esac 809 export _mark_$varpkg="$mark" 810 # NOTE: exported for awk(1) ENVIRON[] 811 done 812 done 813} 814
| 641 f_package_deselect "$package" 642 done 643 for package in $SELECTED_PACKAGES; do 644 mark= 645 f_str2varname "$package" varpkg 646 f_getvar _mark_$varpkg mark 647 [ "$mark" = "R" ] || continue 648 # XXX Re-install package 649 f_package_deselect "$package" 650 done 651 for package in $SELECTED_PACKAGES; do 652 mark= 653 f_str2varname "$package" varpkg 654 f_getvar _mark_$varpkg mark 655 [ "$mark" = "U" ] || continue 656 # XXX Uninstall package 657 f_package_deselect "$package" 658 done 659 660 return $SUCCESS 661} 662 663# f_package_config 664# 665# Allow the user to configure packages and install them. Initially, a list of 666# package categories is loaded/displayed. When the user selects a category, 667# the menus for that category are built (unlike sysinstall which built all 668# category menus up-front -- which also took forever, despite the fact that 669# few people visit more than a couple of categories each time). 670# 671f_package_config() 672{ 673 # Did we get an INDEX? 674 f_index_initialize packages/INDEX || return $FAILURE 675 # Creates following variables (indirectly via f_index_read()) 676 # CATEGORY_MENU_LIST _categories_{varpkg} _rundeps_{varpkg} 677 # PACKAGE_CATEGORIES _npkgs 678 679 # Detect installed packages (updates marks/SELECTED_PACKAGES) 680 f_package_detect_installed 681 682 local retval category varcat defaultitem category_defaultitem="" 683 while :; do 684 # Display the list of package categories 685 f_package_menu_categories \ 686 CATEGORY_MENU_LIST "$category_defaultitem" 687 retval=$? 688 f_dialog_menutag_fetch category 689 f_dprintf "retval=%u mtag=[%s]" $retval "$category" 690 category_defaultitem="$category" 691 692 [ $retval -eq $SUCCESS ] || break 693 694 # Maybe the user chose an action (like `Review') 695 case "$category" in 696 "> $msg_review") 697 f_package_review && break 698 continue ;; 699 "> "*) 700 continue 701 esac 702 703 # Anything else is a package category 704 705 category=${category# } # Trim leading space if present 706 category=${category%\*} # Trim trailing asterisk if present 707 708 f_str2varname "$category" varcat 709 710 local page package varpkg mark menu_choice 711 while :; do 712 # Display the list of packages for selected category 713 page=1 defaultitem="" 714 f_getvar _defaultitem_$varcat defaultitem 715 f_getvar _defaultpage_$varcat page 716 f_package_menu_select \ 717 "$category" "${page:=1}" "$defaultitem" 718 retval=$? 719 f_dialog_menutag_fetch menu_choice 720 f_dprintf "retval=%u mtag=[%s]" $retval "$menu_choice" 721 722 # NOTE: When --and-widget is used only ESC will cause 723 # dialog(1) to return without going to the next widget. 724 # This is alright in our case as we can still detect 725 # the Cancel button because stdout will be NULL. 726 # Alternatively, Xdialog(1) will terminate with 1 727 # if/when Cancel is chosen on any widget. 728 if [ $retval -eq 255 -o ! "$menu_choice" ]; then 729 # User pressed ESC or chose Cancel 730 break 731 elif [ $retval -eq 1 ]; then 732 # Using X11, Xdialog(1) returned 1 for Cancel 733 f_show_msg "%s" "$menu_choice" 734 break 735 elif [ $retval -ne $SUCCESS ]; then 736 # X11-related error occurred using Xdialog(1) 737 f_show_msg "%s" "$menu_choice" 738 break 739 fi 740 741 defaultitem="$menu_choice" 742 743 # NOTE: f_package_menu_select() does not show the 744 # `Previous Page' or `Next Page' items unless needed 745 case "$menu_choice" in 746 "> $msg_previous_page"|"> $msg_previous_page*") 747 page=$(( $page - 1 )) 748 setvar _defaultpage_$varcat $page 749 # Update default-item to match accent that will 750 # be applied by f_package_menu_select(); if the 751 # page-before-prev is cached, add an asterisk. 752 if f_isset \ 753 _index_page_${varcat}_$(( $page - 1 )) 754 then 755 defaultitem="${defaultitem%\*}*" 756 else 757 defaultitem="${defaultitem%\*}" 758 fi 759 setvar _defaultitem_$varcat "$defaultitem" 760 continue ;; 761 "> $msg_next_page"|"> $msg_next_page*") 762 page=$(( $page + 1 )) 763 setvar _defaultpage_$varcat $page 764 # Update default-item to match accent that will 765 # be applied by f_package_menu_select(); if the 766 # page-after-next is cached, add an asterisk. 767 if f_isset \ 768 _index_page_${varcat}_$(( $page + 1 )) 769 then 770 defaultitem="${defaultitem%\*}*" 771 else 772 defaultitem="${defaultitem%\*}" 773 fi 774 setvar _defaultitem_$varcat "$defaultitem" 775 continue ;; 776 "> "*) # Unknown navigation/action item 777 setvar _defaultpage_$varcat $page 778 continue ;; # Do not treat as a package 779 *) 780 setvar _defaultitem_$varcat "$defaultitem" 781 esac 782 783 # Treat any other selection as a package 784 package="${menu_choice# }" # Trim leading space 785 f_str2varname $package varpkg 786 f_dialog_menuitem_fetch mark 787 mark="${mark#?}" 788 mark="${mark%%\] *}" 789 case "$mark" in 790 "I") 791 mark=" " 792 f_package_deselect $package 793 ;; 794 " "|"D") 795 mark="I" 796 f_package_select $package 797 ;; 798 "X"|"R"|"U") 799 f_package_menu_deselect $package || continue 800 f_dialog_menutag_fetch menu_choice 801 case "$menu_choice" in 802 "X $msg_installed") 803 f_package_deselect "$package" 804 mark="X" 805 ;; 806 "R $msg_reinstall") 807 f_package_select "$package" 808 mark="R" 809 ;; 810 "U $msg_uninstall") 811 f_package_select "$package" 812 mark="U" 813 ;; 814 esac 815 ;; 816 esac 817 export _mark_$varpkg="$mark" 818 # NOTE: exported for awk(1) ENVIRON[] 819 done 820 done 821} 822
|
| 823# f_package_add $package_name [$depended] 824# 825# Like f_package_extract(), but assumes current media device and chases deps. 826# Note that $package_name should not contain the archive suffix (e.g., `.tbz'). 827# If $depended is present and non-NULL, the package is treated as a dependency 828# (in this function, dependencies are not handled any differently, but the 829# f_package_extract() function is passed this value and it displays a different 830# message when installing a dependency versus non-dependency). 831# 832f_package_add() 833{ 834 local name="$1" depended="$2" status=$SUCCESS retval 835 836 local alert=f_show_msg no_confirm= 837 f_getvar $VAR_NO_CONFIRM no_confirm 838 [ "$no_confirm" ] && alert=f_show_info 839 840 if ! { [ "$name" ] || { f_getvar $VAR_PACKAGE name && [ "$name" ]; }; } 841 then 842 f_dprintf "packageAdd: %s" \ 843 "$msg_no_package_name_passed_in_package_variable" 844 return $FAILURE 845 fi 846 847 { # Verify and initialize device media if-defined 848 f_media_verify && 849 f_device_init media && 850 f_index_initialize packages/INDEX 851 } || return $FAILURE 852 853 # Now we have (indirectly via f_index_read()): 854 # CATEGORY_MENU_LIST _categories_{varpkg} _rundeps_{varpkg} 855 # PACKAGE_CATEGORIES _npkgs 856 857 local varpkg 858 f_str2varname "$name" varpkg 859 860 # Just as-in the user-interface (opposed to scripted-use), only allow 861 # packages with at least one category to be recognized. 862 # 863 local pkgcat= 864 if ! f_getvar _categories_$varpkg pkgcat || [ ! "$pkgcat" ]; then 865 # $pkg may be a partial name, search the index (this is slow) 866 f_index_search PACKAGE_INDEX $name name 867 if [ ! "$name" ]; then 868 f_show_msg \ 869 "$msg_sorry_package_was_not_found_in_the_index" \ 870 "$name" 871 return $FAILURE 872 fi 873 f_str2varname "$name" varpkg 874 fi 875 876 # If invoked through the scripted interface, we likely have not yet 877 # detected the installed packages -- something we should do only once. 878 # 879 if [ ! "$PACKAGES_DETECTED" ]; then 880 f_package_detect_installed 881 export PACKAGES_DETECTED=1 # exported for awk(1) ENVIRON[] 882 fi 883 # Now we have: _mark_{varpkg}=X for all installed packages 884 885 # 886 # Since we're maintaining data structures for installed packages, 887 # short-circuit the package dependency checks if the package is already 888 # installed. This prevents wasted cycles, minor delays between package 889 # extractions, and worst-case an infinite loop with a certain faulty 890 # INDEX file. 891 # 892 local mark= 893 f_getvar _mark_$varpkg mark && [ "$mark" = "X" ] && return $SUCCESS 894 895 local dep vardep rundeps= 896 f_getvar _rundeps_$varpkg rundeps 897 for dep in $rundeps; do 898 f_str2varname "$dep" vardep 899 900 # Skip dependency if already installed 901 mark= 902 f_getvar _mark_$vardep mark && [ "$mark" = "X" ] && continue 903 904 # Just as-in the user-interface (opposed to scripted-use), only 905 # allow packages with at least one category to be recognized. 906 # 907 local depcat= 908 if ! f_getvar _categories_$vardep depcat || [ ! "$depcat" ] 909 then 910 $alert "$msg_required_package_not_found" "$dep" 911 [ "$no_confirm" ] && sleep 2 912 fi 913 914 f_package_add "$dep" 915 retval=$? 916 if [ $retval -ne $SUCCESS ]; then 917 status=$(( $status | $retval )) 918 919 # XXX package could be on a future disc volume 920 # XXX (not supporting multiple disc volumes yet) 921 922 $alert "$msg_loading_of_dependent_package_failed" \ 923 "$dep" 924 [ "$no_confirm" ] && sleep 2 925 fi 926 done 927 [ $status -eq $SUCCESS ] || return $status 928 929 # 930 # Done with the deps? Try to load the real m'coy. 931 # 932 933 f_package_extract media "$name" "$depended" 934 retval=$? 935 if [ $retval -ne $SUCCESS ]; then 936 status=$(( $status | $retval )) 937 else 938 setvar _mark_$varpkg X 939 fi 940 941 return $status 942} 943 944# f_package_extract $device $name [$depended] 945# 946# Extract a package based on a namespec and media device. If $depended is 947# present and non-NULL, the notification displayed while installing the package 948# has "as a dependency" appended. 949# 950f_package_extract() 951{ 952 local device="$1" name="$2" depended="$3" 953 954 # Check to make sure it's not already there 955 local varpkg mark= 956 f_str2varname "$name" varpkg 957 f_getvar _mark_$varpkg mark 958 [ "$mark" = "X" ] && return $SUCCESS 959 960 if ! f_device_init $device; then 961 f_show_msg \ 962 "$msg_unable_to_initialize_media_type_for_package_extract" 963 return $FAILURE 964 fi 965 966 # If necessary, initialize the ldconfig hints 967 [ -f "/var/run/ld-elf.so.hints" ] || 968 f_quietly ldconfig /usr/lib /usr/lib/compat /usr/local/lib 969 970 # Make a couple paranoid locations for temp 971 # files to live if user specified none 972 local tmpdir 973 f_getvar $VAR_PKG_TMPDIR:-/var/tmp tmpdir 974 f_quietly mkdir -p -m 1777 "$tmpdir" 975 976 local path 977 case "$name" in 978 */*) path="$name" ;; 979 *) 980 case "$name" in 981 *-*|*_*) path="packages/All/$name" ;; 982 *) path="packages/Latest/$name" 983 esac 984 esac 985 986 local fname=f_package_extract 987 988 # We have a path, call the device strategy routine to get the file 989 local pkg_ext probe_only=1 found= 990 for pkg_ext in "" $PACKAGE_EXTENSIONS; do 991 if f_device_get $device "$path$pkg_ext" $probe_only; then 992 path="$path$pkg_ext" 993 f_dprintf "%s: found path=[%s] dev=[%s]" \ 994 $fname "$path" "$device" 995 found=1 996 break 997 fi 998 done 999 1000 local alert=f_show_msg no_confirm= 1001 f_getvar $VAR_NO_CONFIRM no_confirm 1002 [ "$no_confirm" ] && alert=f_show_info 1003 1004 if [ ! "$found" ]; then 1005 f_dprintf "%s: No such %s file on %s device" \ 1006 $fname "$path" "$device" 1007 $alert "$msg_unable_to_fetch_package_from_selected_media" \ 1008 "$name" 1009 [ "$no_confirm" ] && sleep 2 1010 return $FAILURE 1011 fi 1012 1013 local devname= 1014 f_struct device_$device get name devname 1015 if [ "$depended" ]; then 1016 f_show_info "$msg_adding_package_as_a_dependency_from_media" \ 1017 "$name" "$devname" 1018 else 1019 f_show_info "$msg_adding_package_from_media" "$name" "$devname" 1020 fi 1021 1022 # Get package data and pipe into pkg_add(1) while providing feedback 1023 { 1024 if ! f_device_get $device "$path"; then 1025 $alert "$msg_io_error_while_reading_in_the_package" \ 1026 "$name" \ 1027 >&$DIALOG_TERMINAL_PASSTHRU_FD 2> /dev/null 1028 [ "$no_confirm" ] && sleep 2 1029 else 1030 f_show_info \ 1031 "$msg_package_read_successfully_waiting_for_pkg_add" \ 1032 "$name" >&$DIALOG_TERMINAL_PASSTHRU_FD 2> /dev/null 1033 fi 1034 } | { 1035 if f_debugging; then 1036 /usr/sbin/pkg_add -v - 1037 else 1038 f_quietly /usr/sbin/pkg_add - 1039 fi 1040 } 1041 if [ $? -ne $SUCCESS ]; then 1042 $alert "$msg_pkg_add_apparently_did_not_like_the_package" \ 1043 "$name" 1044 [ "$no_confirm" ] && sleep 2 1045 else 1046 f_show_info "$msg_package_was_added_successfully" "$name" 1047 sleep 1 1048 fi 1049 1050 return $SUCCESS 1051} 1052
|
815############################################################ MAIN 816 817f_dprintf "%s: Successfully loaded." packages/packages.subr 818 819fi # ! $_PACKAGES_PACKAGES_SUBR
| 1053############################################################ MAIN 1054 1055f_dprintf "%s: Successfully loaded." packages/packages.subr 1056 1057fi # ! $_PACKAGES_PACKAGES_SUBR
|