packages.subr (256281) | packages.subr (258420) |
---|---|
1if [ ! "$_PACKAGES_PACKAGES_SUBR" ]; then _PACKAGES_PACKAGES_SUBR=1 2# 3# Copyright (c) 2013 Devin Teske 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# | 1if [ ! "$_PACKAGES_PACKAGES_SUBR" ]; then _PACKAGES_PACKAGES_SUBR=1 2# 3# Copyright (c) 2013 Devin Teske 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, 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: stable/10/usr.sbin/bsdconfig/share/packages/packages.subr 256181 2013-10-09 08:12:26Z dteske $ | 27# $FreeBSD: stable/10/usr.sbin/bsdconfig/share/packages/packages.subr 258420 2013-11-21 03:38:47Z 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/device.subr --- 12 unchanged lines hidden (view full) --- 48# 49: ${PACKAGE_MENU_PAGESIZE:=2000} 50 51############################################################ GLOBALS 52 53# 54# Package extensions to try 55# | 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/device.subr --- 12 unchanged lines hidden (view full) --- 48# 49: ${PACKAGE_MENU_PAGESIZE:=2000} 50 51############################################################ GLOBALS 52 53# 54# Package extensions to try 55# |
56PACKAGE_EXTENSIONS=".tbz .tbz2 .tgz" | 56PACKAGE_EXTENSIONS=".txz .tbz .tbz2 .tgz" |
57 58# 59# Variables used to track runtime states 60# 61PACKAGES_DETECTED= # Boolean (NULL/non-NULL); detected installed packages? 62PACKAGE_CATEGORIES= # List of package categories parsed from INDEX 63SELECTED_PACKAGES= # Packages selected by user in [X]dialog(1) interface 64 --- 94 unchanged lines hidden (view full) --- 159 done 160 SELECTED_PACKAGES="$new_list" 161 f_dprintf "Removed %s from selection list" "$package" 162 done 163} 164 165# f_package_detect_installed 166# | 57 58# 59# Variables used to track runtime states 60# 61PACKAGES_DETECTED= # Boolean (NULL/non-NULL); detected installed packages? 62PACKAGE_CATEGORIES= # List of package categories parsed from INDEX 63SELECTED_PACKAGES= # Packages selected by user in [X]dialog(1) interface 64 --- 94 unchanged lines hidden (view full) --- 159 done 160 SELECTED_PACKAGES="$new_list" 161 f_dprintf "Removed %s from selection list" "$package" 162 done 163} 164 165# f_package_detect_installed 166# |
167# Detect installed packages. Currently this searches /var/db/pkg for directory | 167# Detect installed packages. Currently this uses pkg-query(8) for querying |
168# entries and marks each entry as an installed/selected package. 169# 170f_package_detect_installed() 171{ | 168# entries and marks each entry as an installed/selected package. 169# 170f_package_detect_installed() 171{ |
172 local installed package varpkg 173 # 174 # XXX KLUDGE ALERT! This makes evil assumptions about how XXX 175 # packages register themselves and should *really* be done with 176 # `pkg_info -e <name>' except that this is too slow for an 177 # item check routine.. :-( 178 # 179 # NOTE: When transitioning to pkgng, make a single fork to `pkg' to 180 # produce a list of all installed packages and parse _that_ 181 # 182 installed=$( find -s /var/db/pkg -mindepth 1 -maxdepth 1 -type d | 183 sed -e 's:/var/db/pkg/::' ) 184 for package in $installed; do | 172 local package varpkg 173 for package in $( pkg query "%n-%v" ); do |
185 f_str2varname $package varpkg 186 export _mark_$varpkg=X # exported for awk(1) ENVIRON[] 187 f_package_select $package 188 done 189} 190 191# f_package_calculate_totals 192# --- 384 unchanged lines hidden (view full) --- 577# 578# Display a review screen, showing selected packages and what they are marked 579# for, before proceeding (if the user does not press ESC or choose Cancel) to 580# operate on each selection. Returns error if no packages have been selected, 581# or the user has pressed ESC, or if they have chosen Cancel. 582# 583f_package_review() 584{ | 174 f_str2varname $package varpkg 175 export _mark_$varpkg=X # exported for awk(1) ENVIRON[] 176 f_package_select $package 177 done 178} 179 180# f_package_calculate_totals 181# --- 384 unchanged lines hidden (view full) --- 566# 567# Display a review screen, showing selected packages and what they are marked 568# for, before proceeding (if the user does not press ESC or choose Cancel) to 569# operate on each selection. Returns error if no packages have been selected, 570# or the user has pressed ESC, or if they have chosen Cancel. 571# 572f_package_review() 573{ |
574 local funcname=f_package_review |
|
585 local prompt # Calculated below 586 local menu_list # Calculated below 587 local hline="$hline_alnum_arrows_punc_tab_enter" 588 | 575 local prompt # Calculated below 576 local menu_list # Calculated below 577 local hline="$hline_alnum_arrows_punc_tab_enter" 578 |
589 local fname=f_package_review 590 f_dprintf "%s: SELECTED_PACKAGES=[%s]" $fname "$SELECTED_PACKAGES" | 579 f_dprintf "$funcname: SELECTED_PACKAGES=[%s]" "$SELECTED_PACKAGES" |
591 592 prompt=$( printf "$msg_reviewing_selected_packages" "$_All_nselected" ) 593 594 local package varpkg mark 595 for package in $SELECTED_PACKAGES; do 596 mark= 597 f_str2varname "$package" varpkg 598 f_getvar _mark_$varpkg mark --- 35 unchanged lines hidden (view full) --- 634 # + Second, process packages marked for Re-install. 635 # + Finally, process packages marked for Uninstall. 636 # 637 for package in $SELECTED_PACKAGES; do 638 mark= 639 f_str2varname "$package" varpkg 640 debug= f_getvar _mark_$varpkg mark 641 [ "$mark" = "I" ] || continue | 580 581 prompt=$( printf "$msg_reviewing_selected_packages" "$_All_nselected" ) 582 583 local package varpkg mark 584 for package in $SELECTED_PACKAGES; do 585 mark= 586 f_str2varname "$package" varpkg 587 f_getvar _mark_$varpkg mark --- 35 unchanged lines hidden (view full) --- 623 # + Second, process packages marked for Re-install. 624 # + Finally, process packages marked for Uninstall. 625 # 626 for package in $SELECTED_PACKAGES; do 627 mark= 628 f_str2varname "$package" varpkg 629 debug= f_getvar _mark_$varpkg mark 630 [ "$mark" = "I" ] || continue |
642 f_dprintf "%s: Installing %s package" $fname "$package" | 631 f_dprintf "$funcname: Installing %s package" "$package" |
643 f_package_add "$package" 644 done 645 for package in $SELECTED_PACKAGES; do 646 mark= 647 f_str2varname "$package" varpkg 648 debug= f_getvar _mark_$varpkg mark 649 [ "$mark" = "R" ] || continue | 632 f_package_add "$package" 633 done 634 for package in $SELECTED_PACKAGES; do 635 mark= 636 f_str2varname "$package" varpkg 637 debug= f_getvar _mark_$varpkg mark 638 [ "$mark" = "R" ] || continue |
650 f_dprintf "%s: Reinstalling %s package" $fname "$package" | 639 f_dprintf "$funcname: Reinstalling %s package" "$package" |
651 f_package_reinstall "$package" 652 done 653 for package in $SELECTED_PACKAGES; do 654 mark= 655 f_str2varname "$package" varpkg 656 debug= f_getvar _mark_$varpkg mark 657 [ "$mark" = "U" ] || continue | 640 f_package_reinstall "$package" 641 done 642 for package in $SELECTED_PACKAGES; do 643 mark= 644 f_str2varname "$package" varpkg 645 debug= f_getvar _mark_$varpkg mark 646 [ "$mark" = "U" ] || continue |
658 f_dprintf "%s: Uninstalling %s package" $fname "$package" | 647 f_dprintf "$funcname: Uninstalling %s package" "$package" |
659 f_package_delete "$package" || continue 660 f_package_deselect "$package" 661 done 662 663 return $DIALOG_OK 664} 665 666# f_package_config --- 282 unchanged lines hidden (view full) --- 949# f_package_extract $device $name [$depended] 950# 951# Extract a package based on a namespec and media device. If $depended is 952# present and non-NULL, the notification displayed while installing the package 953# has "as a dependency" appended. 954# 955f_package_extract() 956{ | 648 f_package_delete "$package" || continue 649 f_package_deselect "$package" 650 done 651 652 return $DIALOG_OK 653} 654 655# f_package_config --- 282 unchanged lines hidden (view full) --- 938# f_package_extract $device $name [$depended] 939# 940# Extract a package based on a namespec and media device. If $depended is 941# present and non-NULL, the notification displayed while installing the package 942# has "as a dependency" appended. 943# 944f_package_extract() 945{ |
946 local funcname=f_package_extract |
|
957 local device="$1" name="$2" depended="$3" 958 | 947 local device="$1" name="$2" depended="$3" 948 |
959 local fname=f_package_extract 960 f_dprintf "%s: device=[%s] name=[%s] depended=[%s]" \ 961 $fname "$device" "$name" "$depended" | 949 f_dprintf "$funcname: device=[%s] name=[%s] depended=[%s]" \ 950 "$device" "$name" "$depended" |
962 963 # Check to make sure it's not already there 964 local varpkg mark= 965 f_str2varname "$name" varpkg 966 f_getvar _mark_$varpkg mark 967 [ "$mark" = "X" ] && return $SUCCESS 968 969 if ! f_device_init $device; then --- 7 unchanged lines hidden (view full) --- 977 f_quietly ldconfig /usr/lib /usr/lib/compat /usr/local/lib 978 979 # Make a couple paranoid locations for temp 980 # files to live if user specified none 981 local tmpdir 982 f_getvar $VAR_PKG_TMPDIR:-/var/tmp tmpdir 983 f_quietly mkdir -p -m 1777 "$tmpdir" 984 | 951 952 # Check to make sure it's not already there 953 local varpkg mark= 954 f_str2varname "$name" varpkg 955 f_getvar _mark_$varpkg mark 956 [ "$mark" = "X" ] && return $SUCCESS 957 958 if ! f_device_init $device; then --- 7 unchanged lines hidden (view full) --- 966 f_quietly ldconfig /usr/lib /usr/lib/compat /usr/local/lib 967 968 # Make a couple paranoid locations for temp 969 # files to live if user specified none 970 local tmpdir 971 f_getvar $VAR_PKG_TMPDIR:-/var/tmp tmpdir 972 f_quietly mkdir -p -m 1777 "$tmpdir" 973 |
985 local path | 974 local path device_type 975 device_$device get type device_type |
986 case "$name" in 987 */*) path="$name" ;; 988 *) | 976 case "$name" in 977 */*) path="$name" ;; 978 *) |
989 case "$name" in 990 *-*|*_*) path="packages/All/$name" ;; 991 *) path="packages/Latest/$name" 992 esac | 979 if [ "$device_type" = "$DEVICE_TYPE_HTTP" ]; then 980 path="$PKG_ABI/latest/All/$name" 981 else 982 path="packages/$PKG_ABI/All/$name" 983 fi |
993 esac 994 | 984 esac 985 |
995 # We have a path, call the device strategy routine to get the file | 986 # We have a path, call the device strategy routine to check the file |
996 local pkg_ext found= 997 for pkg_ext in "" $PACKAGE_EXTENSIONS; do 998 if f_device_get $device "$path$pkg_ext" $PROBE_EXIST; then 999 path="$path$pkg_ext" | 987 local pkg_ext found= 988 for pkg_ext in "" $PACKAGE_EXTENSIONS; do 989 if f_device_get $device "$path$pkg_ext" $PROBE_EXIST; then 990 path="$path$pkg_ext" |
1000 f_dprintf "%s: found path=[%s] dev=[%s]" \ 1001 $fname "$path" "$device" | |
1002 found=1 1003 break | 991 found=1 992 break |
993 elif [ "$device_type" = "$DEVICE_TYPE_HTTP" ] && 994 f_device_get $device \ 995 "packages/$PKG_ABI/All/$name$pkg_ext" $PROBE_EXIST 996 then 997 # Mirroring physical media over HTTP 998 path="packages/$PKG_ABI/All/$name$pkg_ext" 999 found=1 1000 break |
|
1004 fi 1005 done | 1001 fi 1002 done |
1003 [ "$found" ] && f_dprintf "$funcname: found path=[%s] dev=[%s]" \ 1004 "$path" "$device" |
|
1006 1007 local alert=f_show_msg no_confirm= 1008 f_getvar $VAR_NO_CONFIRM no_confirm 1009 [ "$no_confirm" ] && alert=f_show_info 1010 1011 if [ ! "$found" ]; then | 1005 1006 local alert=f_show_msg no_confirm= 1007 f_getvar $VAR_NO_CONFIRM no_confirm 1008 [ "$no_confirm" ] && alert=f_show_info 1009 1010 if [ ! "$found" ]; then |
1012 f_dprintf "%s: No such %s file on %s device" \ 1013 $fname "$path" "$device" | 1011 f_dprintf "$funcname: No such %s file on %s device" \ 1012 "$path" "$device" |
1014 $alert "$msg_unable_to_fetch_package_from_selected_media" \ 1015 "$name" 1016 [ "$no_confirm" ] && sleep 2 1017 return $FAILURE 1018 fi 1019 1020 local devname= 1021 f_struct device_$device get name devname 1022 if [ "$depended" ]; then 1023 f_show_info "$msg_adding_package_as_a_dependency_from_media" \ 1024 "$name" "$devname" 1025 else 1026 f_show_info "$msg_adding_package_from_media" "$name" "$devname" 1027 fi 1028 | 1013 $alert "$msg_unable_to_fetch_package_from_selected_media" \ 1014 "$name" 1015 [ "$no_confirm" ] && sleep 2 1016 return $FAILURE 1017 fi 1018 1019 local devname= 1020 f_struct device_$device get name devname 1021 if [ "$depended" ]; then 1022 f_show_info "$msg_adding_package_as_a_dependency_from_media" \ 1023 "$name" "$devname" 1024 else 1025 f_show_info "$msg_adding_package_from_media" "$name" "$devname" 1026 fi 1027 |
1029 # Get package data and pipe into pkg_add(1) while providing feedback 1030 { 1031 if ! f_device_get $device "$path"; then 1032 $alert "$msg_io_error_while_reading_in_the_package" \ 1033 "$name" \ 1034 >&$DIALOG_TERMINAL_PASSTHRU_FD 2> /dev/null 1035 [ "$no_confirm" ] && sleep 2 1036 else 1037 f_show_info \ 1038 "$msg_package_read_successfully_waiting_for_pkg_add" \ 1039 "$name" >&$DIALOG_TERMINAL_PASSTHRU_FD 2> /dev/null 1040 fi 1041 } | { 1042 if f_debugging; then 1043 /usr/sbin/pkg_add -v - 1044 else 1045 f_quietly /usr/sbin/pkg_add - 1046 fi 1047 } | 1028 # Request the package be added via pkg-install(8) 1029 if f_debugging; then 1030 f_eval_catch $funcname pkg 'pkg -d install -y "%s"' "$name" 1031 else 1032 f_eval_catch $funcname pkg 'pkg install -y "%s"' "$name" 1033 fi |
1048 if [ $? -ne $SUCCESS ]; then | 1034 if [ $? -ne $SUCCESS ]; then |
1049 $alert "$msg_pkg_add_apparently_did_not_like_the_package" \ | 1035 $alert "$msg_pkg_install_apparently_did_not_like_the_package" \ |
1050 "$name" 1051 [ "$no_confirm" ] && sleep 2 1052 else 1053 f_show_info "$msg_package_was_added_successfully" "$name" 1054 sleep 1 1055 fi 1056 1057 return $SUCCESS 1058} 1059 1060# f_package_delete $name 1061# 1062# Delete package by full $name (lacks archive suffix; e.g., `.tbz'). 1063# 1064f_package_delete() 1065{ | 1036 "$name" 1037 [ "$no_confirm" ] && sleep 2 1038 else 1039 f_show_info "$msg_package_was_added_successfully" "$name" 1040 sleep 1 1041 fi 1042 1043 return $SUCCESS 1044} 1045 1046# f_package_delete $name 1047# 1048# Delete package by full $name (lacks archive suffix; e.g., `.tbz'). 1049# 1050f_package_delete() 1051{ |
1052 local funcname=f_package_delete |
|
1066 local name="$1" | 1053 local name="$1" |
1067 local fname=f_package_delete | |
1068 1069 if ! { [ "$name" ] || { f_getvar $VAR_PACKAGE name && [ "$name" ]; }; } 1070 then 1071 f_dprintf "packageDelete: %s" \ 1072 "$msg_no_package_name_passed_in_package_variable" 1073 return $FAILURE 1074 fi 1075 | 1054 1055 if ! { [ "$name" ] || { f_getvar $VAR_PACKAGE name && [ "$name" ]; }; } 1056 then 1057 f_dprintf "packageDelete: %s" \ 1058 "$msg_no_package_name_passed_in_package_variable" 1059 return $FAILURE 1060 fi 1061 |
1076 f_dprintf "%s: name=[%s]" $fname "$name" | 1062 f_dprintf "$funcname: name=[%s]" "$name" |
1077 1078 [ "$name" ] || return $FAILURE 1079 1080 { # Verify and initialize device media if-defined 1081 f_media_verify && 1082 f_device_init media && 1083 f_index_initialize packages/INDEX 1084 } || return $FAILURE --- 20 unchanged lines hidden (view full) --- 1105 fi 1106 f_str2varname "$name" varpkg 1107 fi 1108 1109 # If invoked through the scripted interface, we likely have not yet 1110 # detected the installed packages -- something we should do only once. 1111 # 1112 if [ ! "$PACKAGES_DETECTED" ]; then | 1063 1064 [ "$name" ] || return $FAILURE 1065 1066 { # Verify and initialize device media if-defined 1067 f_media_verify && 1068 f_device_init media && 1069 f_index_initialize packages/INDEX 1070 } || return $FAILURE --- 20 unchanged lines hidden (view full) --- 1091 fi 1092 f_str2varname "$name" varpkg 1093 fi 1094 1095 # If invoked through the scripted interface, we likely have not yet 1096 # detected the installed packages -- something we should do only once. 1097 # 1098 if [ ! "$PACKAGES_DETECTED" ]; then |
1113 f_dprintf "%s: Detecting installed packages" $fname | 1099 f_dprintf "$funcname: Detecting installed packages" |
1114 f_package_detect_installed 1115 export PACKAGES_DETECTED=1 # exported for awk(1) ENVIRON[] 1116 fi 1117 # Now we have: _mark_{varpkg}=X for all installed packages 1118 1119 # 1120 # Return failure if the package is not already installed. 1121 # --- 35 unchanged lines hidden (view full) --- 1157 "$name" "$depc" "$grammatical_s" 1158 return $FAILURE 1159 fi 1160 1161 # 1162 # Chase dependencies that are marked for uninstallation 1163 # 1164 for pkgsel in $udeps; do | 1100 f_package_detect_installed 1101 export PACKAGES_DETECTED=1 # exported for awk(1) ENVIRON[] 1102 fi 1103 # Now we have: _mark_{varpkg}=X for all installed packages 1104 1105 # 1106 # Return failure if the package is not already installed. 1107 # --- 35 unchanged lines hidden (view full) --- 1143 "$name" "$depc" "$grammatical_s" 1144 return $FAILURE 1145 fi 1146 1147 # 1148 # Chase dependencies that are marked for uninstallation 1149 # 1150 for pkgsel in $udeps; do |
1165 f_dprintf "%s: Uninstalling dependecy %s (marked for delete)" \ 1166 $fname "$pkgsel" | 1151 f_dprintf "$funcname: Uninstalling dependency %s (%s)" \ 1152 "$pkgsel" "marked for delete" |
1167 f_package_delete "$pkgsel" 1168 done 1169 1170 # 1171 # OK to perform the delete (no other packages depend on it)... 1172 # 1173 f_show_info "$msg_uninstalling_package_waiting_for_pkg_delete" "$name" 1174 if f_debugging; then | 1153 f_package_delete "$pkgsel" 1154 done 1155 1156 # 1157 # OK to perform the delete (no other packages depend on it)... 1158 # 1159 f_show_info "$msg_uninstalling_package_waiting_for_pkg_delete" "$name" 1160 if f_debugging; then |
1175 pkg_delete -v "$name" | 1161 f_eval_catch $funcname pkg 'pkg -d delete -y "%s"' "$name" |
1176 else | 1162 else |
1177 f_quietly pkg_delete "$name" | 1163 f_eval_catch $funcname pkg 'pkg delete -y "%s"' "$name" |
1178 fi 1179 if [ $? -ne $SUCCESS ]; then 1180 f_show_msg "$msg_pkg_delete_failed" "$name" 1181 return $FAILURE 1182 else | 1164 fi 1165 if [ $? -ne $SUCCESS ]; then 1166 f_show_msg "$msg_pkg_delete_failed" "$name" 1167 return $FAILURE 1168 else |
1183 f_dprintf "%s: pkg_delete(1) of %s successful" $fname "$name" | 1169 f_dprintf "$funcname: pkg-delete(8) of %s successful" "$name" |
1184 f_str2varname "$name" varpkg 1185 setvar _mark_$varpkg "" 1186 fi 1187} 1188 1189# f_package_reinstall $name 1190# 1191# A simple wrapper to f_package_delete() + f_package_add() 1192# 1193f_package_reinstall() 1194{ 1195 f_package_delete "$1" && f_package_add "$1" 1196} 1197 1198############################################################ MAIN 1199 1200f_dprintf "%s: Successfully loaded." packages/packages.subr 1201 1202fi # ! $_PACKAGES_PACKAGES_SUBR | 1170 f_str2varname "$name" varpkg 1171 setvar _mark_$varpkg "" 1172 fi 1173} 1174 1175# f_package_reinstall $name 1176# 1177# A simple wrapper to f_package_delete() + f_package_add() 1178# 1179f_package_reinstall() 1180{ 1181 f_package_delete "$1" && f_package_add "$1" 1182} 1183 1184############################################################ MAIN 1185 1186f_dprintf "%s: Successfully loaded." packages/packages.subr 1187 1188fi # ! $_PACKAGES_PACKAGES_SUBR |