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 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{
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=
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
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
298 # Add list of categories to menu list
299 menu_list="$menu_list $category_list"
300
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{
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"
374
375 f_isinteger "$page" || return $FAILURE
376
377 local varcat
378 f_str2varname "$category" varcat
379
380 # Get number of packages for this category
381 local npkgs=0
382 case "$category" in
383 "$msg_all"|"") npkgs="${_npkgs:-0}";;
384 *) f_getvar _npkgs_$varcat npkgs
385 esac
386
387 # Calculate number of pages
388 local npages=$(( ${npkgs:=0} / $PACKAGE_MENU_PAGESIZE ))
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
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
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
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{
518 local package="$1"
519 local prompt # Calculated below
520 local menu_list="
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"
526
527 prompt=$( printf "$msg_what_would_you_like_to_do_with" "$package" )
528
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{
562 local prompt # Calculated below
563 local menu_list # Calculated below
564 local hline="$hline_alnum_arrows_punc_tab_enter"
565
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
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 ---
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 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{
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=
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
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
298 # Add list of categories to menu list
299 menu_list="$menu_list $category_list"
300
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{
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"
374
375 f_isinteger "$page" || return $FAILURE
376
377 local varcat
378 f_str2varname "$category" varcat
379
380 # Get number of packages for this category
381 local npkgs=0
382 case "$category" in
383 "$msg_all"|"") npkgs="${_npkgs:-0}";;
384 *) f_getvar _npkgs_$varcat npkgs
385 esac
386
387 # Calculate number of pages
388 local npages=$(( ${npkgs:=0} / $PACKAGE_MENU_PAGESIZE ))
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
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
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
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{
518 local package="$1"
519 local prompt # Calculated below
520 local menu_list="
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"
526
527 prompt=$( printf "$msg_what_would_you_like_to_do_with" "$package" )
528
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{
562 local prompt # Calculated below
563 local menu_list # Calculated below
564 local hline="$hline_alnum_arrows_punc_tab_enter"
565
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
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 ---