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 250538 2013-05-12 00:46:18Z dteske $
| 27# $FreeBSD: head/usr.sbin/bsdconfig/share/packages/packages.subr 251232 2013-06-01 21:29:53Z 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 36f_include $BSDCFG_SHARE/packages/categories.subr 37f_include $BSDCFG_SHARE/packages/index.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 51PACKAGE_CATEGORIES= 52SELECTED_PACKAGES= 53 54# 55# Options 56# 57[ "${SHOW_DESC+set}" ] || SHOW_DESC=1 58 59############################################################ FUNCTIONS 60 61# eval f_package_accent_category_menu $var_to_set $CATEGORY_MENU_LIST 62# 63# Accent the CATEGORY_MENU_LIST produced by f_index_read() (see 64# packages/index.subr). Accented information includes adding an asterisk to the 65# category name if its index has been cached, adding the number of installed 66# packages for each category, and adding the number _selected_ packages for 67# each category. 68# 69# NOTE: The reason `eval' is recommended/shown for the syntax above is because 70# the $CATEGORY_MENU_LIST generated by f_index_read() is meant to be expanded 71# prior to execution (it contains a series of pre-quoted strings which act as 72# the interpolated command arguments). 73# 74f_package_accent_category_menu() 75{ 76 local var_to_set="$1" cat desc help varcat menu_buf n 77 shift 1 # var_to_set 78 while [ $# -gt 0 ]; do 79 cat="${1%\*}" desc="${2%%; *}" help="$3" 80 shift 3 # cat/desc/help 81 82 cat="${cat# }" # Trim leading space inserted by sort-method 83 f_str2varname "$cat" varcat 84 85 # Add number of installed packages for this category (if any) 86 n=0 87 case "$cat" in 88 "$msg_all") debug= f_getvar "_All_ninstalled" n ;; 89 *) debug= f_getvar "_${varcat}_ninstalled" n ;; 90 esac && 91 [ $n -ge 1 ] && desc="$desc; $n $msg_installed_lc" 92 93 # Add number of selected packages for this category (if any) 94 n=0 95 case "$cat" in 96 "$msg_all") debug= f_getvar "_All_nselected" n ;; 97 *) debug= f_getvar "_${varcat}_nselected" n ;; 98 esac && 99 [ $n -ge 1 ] && desc="$desc; $n $msg_selected" 100 101 # Add an asterisk to the category if its index has been cached 102 f_isset _index_page_${varcat}_1 && cat="$cat*" 103 104 # Update buffer with modified elements 105 menu_buf="$menu_buf 106 '$cat' '$desc' '$help'" # End-Quote 107 done 108 setvar "$var_to_set" "$menu_buf" # return our buffer 109} 110 111# f_package_select $package ... 112# 113# Add $package to the list of tracked/selected packages. If $package is already 114# being tracked (already apears in $SELECTED_PACKAGES), this function amounts 115# to having no effect. 116# 117f_package_select() 118{ 119 local package pkgsel 120 while [ $# -gt 0 ]; do 121 package="$1" 122 shift 1 # package 123 for pkgsel in $SELECTED_PACKAGES; do 124 [ "$package" = "$pkgsel" ] && return 125 done 126 SELECTED_PACKAGES="$SELECTED_PACKAGES $package" 127 done 128 SELECTED_PACKAGES="${SELECTED_PACKAGES# }" # Trim leading space 129} 130 131# f_package_deselect $package ... 132# 133# Remove $package from teh list of tracked/selected packages. If $package is 134# not being tracked (doesn't appear in $SELECTED_PACKAGES), this function 135# amounts to having no effet. 136# 137f_package_deselect() 138{ 139 local package pkgsel 140 while [ $# -gt 1 ]; do 141 local new_list="" 142 package="$1" 143 shift 1 # package 144 for pkgsel in $SELECTED_PACKAGES; do 145 [ "$pkgsel" = "$package" ] && continue 146 new_list="$new_list${new_list:+ }$pkgsel" 147 done 148 SELECTED_PACKAGES="$new_list" 149 done 150} 151 152# f_package_detect_installed 153# 154# Detect installed packages. Currently this searches /var/db/pkg for directory 155# entries and marks each entry as an installed/selected package. 156# 157f_package_detect_installed() 158{ 159 local installed package varpkg 160 installed=$( find -s /var/db/pkg -mindepth 1 -maxdepth 1 -type d | 161 sed -e 's:/var/db/pkg/::' ) 162 for package in $installed; do 163 f_str2varname $package varpkg 164 export _mark_$varpkg=X # exported for awk(1) ENVIRON[] 165 f_package_select $package 166 done 167} 168 169# f_package_calculate_totals 170# 171# Calculate number of installed/selected packages for each category listed in 172# $PACKAGE_CATEGORIES (the number of installed packages for $category is stored 173# as $_${varcat}_ninstalled -- where $varcat is the product of `f_str2varname 174# $category varcat' -- and number selected packages as $_${varcat}_nselected). 175# Also calculates the total number of installed/selected packages stored as 176# $_All_ninstalled and $_All_nselected. 177# 178# Calculations are peformed by checking "marks". A "mark" is stored as 179# $_mark_$varpkg -- where $varpkg is the product of `f_str2varname $package 180# varpkg'. A mark can be "X" for an installed package, `I' for a package that 181# is marked for installation, "R" for a package that is marked for re-install, 182# and "U" for a package that is marked for uninstallation. If a package mark is 183# NULL or a single space (e.g., " "), the package is considered to be NOT 184# selected (and therefore does not increment the counts calculated herein). 185# 186f_package_calculate_totals() 187{ 188 local pkg varpkg mark cat varcat pkgcat n tselected=0 tinstalled=0 189 for cat in $PACKAGE_CATEGORIES; do 190 f_str2varname $cat varcat 191 setvar _${varcat}_ninstalled=0 192 setvar _${varcat}_nselected=0 193 done 194 for pkg in $SELECTED_PACKAGES; do 195 f_str2varname $pkg varpkg 196 mark= 197 f_getvar _mark_$varpkg mark 198 case "$mark" in 199 ""|" ") : ;; 200 X) tinstalled=$(( $tinstalled + 1 ));; 201 *) tselected=$(( $tselected + 1 )) 202 esac 203 f_getvar _categories_$varpkg pkgcat 204 for cat in $pkgcat; do 205 f_str2varname $cat varcat 206 case "$mark" in 207 ""|" ") : ;; 208 X) debug= f_getvar _${varcat}_ninstalled n 209 setvar _${varcat}_ninstalled $(( $n + 1 ));; 210 *) debug= f_getvar _${varcat}_nselected n 211 setvar _${varcat}_nselected $(( $n + 1 )) 212 esac 213 done 214 done 215 _All_nselected=$tselected 216 _All_ninstalled=$tinstalled 217} 218 219# f_package_calculate_rundeps 220# 221# Update package dependencies by first unmarking all dependencies and then 222# re-marking all dependencies of packages marked for either install ("I") or 223# re-install ("R"). 224# 225f_package_calculate_rundeps() 226{ 227 local pkg varpkg mark rundeps dep vardep 228 229 # 230 # First unmark all the existing run-dependencies 231 # 232 f_dprintf "Unselecting package run-dependencies..." 233 for pkg in $SELECTED_PACKAGES; do 234 f_str2varname $pkg varpkg 235 mark= 236 debug= f_getvar _mark_$varpkg mark 237 # Only unmark if it's marked as a Dependency 238 if [ "$mark" = "D" ]; then 239 f_dprintf "%s unselected" $pkg 240 unset _mark_$varpkg 241 f_package_deselect $pkg 242 fi 243 done 244 245 # 246 # Processes selected packages, adding dependencies 247 # 248 f_dprintf "Re-selecting package run-dependencies..." 249 for pkg in $SELECTED_PACKAGES; do 250 f_str2varname $pkg varpkg 251 mark= 252 debug= f_getvar _mark_$varpkg mark 253 # Skip pkg unless marked for [Re-]Install 254 [ "$mark" = "I" -o "$mark" = "R" ] || continue 255 f_getvar _rundeps_$varpkg rundeps 256 for dep in $rundeps; do 257 f_str2varname $dep vardep 258 mark= 259 debug= f_getvar _mark_$vardep mark 260 # Skip dep if already marked 261 [ "${mark:- }" = " " ] || continue 262 export _mark_$vardep="D" 263 f_package_select $dep 264 done 265 done 266 267 f_dprintf "Finished recalculating dependencies." 268} 269 270# f_package_menu_categories $var_to_set $defaultitem 271# 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() to populate a local variable that 276# is passed as $defaultitem to highlight the user's last selection by default). 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
| 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 36f_include $BSDCFG_SHARE/packages/categories.subr 37f_include $BSDCFG_SHARE/packages/index.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 51PACKAGE_CATEGORIES= 52SELECTED_PACKAGES= 53 54# 55# Options 56# 57[ "${SHOW_DESC+set}" ] || SHOW_DESC=1 58 59############################################################ FUNCTIONS 60 61# eval f_package_accent_category_menu $var_to_set $CATEGORY_MENU_LIST 62# 63# Accent the CATEGORY_MENU_LIST produced by f_index_read() (see 64# packages/index.subr). Accented information includes adding an asterisk to the 65# category name if its index has been cached, adding the number of installed 66# packages for each category, and adding the number _selected_ packages for 67# each category. 68# 69# NOTE: The reason `eval' is recommended/shown for the syntax above is because 70# the $CATEGORY_MENU_LIST generated by f_index_read() is meant to be expanded 71# prior to execution (it contains a series of pre-quoted strings which act as 72# the interpolated command arguments). 73# 74f_package_accent_category_menu() 75{ 76 local var_to_set="$1" cat desc help varcat menu_buf n 77 shift 1 # var_to_set 78 while [ $# -gt 0 ]; do 79 cat="${1%\*}" desc="${2%%; *}" help="$3" 80 shift 3 # cat/desc/help 81 82 cat="${cat# }" # Trim leading space inserted by sort-method 83 f_str2varname "$cat" varcat 84 85 # Add number of installed packages for this category (if any) 86 n=0 87 case "$cat" in 88 "$msg_all") debug= f_getvar "_All_ninstalled" n ;; 89 *) debug= f_getvar "_${varcat}_ninstalled" n ;; 90 esac && 91 [ $n -ge 1 ] && desc="$desc; $n $msg_installed_lc" 92 93 # Add number of selected packages for this category (if any) 94 n=0 95 case "$cat" in 96 "$msg_all") debug= f_getvar "_All_nselected" n ;; 97 *) debug= f_getvar "_${varcat}_nselected" n ;; 98 esac && 99 [ $n -ge 1 ] && desc="$desc; $n $msg_selected" 100 101 # Add an asterisk to the category if its index has been cached 102 f_isset _index_page_${varcat}_1 && cat="$cat*" 103 104 # Update buffer with modified elements 105 menu_buf="$menu_buf 106 '$cat' '$desc' '$help'" # End-Quote 107 done 108 setvar "$var_to_set" "$menu_buf" # return our buffer 109} 110 111# f_package_select $package ... 112# 113# Add $package to the list of tracked/selected packages. If $package is already 114# being tracked (already apears in $SELECTED_PACKAGES), this function amounts 115# to having no effect. 116# 117f_package_select() 118{ 119 local package pkgsel 120 while [ $# -gt 0 ]; do 121 package="$1" 122 shift 1 # package 123 for pkgsel in $SELECTED_PACKAGES; do 124 [ "$package" = "$pkgsel" ] && return 125 done 126 SELECTED_PACKAGES="$SELECTED_PACKAGES $package" 127 done 128 SELECTED_PACKAGES="${SELECTED_PACKAGES# }" # Trim leading space 129} 130 131# f_package_deselect $package ... 132# 133# Remove $package from teh list of tracked/selected packages. If $package is 134# not being tracked (doesn't appear in $SELECTED_PACKAGES), this function 135# amounts to having no effet. 136# 137f_package_deselect() 138{ 139 local package pkgsel 140 while [ $# -gt 1 ]; do 141 local new_list="" 142 package="$1" 143 shift 1 # package 144 for pkgsel in $SELECTED_PACKAGES; do 145 [ "$pkgsel" = "$package" ] && continue 146 new_list="$new_list${new_list:+ }$pkgsel" 147 done 148 SELECTED_PACKAGES="$new_list" 149 done 150} 151 152# f_package_detect_installed 153# 154# Detect installed packages. Currently this searches /var/db/pkg for directory 155# entries and marks each entry as an installed/selected package. 156# 157f_package_detect_installed() 158{ 159 local installed package varpkg 160 installed=$( find -s /var/db/pkg -mindepth 1 -maxdepth 1 -type d | 161 sed -e 's:/var/db/pkg/::' ) 162 for package in $installed; do 163 f_str2varname $package varpkg 164 export _mark_$varpkg=X # exported for awk(1) ENVIRON[] 165 f_package_select $package 166 done 167} 168 169# f_package_calculate_totals 170# 171# Calculate number of installed/selected packages for each category listed in 172# $PACKAGE_CATEGORIES (the number of installed packages for $category is stored 173# as $_${varcat}_ninstalled -- where $varcat is the product of `f_str2varname 174# $category varcat' -- and number selected packages as $_${varcat}_nselected). 175# Also calculates the total number of installed/selected packages stored as 176# $_All_ninstalled and $_All_nselected. 177# 178# Calculations are peformed by checking "marks". A "mark" is stored as 179# $_mark_$varpkg -- where $varpkg is the product of `f_str2varname $package 180# varpkg'. A mark can be "X" for an installed package, `I' for a package that 181# is marked for installation, "R" for a package that is marked for re-install, 182# and "U" for a package that is marked for uninstallation. If a package mark is 183# NULL or a single space (e.g., " "), the package is considered to be NOT 184# selected (and therefore does not increment the counts calculated herein). 185# 186f_package_calculate_totals() 187{ 188 local pkg varpkg mark cat varcat pkgcat n tselected=0 tinstalled=0 189 for cat in $PACKAGE_CATEGORIES; do 190 f_str2varname $cat varcat 191 setvar _${varcat}_ninstalled=0 192 setvar _${varcat}_nselected=0 193 done 194 for pkg in $SELECTED_PACKAGES; do 195 f_str2varname $pkg varpkg 196 mark= 197 f_getvar _mark_$varpkg mark 198 case "$mark" in 199 ""|" ") : ;; 200 X) tinstalled=$(( $tinstalled + 1 ));; 201 *) tselected=$(( $tselected + 1 )) 202 esac 203 f_getvar _categories_$varpkg pkgcat 204 for cat in $pkgcat; do 205 f_str2varname $cat varcat 206 case "$mark" in 207 ""|" ") : ;; 208 X) debug= f_getvar _${varcat}_ninstalled n 209 setvar _${varcat}_ninstalled $(( $n + 1 ));; 210 *) debug= f_getvar _${varcat}_nselected n 211 setvar _${varcat}_nselected $(( $n + 1 )) 212 esac 213 done 214 done 215 _All_nselected=$tselected 216 _All_ninstalled=$tinstalled 217} 218 219# f_package_calculate_rundeps 220# 221# Update package dependencies by first unmarking all dependencies and then 222# re-marking all dependencies of packages marked for either install ("I") or 223# re-install ("R"). 224# 225f_package_calculate_rundeps() 226{ 227 local pkg varpkg mark rundeps dep vardep 228 229 # 230 # First unmark all the existing run-dependencies 231 # 232 f_dprintf "Unselecting package run-dependencies..." 233 for pkg in $SELECTED_PACKAGES; do 234 f_str2varname $pkg varpkg 235 mark= 236 debug= f_getvar _mark_$varpkg mark 237 # Only unmark if it's marked as a Dependency 238 if [ "$mark" = "D" ]; then 239 f_dprintf "%s unselected" $pkg 240 unset _mark_$varpkg 241 f_package_deselect $pkg 242 fi 243 done 244 245 # 246 # Processes selected packages, adding dependencies 247 # 248 f_dprintf "Re-selecting package run-dependencies..." 249 for pkg in $SELECTED_PACKAGES; do 250 f_str2varname $pkg varpkg 251 mark= 252 debug= f_getvar _mark_$varpkg mark 253 # Skip pkg unless marked for [Re-]Install 254 [ "$mark" = "I" -o "$mark" = "R" ] || continue 255 f_getvar _rundeps_$varpkg rundeps 256 for dep in $rundeps; do 257 f_str2varname $dep vardep 258 mark= 259 debug= f_getvar _mark_$vardep mark 260 # Skip dep if already marked 261 [ "${mark:- }" = " " ] || continue 262 export _mark_$vardep="D" 263 f_package_select $dep 264 done 265 done 266 267 f_dprintf "Finished recalculating dependencies." 268} 269 270# f_package_menu_categories $var_to_set $defaultitem 271# 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() to populate a local variable that 276# is passed as $defaultitem to highlight the user's last selection by default). 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 size dialog_menu 301 size=$( eval f_dialog_menu_with_help_size \ 302 \"\$DIALOG_TITLE\" \ 303 \"\$DIALOG_BACKTITLE\" \ 304 \"\$prompt\" \ 305 \"\$hline\" \ 306 $menu_list )
| 300 local height width rows dialog_menu 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 dialog_menu=$( eval $DIALOG \ 308 --title \"\$DIALOG_TITLE\" \ 309 --backtitle \"\$DIALOG_BACKTITLE\" \ 310 --hline \"\$hline\" \ 311 --item-help \ 312 --default-item \"\$defaultitem\" \ 313 --ok-label \"$msg_select\" \ 314 --cancel-label \"$msg_cancel\" \
| 307 dialog_menu=$( eval $DIALOG \ 308 --title \"\$DIALOG_TITLE\" \ 309 --backtitle \"\$DIALOG_BACKTITLE\" \ 310 --hline \"\$hline\" \ 311 --item-help \ 312 --default-item \"\$defaultitem\" \ 313 --ok-label \"$msg_select\" \ 314 --cancel-label \"$msg_cancel\" \
|
315 --menu \"\$prompt\" $size \
| 315 --menu \"\$prompt\" \ 316 $height $width $rows \
|
316 $menu_list \ 317 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 318 ) 319 local retval=$? 320 setvar DIALOG_MENU_$$ "$dialog_menu" 321 return $retval 322} 323 324# f_package_index_get_page $category $page [$var_to_set [$var_to_get]] 325# 326# Obtain a [potentially cached] page of the INDEX file for a given $category. 327# If $page is 1 and the cache has not yet been generated, the cache-generating 328# function f_index_extract_pages() (above) is called to generate all pages 329# (not just the requested page) in cache before returning the requested page. 330# If $page is not 1 and there is no cached page, failure status is returned. 331# 332f_package_index_get_page() 333{ 334 local category="$1" page="$2" var_to_set="$3" var_to_get="$4" varcat 335 f_str2varname "$category" varcat 336 if ! debug= f_getvar "_index_page_${varcat}_$page" $var_to_set && 337 [ "$page" = "1" ] 338 then 339 f_show_info "$msg_building_package_menus" 340 local pagesize="$PACKAGE_MENU_PAGESIZE" 341 f_index_extract_pages "${var_to_get:-PACKAGE_INDEX}" \ 342 _index_page_${varcat} "$pagesize" "$category" 343 debug= f_getvar _index_page_${varcat}_$page $var_to_set 344 345 # Update category default-item because now we're cached 346 [ $page -eq 1 ] && 347 category_defaultitem="${category_defaultitem%\*}*" 348 else 349 return $FAILURE 350 fi 351} 352 353# f_package_menu_select $category [ $page [ $defaultitem ] ] 354# 355# Display list of packages for $category, optionally $page N and with a default 356# item selected. If $page is omitted, the first page is displayed (but this 357# only matters if there are multiple pages; which is determined by the global 358# maximum $PACKAGE_MENU_PAGESIZE). 359# 360# On success, if the user doesn't press ESC or choose Cancel, the environment 361# variable $DIALOG_MENUITEM_$$ will hold the item associated with the chosen 362# tag (accessible through f_dialog_menutag()). 363# 364f_package_menu_select() 365{ 366 local category="$1" page="${2:-1}" defaultitem="$3" 367 local varcat npkgs=0 npages menu_list 368 369 f_isinteger "$page" || return $FAILURE 370 371 f_str2varname "$category" varcat 372 f_package_index_get_page "$category" $page index_page 373 374 # Get number of packages for this category 375 case "$category" in 376 "$msg_all"|"") npkgs="${_npkgs:-0}";; 377 *) f_getvar _npkgs_$varcat npkgs 378 esac 379 380 # Calculate number of pages 381 npages=$(( ${npkgs:=0} / $PACKAGE_MENU_PAGESIZE )) 382 383 # Add a page to the pagecount if not evenly divisible 384 [ $(( $npages * $PACKAGE_MENU_PAGESIZE )) -lt $npkgs ] && 385 npages=$(( $npages + 1 )) 386 387 # Print some debugging information 388 f_dprintf "f_package_menu_select: category=[%s] npkgs=%u npages=%u" \ 389 "$category" "$npkgs" "$npages" 390 391 local add_prev="" add_next="" 392 local previous_page="$msg_previous_page" next_page="$msg_next_page" 393 if [ $page -gt 1 ]; then 394 add_prev=1 395 # Accent the `Previous Page' item with an asterisk 396 # if the page-before-previous is loaded/cached 397 f_isset _index_page_${varcat}_$(( $page - 1 )) && 398 previous_page="$previous_page*" 399 fi 400 if [ $page -lt $npages ]; then 401 add_next=1 402 # Accent the `Next Page' item with an asterisk 403 # if the page-after-next is loaded/cached 404 f_isset _index_page_${varcat}_$(( $page + 1 )) && 405 next_page="$next_page*" 406 fi 407 408 menu_list=" 409 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}} 410 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}} 411 $( 412 export SHOW_DESC 413 export VALID_VARNAME_CHARS 414 echo "$index_page" | awk -F'|' -v view="port" ' 415 BEGIN { 416 valid_chars = ENVIRON["VALID_VARNAME_CHARS"] 417 prefix = "" 418 } 419 { 420 cur_prefix = tolower(substr($1, 1, 1)) 421 printf "'\''" 422 if ( prefix != cur_prefix ) 423 prefix = cur_prefix 424 else 425 printf " " 426 package = $1 427 if ( view == "port" ) 428 desc = $2 429 varpkg = package 430 gsub("[^" valid_chars "]", "_", varpkg) 431 mark = ENVIRON["_mark_" varpkg] 432 if ( ! mark ) mark = " " 433 printf "%s'\'' '\''[%c] %s'\''", 434 package, mark, desc 435 if ( ENVIRON["SHOW_DESC"] ) { 436 help = $4 437 gsub(/'\''/, "'\''\\'\'\''", help) 438 printf " '\''%s'\''", help 439 } 440 printf "\n" 441 }' 442 ) 443 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}} 444 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}} 445 " # End-Quote 446 447 local prompt="" 448 # Accept/Translate i18n "All" but other category names must 449 # match tree definitions from INDEX, ports, FTP, etc. 450 case "$category" in 451 "$msg_all"|"") f_category_desc_get "All" prompt ;; 452 *) f_category_desc_get "$category" prompt ;; 453 esac 454 prompt="$prompt $( printf "$msg_page_of_npages" \ 455 "$page" "$npages" )" 456 457 local hline="$hline_arrows_tab_punc_enter"
| 317 $menu_list \ 318 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 319 ) 320 local retval=$? 321 setvar DIALOG_MENU_$$ "$dialog_menu" 322 return $retval 323} 324 325# f_package_index_get_page $category $page [$var_to_set [$var_to_get]] 326# 327# Obtain a [potentially cached] page of the INDEX file for a given $category. 328# If $page is 1 and the cache has not yet been generated, the cache-generating 329# function f_index_extract_pages() (above) is called to generate all pages 330# (not just the requested page) in cache before returning the requested page. 331# If $page is not 1 and there is no cached page, failure status is returned. 332# 333f_package_index_get_page() 334{ 335 local category="$1" page="$2" var_to_set="$3" var_to_get="$4" varcat 336 f_str2varname "$category" varcat 337 if ! debug= f_getvar "_index_page_${varcat}_$page" $var_to_set && 338 [ "$page" = "1" ] 339 then 340 f_show_info "$msg_building_package_menus" 341 local pagesize="$PACKAGE_MENU_PAGESIZE" 342 f_index_extract_pages "${var_to_get:-PACKAGE_INDEX}" \ 343 _index_page_${varcat} "$pagesize" "$category" 344 debug= f_getvar _index_page_${varcat}_$page $var_to_set 345 346 # Update category default-item because now we're cached 347 [ $page -eq 1 ] && 348 category_defaultitem="${category_defaultitem%\*}*" 349 else 350 return $FAILURE 351 fi 352} 353 354# f_package_menu_select $category [ $page [ $defaultitem ] ] 355# 356# Display list of packages for $category, optionally $page N and with a default 357# item selected. If $page is omitted, the first page is displayed (but this 358# only matters if there are multiple pages; which is determined by the global 359# maximum $PACKAGE_MENU_PAGESIZE). 360# 361# On success, if the user doesn't press ESC or choose Cancel, the environment 362# variable $DIALOG_MENUITEM_$$ will hold the item associated with the chosen 363# tag (accessible through f_dialog_menutag()). 364# 365f_package_menu_select() 366{ 367 local category="$1" page="${2:-1}" defaultitem="$3" 368 local varcat npkgs=0 npages menu_list 369 370 f_isinteger "$page" || return $FAILURE 371 372 f_str2varname "$category" varcat 373 f_package_index_get_page "$category" $page index_page 374 375 # Get number of packages for this category 376 case "$category" in 377 "$msg_all"|"") npkgs="${_npkgs:-0}";; 378 *) f_getvar _npkgs_$varcat npkgs 379 esac 380 381 # Calculate number of pages 382 npages=$(( ${npkgs:=0} / $PACKAGE_MENU_PAGESIZE )) 383 384 # Add a page to the pagecount if not evenly divisible 385 [ $(( $npages * $PACKAGE_MENU_PAGESIZE )) -lt $npkgs ] && 386 npages=$(( $npages + 1 )) 387 388 # Print some debugging information 389 f_dprintf "f_package_menu_select: category=[%s] npkgs=%u npages=%u" \ 390 "$category" "$npkgs" "$npages" 391 392 local add_prev="" add_next="" 393 local previous_page="$msg_previous_page" next_page="$msg_next_page" 394 if [ $page -gt 1 ]; then 395 add_prev=1 396 # Accent the `Previous Page' item with an asterisk 397 # if the page-before-previous is loaded/cached 398 f_isset _index_page_${varcat}_$(( $page - 1 )) && 399 previous_page="$previous_page*" 400 fi 401 if [ $page -lt $npages ]; then 402 add_next=1 403 # Accent the `Next Page' item with an asterisk 404 # if the page-after-next is loaded/cached 405 f_isset _index_page_${varcat}_$(( $page + 1 )) && 406 next_page="$next_page*" 407 fi 408 409 menu_list=" 410 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}} 411 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}} 412 $( 413 export SHOW_DESC 414 export VALID_VARNAME_CHARS 415 echo "$index_page" | awk -F'|' -v view="port" ' 416 BEGIN { 417 valid_chars = ENVIRON["VALID_VARNAME_CHARS"] 418 prefix = "" 419 } 420 { 421 cur_prefix = tolower(substr($1, 1, 1)) 422 printf "'\''" 423 if ( prefix != cur_prefix ) 424 prefix = cur_prefix 425 else 426 printf " " 427 package = $1 428 if ( view == "port" ) 429 desc = $2 430 varpkg = package 431 gsub("[^" valid_chars "]", "_", varpkg) 432 mark = ENVIRON["_mark_" varpkg] 433 if ( ! mark ) mark = " " 434 printf "%s'\'' '\''[%c] %s'\''", 435 package, mark, desc 436 if ( ENVIRON["SHOW_DESC"] ) { 437 help = $4 438 gsub(/'\''/, "'\''\\'\'\''", help) 439 printf " '\''%s'\''", help 440 } 441 printf "\n" 442 }' 443 ) 444 ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}} 445 ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}} 446 " # End-Quote 447 448 local prompt="" 449 # Accept/Translate i18n "All" but other category names must 450 # match tree definitions from INDEX, ports, FTP, etc. 451 case "$category" in 452 "$msg_all"|"") f_category_desc_get "All" prompt ;; 453 *) f_category_desc_get "$category" prompt ;; 454 esac 455 prompt="$prompt $( printf "$msg_page_of_npages" \ 456 "$page" "$npages" )" 457 458 local hline="$hline_arrows_tab_punc_enter"
|
458 local size isize dialog_menu item 459 size=$( eval f_dialog_menu${SHOW_DESC:+_with_help}_size \ 460 \"\$DIALOG_TITLE\" \ 461 \"\$DIALOG_BACKTITLE\" \ 462 \"\$prompt\" \ 463 \"\$hline\" \ 464 $menu_list ) 465 isize=$( f_dialog_infobox_size \ 466 "$DIALOG_TITLE" \ 467 "$DIALOG_BACKTITLE" \ 468 "$msg_processing_selection" )
| 459 local mheight mwidth mrows 460 f_dialog_menu${SHOW_DESC:+_with_help}_size mheight mwidth mrows \ 461 \"\$DIALOG_TITLE\" \"\$DIALOG_BACKTITLE\" \ 462 \"\$prompt\" \"\$hline\" $menu_list 463 local iheight iwidth 464 f_dialog_infobox_size iheight iwidth \ 465 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" \ 466 "$msg_processing_selection" 467 local dialog_menu item
|
469 dialog_menu=$( eval $DIALOG \ 470 --title \"\$DIALOG_TITLE\" \ 471 --backtitle \"\$DIALOG_BACKTITLE\" \ 472 --hline \"\$hline\" \ 473 --keep-tite \ 474 --ok-label \"$msg_select\" \ 475 --cancel-label \"$msg_back\" \ 476 ${SHOW_DESC:+--item-help} \ 477 --default-item \"\$defaultitem\" \
| 468 dialog_menu=$( eval $DIALOG \ 469 --title \"\$DIALOG_TITLE\" \ 470 --backtitle \"\$DIALOG_BACKTITLE\" \ 471 --hline \"\$hline\" \ 472 --keep-tite \ 473 --ok-label \"$msg_select\" \ 474 --cancel-label \"$msg_back\" \ 475 ${SHOW_DESC:+--item-help} \ 476 --default-item \"\$defaultitem\" \
|
478 --menu \"\$prompt\" $size \
| 477 --menu \"\$prompt\" \ 478 $mheight $mwidth $mrows \
|
479 $menu_list \ 480 --and-widget \ 481 ${USE_XDIALOG:+--no-buttons} \
| 479 $menu_list \ 480 --and-widget \ 481 ${USE_XDIALOG:+--no-buttons} \
|
482 --infobox \"\$msg_processing_selection\" $isize \
| 482 --infobox \"\$msg_processing_selection\" \ 483 $iheight $iwidth \
|
483 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 484 ) 485 local retval=$? 486 setvar DIALOG_MENU_$$ "$dialog_menu" 487 488 if [ $retval -eq $SUCCESS ]; then 489 item=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \ 490 \"\$dialog_menu\" $menu_list ) 491 setvar DIALOG_MENUITEM_$$ "$item" 492 fi 493 494 return $retval 495} 496 497# f_package_menu_deselect $package 498# 499# Display a menu, asking the user what they would like to do with $package 500# with regard to "deselecting" an already installed package. Choices include 501# uninstall, re-install, or cancel (leave $package marked as installed). 502# Returns success if the user does not press ESC or choose Cnacel. Use the 503# f_dialog_menutag() function upon success to retrieve the user's choice. 504# 505f_package_menu_deselect() 506{
| 484 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 485 ) 486 local retval=$? 487 setvar DIALOG_MENU_$$ "$dialog_menu" 488 489 if [ $retval -eq $SUCCESS ]; then 490 item=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \ 491 \"\$dialog_menu\" $menu_list ) 492 setvar DIALOG_MENUITEM_$$ "$item" 493 fi 494 495 return $retval 496} 497 498# f_package_menu_deselect $package 499# 500# Display a menu, asking the user what they would like to do with $package 501# with regard to "deselecting" an already installed package. Choices include 502# uninstall, re-install, or cancel (leave $package marked as installed). 503# Returns success if the user does not press ESC or choose Cnacel. Use the 504# f_dialog_menutag() function upon success to retrieve the user's choice. 505# 506f_package_menu_deselect() 507{
|
507 local package="$1" prompt menu_list size dialog_menu
| 508 local package="$1" prompt menu_list dialog_menu
|
508 prompt=$( printf "$msg_what_would_you_like_to_do_with" "$package" ) 509 local hline="$hline_alnum_arrows_punc_tab_enter" 510 menu_list=" 511 'X $msg_installed' '$msg_installed_desc' 512 'R $msg_reinstall' '$msg_reinstall_desc' 513 'U $msg_uninstall' '$msg_uninstall_desc' 514 " # End-Quote
| 509 prompt=$( printf "$msg_what_would_you_like_to_do_with" "$package" ) 510 local hline="$hline_alnum_arrows_punc_tab_enter" 511 menu_list=" 512 'X $msg_installed' '$msg_installed_desc' 513 'R $msg_reinstall' '$msg_reinstall_desc' 514 'U $msg_uninstall' '$msg_uninstall_desc' 515 " # End-Quote
|
515 size=$( eval f_dialog_menu_size \ 516 \"\$DIALOG_TITLE\" \ 517 \"\$DIALOG_BACKTITLE\" \ 518 \"\$prompt\" \ 519 \"\$hline\" \ 520 $menu_list )
| 516 517 local height width rows 518 eval f_dialog_menu_size height width rows \ 519 \"\$DIALOG_TITLE\" \ 520 \"\$DIALOG_BACKTITLE\" \ 521 \"\$prompt\" \ 522 \"\$hline\" \ 523 $menu_list 524
|
521 dialog_menu=$( eval $DIALOG \ 522 --title \"\$DIALOG_TITLE\" \ 523 --backtitle \"\$DIALOG_BACKTITLE\" \ 524 --hline \"\$hline\" \ 525 --ok-label \"$msg_select\" \ 526 --cancel-label \"$msg_cancel\" \
| 525 dialog_menu=$( eval $DIALOG \ 526 --title \"\$DIALOG_TITLE\" \ 527 --backtitle \"\$DIALOG_BACKTITLE\" \ 528 --hline \"\$hline\" \ 529 --ok-label \"$msg_select\" \ 530 --cancel-label \"$msg_cancel\" \
|
527 --menu \"\$prompt\" $size \
| 531 --menu \"\$prompt\" \ 532 $height $width $rows \
|
528 $menu_list \ 529 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 530 ) 531 local retval=$? 532 setvar DIALOG_MENU_$$ "$dialog_menu" 533 return $retval 534} 535 536# f_package_review 537# 538# Display a review screen, showing selected packages and what they are marked 539# for, before proceeding (if the user does not press ESC or choose Cancel) to 540# operate on each selection. Returns error if no packages have been selected, 541# or the user has pressed ESC, or if they have chosen Cancel. 542# 543f_package_review() 544{
| 533 $menu_list \ 534 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 535 ) 536 local retval=$? 537 setvar DIALOG_MENU_$$ "$dialog_menu" 538 return $retval 539} 540 541# f_package_review 542# 543# Display a review screen, showing selected packages and what they are marked 544# for, before proceeding (if the user does not press ESC or choose Cancel) to 545# operate on each selection. Returns error if no packages have been selected, 546# or the user has pressed ESC, or if they have chosen Cancel. 547# 548f_package_review() 549{
|
545 local prompt size dialog_menu package varpkg mark menu_list=
| 550 local prompt dialog_menu package varpkg mark menu_list=
|
546 prompt=$( printf "$msg_reviewing_selected_packages" \ 547 "$_All_nselected" ) 548 local hline="$hline_alnum_arrows_punc_tab_enter" 549 f_dprintf "f_package_review: SELECTED_PACKAGES=[%s]" \ 550 "$SELECTED_PACKAGES" 551 for package in $SELECTED_PACKAGES; do 552 mark= 553 f_str2varname "$package" varpkg 554 f_getvar _mark_$varpkg mark 555 [ "$mark" -a ! "${mark#[IRUD]}" ] || continue 556 menu_list="$menu_list 557 '$mark' '$package' 558 " # End-Quote 559 done 560 if [ ! "$menu_list" ]; then 561 f_show_msg "$msg_no_packages_were_selected_for_extraction" 562 return $FAILURE # They might have selected this by accident 563 fi 564 menu_list=$( echo "$menu_list" | sort )
| 551 prompt=$( printf "$msg_reviewing_selected_packages" \ 552 "$_All_nselected" ) 553 local hline="$hline_alnum_arrows_punc_tab_enter" 554 f_dprintf "f_package_review: SELECTED_PACKAGES=[%s]" \ 555 "$SELECTED_PACKAGES" 556 for package in $SELECTED_PACKAGES; do 557 mark= 558 f_str2varname "$package" varpkg 559 f_getvar _mark_$varpkg mark 560 [ "$mark" -a ! "${mark#[IRUD]}" ] || continue 561 menu_list="$menu_list 562 '$mark' '$package' 563 " # End-Quote 564 done 565 if [ ! "$menu_list" ]; then 566 f_show_msg "$msg_no_packages_were_selected_for_extraction" 567 return $FAILURE # They might have selected this by accident 568 fi 569 menu_list=$( echo "$menu_list" | sort )
|
565 size=$( eval f_dialog_menu_size \ 566 \"\$DIALOG_TITLE\" \ 567 \"\$DIALOG_BACKTITLE\" \ 568 \"\$prompt\" \ 569 \"\$hline\" \ 570 $menu_list )
| 570 571 local height width rows 572 eval f_dialog_menu_size height width rows \ 573 \"\$DIALOG_TITLE\" \ 574 \"\$DIALOG_BACKTITLE\" \ 575 \"\$prompt\" \ 576 \"\$hline\" \ 577 $menu_list 578
|
571 dialog_menu=$( eval $DIALOG \ 572 --title \"\$DIALOG_TITLE\" \ 573 --backtitle \"\$DIALOG_BACKTITLE\" \ 574 --hline \"\$hline\" \ 575 --ok-label \"\$msg_proceed\" \ 576 --cancel-label \"\$msg_cancel\" \
| 579 dialog_menu=$( eval $DIALOG \ 580 --title \"\$DIALOG_TITLE\" \ 581 --backtitle \"\$DIALOG_BACKTITLE\" \ 582 --hline \"\$hline\" \ 583 --ok-label \"\$msg_proceed\" \ 584 --cancel-label \"\$msg_cancel\" \
|
577 --menu \"\$prompt\" $size \
| 585 --menu \"\$prompt\" \ 586 $height $width $rows \
|
578 $menu_list \ 579 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 580 ) 581 local retval=$? 582 setvar DIALOG_MENU_$$ "$dialog_menu" 583 584 # 585 # XXX 586 # 587 f_show_msg "Coming soon..." 588 # 589 # XXX 590 # 591 592 return $retval 593} 594 595# f_package_config 596# 597# Allow the user to configure packages and install them. Initially, a list of 598# package categories is loaded/displayed. When the user selects a category, 599# the menus for that category are built (unlike sysinstall which built all 600# category menus up-front -- which also took forever, despite the fact that 601# few people visit more than a couple of categories each time). 602# 603f_package_config() 604{ 605 # Did we get an INDEX? 606 f_index_initialize packages/INDEX || return $FAILURE 607 # Creates following variables (indirectly via f_index_read()) 608 # CATEGORY_MENU_LIST _categories_{varpkg} _rundeps_{varpkg} 609 # PACKAGE_CATEGORIES _npkgs 610 611 # Detect installed packages (updates marks/SELECTED_PACKAGES) 612 f_package_detect_installed 613 614 local retval category varcat defaultitem category_defaultitem="" 615 while :; do 616 # Display the list of package categories 617 f_package_menu_categories \ 618 CATEGORY_MENU_LIST "$category_defaultitem" 619 retval=$? 620 category=$( f_dialog_menutag ) 621 f_dprintf "retval=%u mtag=[%s]" $retval "$category" 622 category_defaultitem="$category" 623 624 [ $retval -eq $SUCCESS ] || break 625 626 # Maybe the user chose an action (like `Review') 627 case "$category" in 628 "> $msg_review") 629 f_package_review && break 630 continue ;; 631 "> "*) 632 continue 633 esac 634 635 # Anything else is a package category 636 637 category=${category# } # Trim leading space if present 638 category=${category%\*} # Trim trailing asterisk if present 639 640 f_str2varname "$category" varcat 641 642 local page package varpkg mark 643 while :; do 644 # Display the list of packages for selected category 645 page=1 defaultitem="" 646 f_getvar _defaultitem_$varcat defaultitem 647 f_getvar _defaultpage_$varcat page 648 f_package_menu_select \ 649 "$category" "${page:=1}" "$defaultitem" 650 retval=$? 651 dialog_menu=$( f_dialog_menutag ) 652 f_dprintf "retval=%u mtag=[%s]" $retval "$dialog_menu" 653 654 # NOTE: When --and-widget is used only ESC will cause 655 # dialog(1) to return without going to the next widget. 656 # This is alright in our case as we can still detect 657 # the Cancel button because stdout will be NULL. 658 # Alternatively, Xdialog(1) will terminate with 1 659 # if/when Cancel is chosen on any widget. 660 if [ $retval -eq 255 -o ! "$dialog_menu" ]; then 661 # User pressed ESC or chose Cancel 662 break 663 elif [ $retval -eq 1 ]; then 664 # Using X11, Xdialog(1) returned 1 for Cancel 665 f_show_msg "%s" "$dialog_menu" 666 break 667 elif [ $retval -ne $SUCCESS ]; then 668 # X11-related error occurred using Xdialog(1) 669 f_show_msg "%s" "$dialog_menu" 670 break 671 fi 672 673 defaultitem="$dialog_menu" 674 675 # NOTE: f_package_menu_select() does not show the 676 # `Previous Page' or `Next Page' items unless needed 677 case "$dialog_menu" in 678 "> $msg_previous_page"|"> $msg_previous_page*") 679 page=$(( $page - 1 )) 680 setvar _defaultpage_$varcat $page 681 # Update default-item to match accent that will 682 # be applied by f_package_menu_select(); if the 683 # page-before-prev is cached, add an asterisk. 684 if f_isset \ 685 _index_page_${varcat}_$(( $page - 1 )) 686 then 687 defaultitem="${defaultitem%\*}*" 688 else 689 defaultitem="${defaultitem%\*}" 690 fi 691 setvar _defaultitem_$varcat "$defaultitem" 692 continue ;; 693 "> $msg_next_page"|"> $msg_next_page*") 694 page=$(( $page + 1 )) 695 setvar _defaultpage_$varcat $page 696 # Update default-item to match accent that will 697 # be applied by f_package_menu_select(); if the 698 # page-after-next is cached, add an asterisk. 699 if f_isset \ 700 _index_page_${varcat}_$(( $page + 1 )) 701 then 702 defaultitem="${defaultitem%\*}*" 703 else 704 defaultitem="${defaultitem%\*}" 705 fi 706 setvar _defaultitem_$varcat "$defaultitem" 707 continue ;; 708 "> "*) # Unknown navigation/action item 709 setvar _defaultpage_$varcat $page 710 continue ;; # Do not treat as a package 711 *) 712 setvar _defaultitem_$varcat "$defaultitem" 713 esac 714 715 # Treat any other selection as a package 716 package="${dialog_menu# }" # Trim leading space 717 f_str2varname $package varpkg 718 f_getvar DIALOG_MENUITEM_$$ mark 719 mark="${mark#?}" 720 mark="${mark%%\] *}" 721 case "$mark" in 722 "I") 723 mark=" " 724 f_package_deselect $package 725 ;; 726 " "|"D") 727 mark="I" 728 f_package_select $package 729 ;; 730 "X"|"R"|"U") 731 f_package_menu_deselect $package || continue 732 dialog_menu=$( f_dialog_menutag ) 733 case "$dialog_menu" in 734 "X $msg_installed") 735 f_package_deselect "$package" 736 mark="X" 737 ;; 738 "R $msg_reinstall") 739 f_package_select "$package" 740 mark="R" 741 ;; 742 "U $msg_uninstall") 743 f_package_select "$package" 744 mark="U" 745 ;; 746 esac 747 ;; 748 esac 749 export _mark_$varpkg="$mark" 750 # NOTE: exported for awk(1) ENVIRON[] 751 done 752 done 753} 754 755############################################################ MAIN 756 757f_dprintf "%s: Successfully loaded." packages/packages.subr 758 759fi # ! $_PACKAGES_PACKAGES_SUBR
| 587 $menu_list \ 588 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 589 ) 590 local retval=$? 591 setvar DIALOG_MENU_$$ "$dialog_menu" 592 593 # 594 # XXX 595 # 596 f_show_msg "Coming soon..." 597 # 598 # XXX 599 # 600 601 return $retval 602} 603 604# f_package_config 605# 606# Allow the user to configure packages and install them. Initially, a list of 607# package categories is loaded/displayed. When the user selects a category, 608# the menus for that category are built (unlike sysinstall which built all 609# category menus up-front -- which also took forever, despite the fact that 610# few people visit more than a couple of categories each time). 611# 612f_package_config() 613{ 614 # Did we get an INDEX? 615 f_index_initialize packages/INDEX || return $FAILURE 616 # Creates following variables (indirectly via f_index_read()) 617 # CATEGORY_MENU_LIST _categories_{varpkg} _rundeps_{varpkg} 618 # PACKAGE_CATEGORIES _npkgs 619 620 # Detect installed packages (updates marks/SELECTED_PACKAGES) 621 f_package_detect_installed 622 623 local retval category varcat defaultitem category_defaultitem="" 624 while :; do 625 # Display the list of package categories 626 f_package_menu_categories \ 627 CATEGORY_MENU_LIST "$category_defaultitem" 628 retval=$? 629 category=$( f_dialog_menutag ) 630 f_dprintf "retval=%u mtag=[%s]" $retval "$category" 631 category_defaultitem="$category" 632 633 [ $retval -eq $SUCCESS ] || break 634 635 # Maybe the user chose an action (like `Review') 636 case "$category" in 637 "> $msg_review") 638 f_package_review && break 639 continue ;; 640 "> "*) 641 continue 642 esac 643 644 # Anything else is a package category 645 646 category=${category# } # Trim leading space if present 647 category=${category%\*} # Trim trailing asterisk if present 648 649 f_str2varname "$category" varcat 650 651 local page package varpkg mark 652 while :; do 653 # Display the list of packages for selected category 654 page=1 defaultitem="" 655 f_getvar _defaultitem_$varcat defaultitem 656 f_getvar _defaultpage_$varcat page 657 f_package_menu_select \ 658 "$category" "${page:=1}" "$defaultitem" 659 retval=$? 660 dialog_menu=$( f_dialog_menutag ) 661 f_dprintf "retval=%u mtag=[%s]" $retval "$dialog_menu" 662 663 # NOTE: When --and-widget is used only ESC will cause 664 # dialog(1) to return without going to the next widget. 665 # This is alright in our case as we can still detect 666 # the Cancel button because stdout will be NULL. 667 # Alternatively, Xdialog(1) will terminate with 1 668 # if/when Cancel is chosen on any widget. 669 if [ $retval -eq 255 -o ! "$dialog_menu" ]; then 670 # User pressed ESC or chose Cancel 671 break 672 elif [ $retval -eq 1 ]; then 673 # Using X11, Xdialog(1) returned 1 for Cancel 674 f_show_msg "%s" "$dialog_menu" 675 break 676 elif [ $retval -ne $SUCCESS ]; then 677 # X11-related error occurred using Xdialog(1) 678 f_show_msg "%s" "$dialog_menu" 679 break 680 fi 681 682 defaultitem="$dialog_menu" 683 684 # NOTE: f_package_menu_select() does not show the 685 # `Previous Page' or `Next Page' items unless needed 686 case "$dialog_menu" in 687 "> $msg_previous_page"|"> $msg_previous_page*") 688 page=$(( $page - 1 )) 689 setvar _defaultpage_$varcat $page 690 # Update default-item to match accent that will 691 # be applied by f_package_menu_select(); if the 692 # page-before-prev is cached, add an asterisk. 693 if f_isset \ 694 _index_page_${varcat}_$(( $page - 1 )) 695 then 696 defaultitem="${defaultitem%\*}*" 697 else 698 defaultitem="${defaultitem%\*}" 699 fi 700 setvar _defaultitem_$varcat "$defaultitem" 701 continue ;; 702 "> $msg_next_page"|"> $msg_next_page*") 703 page=$(( $page + 1 )) 704 setvar _defaultpage_$varcat $page 705 # Update default-item to match accent that will 706 # be applied by f_package_menu_select(); if the 707 # page-after-next is cached, add an asterisk. 708 if f_isset \ 709 _index_page_${varcat}_$(( $page + 1 )) 710 then 711 defaultitem="${defaultitem%\*}*" 712 else 713 defaultitem="${defaultitem%\*}" 714 fi 715 setvar _defaultitem_$varcat "$defaultitem" 716 continue ;; 717 "> "*) # Unknown navigation/action item 718 setvar _defaultpage_$varcat $page 719 continue ;; # Do not treat as a package 720 *) 721 setvar _defaultitem_$varcat "$defaultitem" 722 esac 723 724 # Treat any other selection as a package 725 package="${dialog_menu# }" # Trim leading space 726 f_str2varname $package varpkg 727 f_getvar DIALOG_MENUITEM_$$ mark 728 mark="${mark#?}" 729 mark="${mark%%\] *}" 730 case "$mark" in 731 "I") 732 mark=" " 733 f_package_deselect $package 734 ;; 735 " "|"D") 736 mark="I" 737 f_package_select $package 738 ;; 739 "X"|"R"|"U") 740 f_package_menu_deselect $package || continue 741 dialog_menu=$( f_dialog_menutag ) 742 case "$dialog_menu" in 743 "X $msg_installed") 744 f_package_deselect "$package" 745 mark="X" 746 ;; 747 "R $msg_reinstall") 748 f_package_select "$package" 749 mark="R" 750 ;; 751 "U $msg_uninstall") 752 f_package_select "$package" 753 mark="U" 754 ;; 755 esac 756 ;; 757 esac 758 export _mark_$varpkg="$mark" 759 # NOTE: exported for awk(1) ENVIRON[] 760 done 761 done 762} 763 764############################################################ MAIN 765 766f_dprintf "%s: Successfully loaded." packages/packages.subr 767 768fi # ! $_PACKAGES_PACKAGES_SUBR
|