Deleted Added
full compact
packages.subr (251236) packages.subr (251264)
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:

--- 10 unchanged lines hidden (view full) ---

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:

--- 10 unchanged lines hidden (view full) ---

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 251236 2013-06-01 23:58:44Z dteske $
27# $FreeBSD: head/usr.sbin/bsdconfig/share/packages/packages.subr 251264 2013-06-02 20:02:50Z 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
35f_include $BSDCFG_SHARE/strings.subr

--- 236 unchanged lines hidden (view full) ---

272# Dislay the menu of package categories, complete with package counts for each
273# category, accents, and other miscellany. If $defaultitem is non-NULL and
274# matches one of the existing menu-items, it will be pre-highlighted in the
275# menu dialog (HINT: Use f_dialog_menutag_fetch() to populate a local variable
276# that is passed as $defaultitem to highlight the user's last selection).
277#
278f_package_menu_categories()
279{
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/strings.subr

--- 236 unchanged lines hidden (view full) ---

272# Dislay the menu of package categories, complete with package counts for each
273# category, accents, and other miscellany. If $defaultitem is non-NULL and
274# matches one of the existing menu-items, it will be pre-highlighted in the
275# menu dialog (HINT: Use f_dialog_menutag_fetch() to populate a local variable
276# that is passed as $defaultitem to highlight the user's last selection).
277#
278f_package_menu_categories()
279{
280 local var_to_get="$1" defaultitem="$2" category_list menu_list
280 local var_to_get="$1" defaultitem="$2"
281 local prompt="$msg_please_select_a_category_to_display"
282 local menu_list="
283 '> $msg_review' '$msg_review_desc' '$msg_review_help'
284 " # End-Quote
285 local hline=
281
282 f_package_calculate_rundeps
283 # updates package mark variables and SELECTED_PACKAGES
284 f_package_calculate_totals
285 # creates _{varcat}_ninstalled and _{varcat}_nselected
286
286
287 f_package_calculate_rundeps
288 # updates package mark variables and SELECTED_PACKAGES
289 f_package_calculate_totals
290 # creates _{varcat}_ninstalled and _{varcat}_nselected
291
292 local category_list
287 debug= f_getvar "$var_to_get" category_list || return $FAILURE
288
289 # Accent the category menu list with ninstalled/nselected
290 eval f_package_accent_category_menu category_list $category_list
291
293 debug= f_getvar "$var_to_get" category_list || return $FAILURE
294
295 # Accent the category menu list with ninstalled/nselected
296 eval f_package_accent_category_menu category_list $category_list
297
292 local prompt="$msg_please_select_a_category_to_display"
293 local hline=""
298 # Add list of categories to menu list
299 menu_list="$menu_list $category_list"
294
300
295 menu_list="
296 '> $msg_review' '$msg_review_desc' '$msg_review_help'
297 $category_list
298 " # End-Quote
299
300 local height width rows
301 eval f_dialog_menu_with_help_size height width rows \
302 \"\$DIALOG_TITLE\" \
303 \"\$DIALOG_BACKTITLE\" \
304 \"\$prompt\" \
305 \"\$hline\" \
306 $menu_list
307 local menu_choice

--- 52 unchanged lines hidden (view full) ---

360# maximum $PACKAGE_MENU_PAGESIZE).
361#
362# On success, if the user doesn't press ESC or choose Cancel, the environment
363# variable $DIALOG_MENUITEM_$$ will hold the item associated with the chosen
364# tag (accessible through f_dialog_menutag_fetch()).
365#
366f_package_menu_select()
367{
301 local height width rows
302 eval f_dialog_menu_with_help_size height width rows \
303 \"\$DIALOG_TITLE\" \
304 \"\$DIALOG_BACKTITLE\" \
305 \"\$prompt\" \
306 \"\$hline\" \
307 $menu_list
308 local menu_choice

--- 52 unchanged lines hidden (view full) ---

361# maximum $PACKAGE_MENU_PAGESIZE).
362#
363# On success, if the user doesn't press ESC or choose Cancel, the environment
364# variable $DIALOG_MENUITEM_$$ will hold the item associated with the chosen
365# tag (accessible through f_dialog_menutag_fetch()).
366#
367f_package_menu_select()
368{
368 local category="$1" page="${2:-1}" defaultitem="$3"
369 local varcat npkgs=0 npages menu_list
369 local category="$1" page="${2:-1}"
370 local prompt= # Calculated below
371 local menu_list # Calculated below
372 local defaultitem="$3"
373 local hline="$hline_arrows_tab_punc_enter"
370
371 f_isinteger "$page" || return $FAILURE
372
374
375 f_isinteger "$page" || return $FAILURE
376
377 local varcat
373 f_str2varname "$category" varcat
378 f_str2varname "$category" varcat
374 f_package_index_get_page "$category" $page index_page
375
376 # Get number of packages for this category
379
380 # Get number of packages for this category
381 local npkgs=0
377 case "$category" in
378 "$msg_all"|"") npkgs="${_npkgs:-0}";;
379 *) f_getvar _npkgs_$varcat npkgs
380 esac
381
382 # Calculate number of pages
382 case "$category" in
383 "$msg_all"|"") npkgs="${_npkgs:-0}";;
384 *) f_getvar _npkgs_$varcat npkgs
385 esac
386
387 # Calculate number of pages
383 npages=$(( ${npkgs:=0} / $PACKAGE_MENU_PAGESIZE ))
388 local npages=$(( ${npkgs:=0} / $PACKAGE_MENU_PAGESIZE ))
384
385 # Add a page to the pagecount if not evenly divisible
386 [ $(( $npages * $PACKAGE_MENU_PAGESIZE )) -lt $npkgs ] &&
387 npages=$(( $npages + 1 ))
388
389 # Print some debugging information
390 f_dprintf "f_package_menu_select: category=[%s] npkgs=%u npages=%u" \
391 "$category" "$npkgs" "$npages"

