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 $
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
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
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
292 local prompt="$msg_please_select_a_category_to_display"
293 local hline=""
294
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{
368 local category="$1" page="${2:-1}" defaultitem="$3"
369 local varcat npkgs=0 npages menu_list
370
371 f_isinteger "$page" || return $FAILURE
372
373 f_str2varname "$category" varcat
374 f_package_index_get_page "$category" $page index_page
375
376 # Get number of packages for this category
377 case "$category" in
378 "$msg_all"|"") npkgs="${_npkgs:-0}";;
379 *) f_getvar _npkgs_$varcat npkgs
380 esac
381
382 # Calculate number of pages
383 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
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
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
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{
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="
516 'X $msg_installed' '$msg_installed_desc'
517 'R $msg_reinstall' '$msg_reinstall_desc'
518 'U $msg_uninstall' '$msg_uninstall_desc'
519 " # End-Quote
520
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{
554 local prompt package varpkg mark menu_list=
555 prompt=$( printf "$msg_reviewing_selected_packages" \
556 "$_All_nselected" )
557 local hline="$hline_alnum_arrows_punc_tab_enter"
558 f_dprintf "f_package_review: SELECTED_PACKAGES=[%s]" \
559 "$SELECTED_PACKAGES"
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 ---
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 $
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
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
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
292 local prompt="$msg_please_select_a_category_to_display"
293 local hline=""
294
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{
368 local category="$1" page="${2:-1}" defaultitem="$3"
369 local varcat npkgs=0 npages menu_list
370
371 f_isinteger "$page" || return $FAILURE
372
373 f_str2varname "$category" varcat
374 f_package_index_get_page "$category" $page index_page
375
376 # Get number of packages for this category
377 case "$category" in
378 "$msg_all"|"") npkgs="${_npkgs:-0}";;
379 *) f_getvar _npkgs_$varcat npkgs
380 esac
381
382 # Calculate number of pages
383 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
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
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
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{
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="
516 'X $msg_installed' '$msg_installed_desc'
517 'R $msg_reinstall' '$msg_reinstall_desc'
518 'U $msg_uninstall' '$msg_uninstall_desc'
519 " # End-Quote
520
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{
554 local prompt package varpkg mark menu_list=
555 prompt=$( printf "$msg_reviewing_selected_packages" \
556 "$_All_nselected" )
557 local hline="$hline_alnum_arrows_punc_tab_enter"
558 f_dprintf "f_package_review: SELECTED_PACKAGES=[%s]" \
559 "$SELECTED_PACKAGES"
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 ---