comparison sbin/check-ports @ 150:937c96ffe358

Implemented the "-n" option to check only given packages but in the most detail possible
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 03 Nov 2019 18:06:31 +0100
parents c4e9099a3d3e
children 27b7454140be
comparison
equal deleted inserted replaced
149:04deefed8c61 150:937c96ffe358
245 printf '%-*s %-15s: %-17s %s %s\n' $((_indent)) '' "${_repo}" "${_version}" "${_label}" "${_real_descr}" 245 printf '%-*s %-15s: %-17s %s %s\n' $((_indent)) '' "${_repo}" "${_version}" "${_label}" "${_real_descr}"
246 } 246 }
247 247
248 248
249 check_ports() { 249 check_ports() {
250 : 'Implementation of main 250 : 'Implementation of all command variants besides of `-n`
251 251
252 ' 252 '
253 local _ipackage _iversion _irepo _mapped_package_name _dummy 253 local _ipackage _iversion _irepo _mapped_package_name _dummy
254 local _print_detail _local_index_exists 254 local _print_detail _local_index_exists
255 local _index_version _index_label _index_descr 255 local _index_version _index_label _index_descr
384 fi 384 fi
385 done 385 done
386 } 386 }
387 387
388 388
389 check_packages() {
390 : 'Check the status of all given packages in the most detail possible
391
392 Args:
393 $@: the name of packaged to handle to
394
395 '
396 local _package _version _label _repo _descr _dummy
397 local _local_index_exists _mapped_package_name
398
399 if test_exists_local_index; then
400 _local_index_exists="1"
401 fi
402
403 while [ $# -gt 0 ]; do
404 _package="$1"
405 shift
406 read -r _version _repo <<EOF_INSTALLED
407 $(pkg query '%v %R' "${_package}")
408 EOF_INSTALLED
409 if [ -n "${_version}" ]; then
410 title_printed=""
411 print_title "${_package}" "${_version}" "${_repo}"
412 if [ -n "${_local_index_exists}" ]; then
413 read -r _dummy _label _descr <<EOF_INDEX
414 $(pkg version -U -I -n "${_package}" -v)
415 EOF_INDEX
416 _version="$(get_immediate_index_version "${_package}")"
417 print_detail_item "INDEX" "${_version}" "${_label}" "${_descr}"
418 fi
419 for _repo in "${FREEBSD_REPO}" "${LOCALBSDPORTS_REPO}" "${SHARED_LOCAL_REPO}" "${LOCAL_REPO}"; do
420 read -r _dummy _label _descr <<EOF_REPO
421 $(pkg version -U -R -r "${_repo}" -n "${_package}" -v)
422 EOF_REPO
423 _version="$(pkg rquery -U -r "${_repo}" '%v' "${_package}")"
424 print_detail_item "${_repo}" "${_version}" "${_label}" "${_descr}"
425 done
426 _mapped_package_name="$(get_mapping "${_ipackage}")"
427 if [ -n "${_mapped_package_name}" ] ; then
428 printf '%18s %s %s (%s)\n' "--------------->" "${_mapped_package_name}" "$(pkg rquery -U '%v' "${_mapped_package_name}")" "$(pkg rquery -U '%R' "${_mapped_package_name}")"
429 if [ -n "${_local_index_exists}" ]; then
430 print_detail_item "INDEX" "$(get_immediate_index_version "${_mapped_package_name}")" "" ""
431 fi
432 for _repo in "${FREEBSD_REPO}" "${LOCALBSDPORTS_REPO}" "${SHARED_LOCAL_REPO}" "${LOCAL_REPO}"; do
433 print_detail_item "${_repo}" "$(pkg rquery -U -r "${_repo}" '%v' "${_mapped_package_name}")" "" ""
434 done
435 fi
436 fi
437 done
438 }
439
440
389 option_alldata="" 441 option_alldata=""
390 option_alldata_FreeBSD="" 442 option_alldata_FreeBSD=""
391 option_alldata_LocalBSDPorts="" 443 option_alldata_LocalBSDPorts=""
392 opeion_alldata_SharedLocalRepo="" 444 opeion_alldata_SharedLocalRepo=""
393 option_alldata_LocalRepo="" 445 option_alldata_LocalRepo=""
394 option_short="" 446 option_short=""
395 option_verbose="" 447 option_verbose=""
396 448 option_packages=""
397 while getopts "VAasv" _opt ; do 449
450 while getopts "VAansv" _opt ; do
398 case ${_opt} in 451 case ${_opt} in
399 V) 452 V)
400 printf 'check-ports v%s (rv:%s)\n' "${VERSION}" '@@HGREVISION@@' 453 printf 'check-ports v%s (rv:%s)\n' "${VERSION}" '@@HGREVISION@@'
401 exit 0 454 exit 0
402 ;; 455 ;;
410 ;; 463 ;;
411 a) 464 a)
412 # Print the data of all repos that have the package 465 # Print the data of all repos that have the package
413 option_alldata="1" 466 option_alldata="1"
414 ;; 467 ;;
468 n)
469 #
470 # Print status of given packages in all details.
471 # No other options are respected.
472 #
473 option_packages="1"
474 ;;
415 s) 475 s)
416 # "short" output: if installed from FreeBSD repo: don't 476 # "short" output: if installed from FreeBSD repo: don't
417 # report if only the index is newer 477 # report if only the index is newer
418 option_short="1" 478 option_short="1"
419 ;; 479 ;;
433 exit 2 493 exit 2
434 ;; 494 ;;
435 esac 495 esac
436 done 496 done
437 497
498 #
499 # Reset the Shell's option handling system to prepare for handling
500 # command-local options.
501 #
502 shift $((OPTIND-1))
503 OPTIND=1
504
438 if [ -n "${option_short}" -a -n "${option_alldata}" ]; then 505 if [ -n "${option_short}" -a -n "${option_alldata}" ]; then
439 echo "the -s option cannot be combined with -A or -a" >&2 506 echo "the -s option cannot be combined with -A or -a" >&2
440 exit 2 507 exit 2
441 fi 508 fi
442 509
443 check_ports 510 if [ -n "${option_packages}" ]; then
511 check_packages "$@"
512 else
513 check_ports
514 fi