--- 10 unchanged lines hidden (view full) ---

402 if [ $page -lt $npages ]; then
403 add_next=1
404 # Accent the `Next Page' item with an asterisk
405 # if the page-after-next is loaded/cached
406 f_isset _index_page_${varcat}_$(( $page + 1 )) &&
407 next_page="$next_page*"
408 fi
409
389
390 # Add a page to the pagecount if not evenly divisible
391 [ $(( $npages * $PACKAGE_MENU_PAGESIZE )) -lt $npkgs ] &&
392 npages=$(( $npages + 1 ))
393
394 # Print some debugging information
395 f_dprintf "f_package_menu_select: category=[%s] npkgs=%u npages=%u" \
396 "$category" "$npkgs" "$npages"

--- 10 unchanged lines hidden (view full) ---

407 if [ $page -lt $npages ]; then
408 add_next=1
409 # Accent the `Next Page' item with an asterisk
410 # if the page-after-next is loaded/cached
411 f_isset _index_page_${varcat}_$(( $page + 1 )) &&
412 next_page="$next_page*"
413 fi
414
415 local index_page
416 f_package_index_get_page "$category" $page index_page
417
410 menu_list="
411 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}}
412 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}}
413 $(
414 export SHOW_DESC
415 export VALID_VARNAME_CHARS
416 echo "$index_page" | awk -F'|' -v view="port" '
417 BEGIN {

--- 23 unchanged lines hidden (view full) ---

441 }
442 printf "\n"
443 }'
444 )
445 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}}
446 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}}
447 " # End-Quote
448
418 menu_list="
419 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}}
420 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}}
421 $(
422 export SHOW_DESC
423 export VALID_VARNAME_CHARS
424 echo "$index_page" | awk -F'|' -v view="port" '
425 BEGIN {

--- 23 unchanged lines hidden (view full) ---

449 }
450 printf "\n"
451 }'
452 )
453 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}}
454 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}}
455 " # End-Quote
456
449 local prompt=""
450 # Accept/Translate i18n "All" but other category names must
451 # match tree definitions from INDEX, ports, FTP, etc.
452 case "$category" in
453 "$msg_all"|"") f_category_desc_get "All" prompt ;;
454 *) f_category_desc_get "$category" prompt ;;
455 esac
456 prompt="$prompt $( printf "$msg_page_of_npages" \
457 "$page" "$npages" )"
458
457 # Accept/Translate i18n "All" but other category names must
458 # match tree definitions from INDEX, ports, FTP, etc.
459 case "$category" in
460 "$msg_all"|"") f_category_desc_get "All" prompt ;;
461 *) f_category_desc_get "$category" prompt ;;
462 esac
463 prompt="$prompt $( printf "$msg_page_of_npages" \
464 "$page" "$npages" )"
465
459 local hline="$hline_arrows_tab_punc_enter"
460 local mheight mwidth mrows
461 f_dialog_menu${SHOW_DESC:+_with_help}_size mheight mwidth mrows \
462 \"\$DIALOG_TITLE\" \"\$DIALOG_BACKTITLE\" \
463 \"\$prompt\" \"\$hline\" $menu_list
464 local iheight iwidth
465 f_dialog_infobox_size iheight iwidth \
466 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" \
467 "$msg_processing_selection"

--- 36 unchanged lines hidden (view full) ---

