index.subr (256281) | index.subr (258420) |
---|---|
1if [ ! "$_PACKAGES_INDEX_SUBR" ]; then _PACKAGES_INDEX_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_INDEX_SUBR" ]; then _PACKAGES_INDEX_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/index.subr 252987 2013-07-07 18:51:44Z dteske $ | 27# $FreeBSD: stable/10/usr.sbin/bsdconfig/share/packages/index.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..." packages/index.subr 34f_include $BSDCFG_SHARE/device.subr 35f_include $BSDCFG_SHARE/media/common.subr 36f_include $BSDCFG_SHARE/strings.subr 37 38BSDCFG_LIBE="/usr/libexec/bsdconfig" 39f_include_lang $BSDCFG_LIBE/include/messages.subr 40 41############################################################ GLOBALS 42 43PACKAGE_INDEX= 44_INDEX_INITTED= 45 | 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." packages/index.subr 34f_include $BSDCFG_SHARE/device.subr 35f_include $BSDCFG_SHARE/media/common.subr 36f_include $BSDCFG_SHARE/strings.subr 37 38BSDCFG_LIBE="/usr/libexec/bsdconfig" 39f_include_lang $BSDCFG_LIBE/include/messages.subr 40 41############################################################ GLOBALS 42 43PACKAGE_INDEX= 44_INDEX_INITTED= 45 |
46# 47# Default path to pkg(8) repo-packagesite.sqlite database 48# 49SQLITE_REPO="/var/db/pkg/repo-packagesite.sqlite" 50 51# 52# Default path to on-disk cache INDEX file 53# 54PACKAGES_INDEX_CACHEFILE="/var/run/bsdconfig/packages_INDEX.cache" 55 56# 57# INDEX format for FreeBSD-6.0 or higher: 58# 59# package|port-origin|install-prefix|comment|port-desc-file|maintainer| 60# categories|build-deps|run-deps|www-site|reserve|reserve|reserve|disc 61# 62INDEX_FORMAT="%n-%v" # package 63INDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o" # port-origin 64INDEX_FORMAT="$INDEX_FORMAT|%p" # install-prefix 65INDEX_FORMAT="$INDEX_FORMAT|%c" # comment 66INDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o/pkg-descr" # port-desc-file 67INDEX_FORMAT="$INDEX_FORMAT|%m" # maintainer 68INDEX_FORMAT="$INDEX_FORMAT|@CATEGORIES@" # place-holder 69INDEX_FORMAT="$INDEX_FORMAT|" # build-deps 70INDEX_FORMAT="$INDEX_FORMAT|@RUNDEPS@" # place-holder 71INDEX_FORMAT="$INDEX_FORMAT|%w" # www-site 72INDEX_FORMAT="$INDEX_FORMAT|" # reserved 73INDEX_FORMAT="$INDEX_FORMAT|" # reserved 74INDEX_FORMAT="$INDEX_FORMAT|" # reserved 75INDEX_FORMAT="$INDEX_FORMAT|" # disc 76 |
|
46############################################################ FUNCTIONS 47 | 77############################################################ FUNCTIONS 78 |
48# f_index_initialize $path [$var_to_set] | 79# f_index_initialize [$var_to_set] |
49# | 80# |
50# Read and initialize the global index. $path is to be relative to the chosen 51# media (not necessarily the filesystem; e.g. FTP) -- this is usually going to 52# be `packages/INDEX'. Returns success unless media cannot be initialized for 53# any reason (e.g. user cancels media selection dialog) or an error occurs. The 54# index is sorted before being loaded into $var_to_set. | 81# Read and initialize the global index. Returns success unless media cannot be 82# initialized for any reason (e.g. user cancels media selection dialog or an 83# error occurs). The index is sorted before being loaded into $var_to_set. |
55# 56# NOTE: The index is processed with f_index_read() [below] after being loaded. 57# 58f_index_initialize() 59{ | 84# 85# NOTE: The index is processed with f_index_read() [below] after being loaded. 86# 87f_index_initialize() 88{ |
60 local __path="$1" __var_to_set="${2:-PACKAGE_INDEX}" | 89 local __funcname=f_index_initialize 90 local __var_to_set="${2:-PACKAGE_INDEX}" |
61 62 [ "$_INDEX_INITTED" ] && return $SUCCESS | 91 92 [ "$_INDEX_INITTED" ] && return $SUCCESS |
63 [ "$__path" ] || return $FAILURE | |
64 65 # Got any media? 66 f_media_verify || return $FAILURE 67 68 # Does it move when you kick it? 69 f_device_init media || return $FAILURE 70 | 93 94 # Got any media? 95 f_media_verify || return $FAILURE 96 97 # Does it move when you kick it? 98 f_device_init media || return $FAILURE 99 |
71 f_show_info "$msg_attempting_to_fetch_file_from_selected_media" \ 72 "$__path" 73 eval "$__var_to_set"='$( f_device_get media "$__path" )' 74 if [ $? -ne $SUCCESS ]; then 75 f_show_msg "$msg_unable_to_get_file_from_selected_media" \ 76 "$__path" | 100 f_show_info "$msg_attempting_to_update_repository_catalogue" 101 102 # 103 # Generate $PACKAGESITE variable for pkg(8) based on media type 104 # 105 local __type __data __site 106 device_media get type __type 107 device_media get private __data 108 case "$__type" in 109 $DEVICE_TYPE_DIRECTORY) 110 __site="file://$__data/packages/$PKG_ABI" ;; 111 $DEVICE_TYPE_FLOPPY) 112 __site="file://${__data:-$MOUNTPOINT}/packages/$PKG_ABI" ;; 113 $DEVICE_TYPE_FTP) 114 f_getvar $VAR_FTP_PATH __site 115 __site="$__site/packages/$PKG_ABI" ;; 116 $DEVICE_TYPE_HTTP) 117 f_getvar $VAR_HTTP_PATH __site 118 __site="$__site/$PKG_ABI/latest" ;; 119 $DEVICE_TYPE_HTTP_PROXY) 120 f_getvar $VAR_HTTP_PROXY_PATH __site 121 __site="$__site/packages/$PKG_ABI" ;; 122 *) # UFS, DISK, CDROM, USB, DOS, NFS, etc. 123 __site="file://$MOUNTPOINT/packages/$PKG_ABI" 124 esac 125 126 export PACKAGESITE="$__site" 127 f_dprintf "PACKAGESITE=[%s]" "$PACKAGESITE" 128 if ! f_eval_catch $__funcname pkg "pkg update"; then 129 f_show_err "$msg_unable_to_update_pkg_from_selected_media" |
77 f_device_shutdown media 78 return $FAILURE 79 fi | 130 f_device_shutdown media 131 return $FAILURE 132 fi |
133 134 # 135 # Try to get contents from validated on-disk cache 136 # 137 138 # 139 # Calculate digest used to determine if the on-disk persistant cache 140 # INDEX (containing this digest on the first line) is valid and can be 141 # used to quickly populate the environment. 142 # 143 local __sqlite_digest 144 if ! __sqlite_digest=$( md5 < "$SQLITE_REPO" 2> /dev/null ); then 145 f_show_err "$msg_no_pkg_database_found" 146 f_device_shutdown media 147 return $FAILURE 148 fi 149 150 # 151 # Check to see if the persistant cache INDEX file exists 152 # 153 if [ -f "$PACKAGES_INDEX_CACHEFILE" ]; then 154 # 155 # Attempt to populate the environment with the (soon to be) 156 # validated on-disk cache. If validation fails, fall-back to 157 # generating a fresh cache. 158 # 159 if eval $__var_to_set='$( 160 ( # Get digest as the first word on first line 161 read digest rest_ignored 162 163 # 164 # If the stored digest matches the calculated- 165 # one populate the environment from the on-disk 166 # cache and provide success exit status. 167 # 168 if [ "$digest" = "$__sqlite_digest" ]; then 169 cat 170 exit $SUCCESS 171 else 172 # Otherwise, return the current value 173 eval echo \"\$__var_to_set\" 174 exit $FAILURE 175 fi 176 ) < "$PACKAGES_INDEX_CACHEFILE" 2> /dev/null 177 )'; then 178 f_show_info \ 179 "$msg_located_index_now_reading_package_data_from_it" 180 if ! f_index_read "$__var_to_set"; then 181 f_show_err \ 182 "$msg_io_or_format_error_on_index_file" 183 return $FAILURE 184 fi 185 _INDEX_INITTED=1 186 return $SUCCESS 187 fi 188 # Otherwise, fall-thru to create a fresh cache from scratch 189 fi 190 191 # 192 # If we reach this point, we need to generate the data from scratch 193 # 194 195 f_show_info "$msg_getting_package_categories_via_pkg_rquery" 196 if ! eval "$( pkg rquery "%n-%v %C" | awk ' 197 { categories[$1] = categories[$1] " " $2 } 198 END { 199 for (package in categories) 200 { 201 cats = categories[package] 202 sub(/^ /, "", cats) 203 gsub(/[^[:alnum:]_]/, "_", package) 204 printf "local _%s_categories=\"%s\";\n", package, cats 205 } 206 }' )"; then 207 f_show_err "$msg_unable_to_pkg_rquery_package_dependencies" 208 f_device_shutdown media 209 return $FAILURE 210 fi 211 212 f_show_info "$msg_getting_package_dependencies_via_pkg_rquery" 213 if ! eval "$( pkg rquery "%n-%v %dn-%dv" | awk ' 214 { rundeps[$1] = rundeps[$1] " " $2 } 215 END { 216 for (package in rundeps) 217 { 218 deps = rundeps[package] 219 sub(/^ /, "", deps) 220 gsub(/[^[:alnum:]_]/, "_", package) 221 printf "local _%s_rundeps=\"%s\";\n", package, deps 222 } 223 }' )"; then 224 f_show_err "$msg_unable_to_pkg_rquery_package_dependencies" 225 f_device_shutdown media 226 return $FAILURE 227 fi 228 229 f_show_info "$msg_generating_index_from_pkg_database" 230 eval "$__var_to_set"='$( pkg rquery "$INDEX_FORMAT" | 231 while read LINE; do 232 package="${LINE%%|*}"; 233 f_str2varname "$package" varpkg; 234 eval f_replaceall \"\$LINE\" \"\|@CATEGORIES@\|\" \ 235 \"\|\$_${varpkg}_categories\|\" LINE 236 eval f_replaceall \"\$LINE\" \"\|@RUNDEPS@\|\" \ 237 \"\|\$_${varpkg}_rundeps\|\" LINE 238 echo "$LINE" 239 done 240 )' # always returns true (status of last item in pipe-chain) |
|
80 eval "$__var_to_set"='$( debug= f_getvar "$__var_to_set" | sort )' 81 | 241 eval "$__var_to_set"='$( debug= f_getvar "$__var_to_set" | sort )' 242 |
243 # 244 # Attempt to create the persistant on-disk cache 245 # 246 247 # Create a new temporary file to write to 248 local __tmpfile="$( mktemp -t "$pgm" )" 249 if [ "$__tmpfile" ]; then 250 # Write the temporary file contents 251 echo "$__sqlite_digest" > "$__tmpfile" 252 debug= f_getvar "$__var_to_set" >> "$__tmpfile" 253 254 # Finally, move the temporary file into place 255 case "$PACKAGES_INDEX_CACHEFILE" in 256 */*) f_quietly mkdir -p "${PACKAGES_INDEX_CACHEFILE%/*}" 257 esac 258 f_quietly mv -f "$__tmpfile" "$PACKAGES_INDEX_CACHEFILE" 259 fi 260 |
|
82 f_show_info "$msg_located_index_now_reading_package_data_from_it" 83 if ! f_index_read "$__var_to_set"; then | 261 f_show_info "$msg_located_index_now_reading_package_data_from_it" 262 if ! f_index_read "$__var_to_set"; then |
84 f_show_msg "$msg_io_or_format_error_on_index_file" "$__path" | 263 f_show_err "$msg_io_or_format_error_on_index_file" |
85 return $FAILURE 86 fi 87 88 _INDEX_INITTED=1 89 return $SUCCESS 90} 91 92# f_index_read [$var_to_get] --- 195 unchanged lines hidden --- | 264 return $FAILURE 265 fi 266 267 _INDEX_INITTED=1 268 return $SUCCESS 269} 270 271# f_index_read [$var_to_get] --- 195 unchanged lines hidden --- |