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