504# Display a menu, asking the user what they would like to do with $package
505# with regard to "deselecting" an already installed package. Choices include
506# uninstall, re-install, or cancel (leave $package marked as installed).
507# Returns success if the user does not press ESC or choose Cnacel. Use the
508# f_dialog_menutag_fetch() function upon success to retrieve the user's choice.
509#
510f_package_menu_deselect()
511{
466 local mheight mwidth mrows
467 f_dialog_menu${SHOW_DESC:+_with_help}_size mheight mwidth mrows \
468 \"\$DIALOG_TITLE\" \"\$DIALOG_BACKTITLE\" \
469 \"\$prompt\" \"\$hline\" $menu_list
470 local iheight iwidth
471 f_dialog_infobox_size iheight iwidth \
472 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" \
473 "$msg_processing_selection"

--- 36 unchanged lines hidden (view full) ---

510# Display a menu, asking the user what they would like to do with $package
511# with regard to "deselecting" an already installed package. Choices include
512# uninstall, re-install, or cancel (leave $package marked as installed).
513# Returns success if the user does not press ESC or choose Cnacel. Use the
514# f_dialog_menutag_fetch() function upon success to retrieve the user's choice.
515#
516f_package_menu_deselect()
517{
512 local package="$1" prompt menu_list
513 prompt=$( printf "$msg_what_would_you_like_to_do_with" "$package" )
514 local hline="$hline_alnum_arrows_punc_tab_enter"
515 menu_list="
518 local package="$1"
519 local prompt # Calculated below
520 local menu_list="
516 'X $msg_installed' '$msg_installed_desc'
517 'R $msg_reinstall' '$msg_reinstall_desc'
518 'U $msg_uninstall' '$msg_uninstall_desc'
519 " # End-Quote
521 'X $msg_installed' '$msg_installed_desc'
522 'R $msg_reinstall' '$msg_reinstall_desc'
523 'U $msg_uninstall' '$msg_uninstall_desc'
524 " # End-Quote
525 local hline="$hline_alnum_arrows_punc_tab_enter"
520
526
527 prompt=$( printf "$msg_what_would_you_like_to_do_with" "$package" )
528
521 local height width rows
522 eval f_dialog_menu_size height width rows \
523 \"\$DIALOG_TITLE\" \
524 \"\$DIALOG_BACKTITLE\" \
525 \"\$prompt\" \
526 \"\$hline\" \
527 $menu_list
528 local menu_choice

--- 17 unchanged lines hidden (view full) ---

546#
547# Display a review screen, showing selected packages and what they are marked
548# for, before proceeding (if the user does not press ESC or choose Cancel) to
549# operate on each selection. Returns error if no packages have been selected,
550# or the user has pressed ESC, or if they have chosen Cancel.
551#
552f_package_review()
553{
529 local height width rows
530 eval f_dialog_menu_size height width rows \
531 \"\$DIALOG_TITLE\" \
532 \"\$DIALOG_BACKTITLE\" \
533 \"\$prompt\" \
534 \"\$hline\" \
535 $menu_list
536 local menu_choice

--- 17 unchanged lines hidden (view full) ---

554#
555# Display a review screen, showing selected packages and what they are marked
556# for, before proceeding (if the user does not press ESC or choose Cancel) to
557# operate on each selection. Returns error if no packages have been selected,
558# or the user has pressed ESC, or if they have chosen Cancel.
559#
560f_package_review()
561{
554 local prompt package varpkg mark menu_list=
555 prompt=$( printf "$msg_reviewing_selected_packages" \
556 "$_All_nselected" )
562 local prompt # Calculated below
563 local menu_list # Calculated below
557 local hline="$hline_alnum_arrows_punc_tab_enter"
564 local hline="$hline_alnum_arrows_punc_tab_enter"
565
558 f_dprintf "f_package_review: SELECTED_PACKAGES=[%s]" \
559 "$SELECTED_PACKAGES"
566 f_dprintf "f_package_review: SELECTED_PACKAGES=[%s]" \
567 "$SELECTED_PACKAGES"
568
569 prompt=$( printf "$msg_reviewing_selected_packages" "$_All_nselected" )
570
571 local package varpkg mark
560 for package in $SELECTED_PACKAGES; do
561 mark=
562 f_str2varname "$package" varpkg
563 f_getvar _mark_$varpkg mark
564 [ "$mark" -a ! "${mark#[IRUD]}" ] || continue
565 menu_list="$menu_list
566 '$mark' '$package'
567 " # End-Quote

--- 204 unchanged lines hidden ---
572 for package in $SELECTED_PACKAGES; do
573 mark=
574 f_str2varname "$package" varpkg
575 f_getvar _mark_$varpkg mark
576 [ "$mark" -a ! "${mark#[IRUD]}" ] || continue
577 menu_list="$menu_list
578 '$mark' '$package'
579 " # End-Quote

--- 204 unchanged lines hidden ---