Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
changeset 140:17b2f4fa9c1b
- Refactor: check-ports now deals with missing local index files
- Handle a "SharedLocalRepo" repository
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 30 Oct 2019 09:40:42 +0100 |
| parents | 302225cfb01b |
| children | 00a17d4b6dfe |
| files | sbin/check-ports |
| diffstat | 1 files changed, 223 insertions(+), 295 deletions(-) [+] |
line wrap: on
line diff
--- a/sbin/check-ports Fri Oct 25 09:25:05 2019 +0200 +++ b/sbin/check-ports Wed Oct 30 09:40:42 2019 +0100 @@ -1,7 +1,7 @@ #!/bin/sh # -*- indent-tabs-mode: nil; -*- : 'Check the version status of installed ports and compare them to -repository versions. +version in remote repositories and the local ports index. :Author: Franz Glasner :Copyright: (c) 2017-2019 Franz Glasner. @@ -71,120 +71,16 @@ : ${INDEXFILE:=@@INDEXFILE@@} -get_remote_repo_versions() { - : 'Determine the remote repository versions of all packages in - repository `_repo`. - - Args: - _repo: the name of the repote repository - - Returns: - status 0 on success, 1 on errors - - Output (Globals): - remote_versions_${_repo}: the versions of all packages in `_repo` and - their extended version status with respect to - locally installed packages - - ' - local _repo _data _rv - - _repo=$1 - - _data=$(pkg version -U -R -r ${_repo} -v) - _rv=$? - eval remote_versions_${_repo}=\"\${_data}\" - return ${_rv} -} - -get_remote_repo_data() { - : 'Get the extended package version information from the remote repository - `_repo` for package `_name`. - - Args: - _repo: the name of the remote repository - _name: the package name - - Input (Globals): - remote_versions_${_repo}: the extended version info for *all* packages - in repo `_repo`. +test_exists_local_index() { + : 'Determine whether there exists a ports directory with an index + file. Returns: - status 0 on success, 1 on errors or if the package is not found - in the remote repository - - Output (Globals): - remote_label_${_repo}: - remote_descr_${_repo}: - + status 0 iff the local index exists ' - local _repo _name _rversions _rfqp _rl _rdescr - - _repo=$1 - _name=$2 - - eval _rversions=\"\${remote_versions_${_repo}}\" - while read _rfqp _rl _rdescr ; do - if [ "${_rfqp%-*}" = "${_name}" ] ; then - eval remote_label_${_repo}=\"\${_rl}\" - eval remote_descr_${_repo}=\"\${_rdescr}\" - return 0 - fi - done <<EOF884657 -${_rversions} -EOF884657 - eval remote_label_${_repo}="" - eval remote_descr_${_repo}="" - return 1 + pkg version -I -n DUMMY >/dev/null 2>/dev/null } -get_local_index_versions() { - : 'Determine the extendes versions of all packages in the local index - (ports). - - Returns: - status 0 on success or 1 on errors - - Output (Globals): - local_index_versions: - - ' - local_index_versions=$(pkg version -I -v) -} - -get_repo_for_installed_package() { - : 'Determine for a package `_name` from which repository is has been - installed. - - Args: - _name: the name of the package to search for - - Input (Globals): - installed_data the output of ``pkg query "%n %v %R"`` of all - installed packages - - Returns: - 0 on success, 1 on errors or if the package is not installed - - Output (Globals): - repository: the repository from which the installed packages `_name` - has been installed - - ' - local _name _n _v _r - - _name=$1 - - while read _n _v _r ; do - if [ "${_name}" = "${_n}" ] ; then - repository=${_r} - return 0 - fi - done <<EOF223777 -${installed_data} -EOF223777 - return 1 -} get_immediate_index_version() { : 'Determine for package `_package` the version of the package in the @@ -198,21 +94,21 @@ INDEXFILE: the name of the index file Returns: - 0 on success, 1 on errors or if the package is not in the index + 0 on success, 1 on errors or if the package is not in the local + ports index - Output (Globals): - immediate_index_version: the version number of `_package` in the - index + Output (stdout): + the version number of `_package` in the local ports index ' local _package _line _fqpn _n _lines - _package=$1 + _package="$1" # _val=$(pkg rquery -I "${_package}" | cut -f 1 -d '|') # _rv=$? # immediate_index_version=${_val##*-} -# return ${_rv} + # return ${_rv} if [ -r "${INDEXDIR}/${INDEXFILE}" ] ; then # @@ -228,80 +124,16 @@ _fqpn="${_line%%|*}" _n=${_fqpn%-*} if [ "${_package}" = "${_n}" ] ; then - immediate_index_version="${_fqpn##*-}" + printf '%s' "${_fqpn##*-}" return 0 fi done <<EOF1334TGH1 ${_lines} EOF1334TGH1 fi - - immediate_index_version="" return 1 } -get_immediate_remote_repo_version() { - : 'Ask a remote repository for the version of a package. - - Args: - _repo: the repository name - _name: the name of the package - - Returns: - 0 on success and other status codes otherwise - - Output (Globals): - immediate_remote_repo_version_${_repo}: the version of package `_name` - in repo `_repo` - - ' - local _repo _name _version _rv - - _repo=$1 - _name=$2 - - _version=$(pkg rquery -U -r "${_repo}" '%v' "${_name}") - _rv=$? - eval immediate_remote_repo_version_${_repo}=\"\${_version}\" - return ${_rv} -} - -assert_local_version() { - : 'Check whether an installed package `_name` has given - version `_version`. - - Args: - _name: the package name - _version: the version to check for - - Input (Globals): - installed_data: the output of ``pkg query "%n %v %R"`` of all - installed packages - - Returns: - - 0 if the installed version of package `_name` is equal to `_version` - - 1 if the installed version of package `_name` differs from `_version` - - 2 on other errors - - ' - local _name _version _n _v _r - - _name=$1 - _version=$2 - - while read _n _v _r ; do - if [ "${_name}" = "${_n}" ] ; then - if [ "${_version}" != "${_v}" ] ; then - return 1 - else - return 0 - fi - fi - done <<EOF223 -${installed_data} -EOF223 - return 2 -} get_mapping() { : 'Determine whether a package `_package` is essentially the same as @@ -313,9 +145,8 @@ Returns: 0 when a package mapping has been found, 1 otherwise - Output (Globals): - mapped_package_name: the name of the package on which `_package` is - based on + Output (stdout): + the name of the package on which `_package` is based on This command reads from the mapping database in in file `/usr/local/etc/local-bsdtools/package-mapping.conf`. @@ -330,25 +161,26 @@ ' local _package _n _mapped - _package=$1 + _package="$1" if [ -r "${PACKAGE_MAPPING}" ] ; then while read _n _mapped ; do if [ "${_n}" = "${_package}" ] ; then - mapped_package_name="${_mapped}" + printf '%s' "${_mapped}" return 0 fi done < ${PACKAGE_MAPPING} fi - mapped_package_name="" return 1 } + print_title() { : 'Print the output title line for a package Args: _package: the package name + _version: the package version _repo: the repository name Input (Globals). @@ -363,22 +195,204 @@ title_printed: set to "yes" if the title has been printed ' - local _package _repo + local _package _version _repo - _package=$1 - _repo=$2 - if [ -z "${title_printed}" ] ; then - echo "${_package} (${_repo})" + _package="$1" + _version="$2" + _repo="$3" + if [ -z "${title_printed}" ]; then + printf '%-36s %-17s (%s)\n' "${_package}" "${_version}" "${_repo}" title_printed=yes fi } -alldata_flag="" -alldata_flag_LocalBSDPorts="" -alldata_flag_LocalRepo="" -short_flag="" -verbose_flag="" +print_detail_item() { + : 'Print a detail item to stdout. + + The description `_descr` will not be printed if the label `_label` + is ``?``. + + Args: + _repo: the repository name + _version: the version number to print to + _label: the label (aka comparison character) to print to + _descr: the description to print to + _indent: (optional) extra indentation number (default 0) + + Output (stdout): + the formatted detail line + + ' + local _repo _version _label _descr _indent + local _real_descr + + _repo="$1" + _version="$2" + _label="$3" + _descr="$4" + _indent="$5" + + if [ -z "${_indent}" ]; then + _indent="0" + fi + if [ "${_label}" = '?' ]; then + _real_descr='' + else + _real_descr="${_descr}" + fi + + printf '%-*s %-15s: %-17s %s %s\n' $((_indent)) '' "${_repo}" "${_version}" "${_label}" "${_real_descr}" +} + + +check_ports() { + : 'Implementation of main + + ' + local _ipackage _iversion _irepo _mapped_package_name _dummy + local _print_detail _local_index_exists + local _index_version _index_label _index_descr + local _remote_version_FreeBSD _remote_label_FreeBSD _remote_descr_FreeBSD + local _remote_version_LocalBSDPorts _remote_label_LocalBSDPorts _remote_descr_LocalBSDPorts + local _remote_version_SharedLocalRepo _remote_label_SharedLocalRepo _remote_descr_SharedLocalRepo + local _remote_version_LocalRepo _remote_label_LocalRepo _remote_descr_LocalRepo + + if test_exists_local_index; then + _local_index_exists="1" + fi + pkg query '%n %v %R' | + while read -r _ipackage _iversion _irepo; do + title_printed="" + _print_detail="" + if [ -n "${_local_index_exists}" ]; then + read -r _dummy _index_label _index_descr <<EOF_INDEX +$(pkg version -U -I -n "${_ipackage}" -v) +EOF_INDEX + fi + read -r _dummy _remote_label_FreeBSD _remote_descr_FreeBSD <<EOF_FreeBSD +$(pkg version -U -R -r "${FREEBSD_REPO}" -n "${_ipackage}" -v) +EOF_FreeBSD + read -r _dummy _remote_label_LocalBSDPorts _remote_descr_LocalBSDPorts <<EOF_LocalBSDPorts +$(pkg version -U -R -r "${LOCALBSDPORTS_REPO}" -n "${_ipackage}" -v) +EOF_LocalBSDPorts + read -r _remote_fpname_SharedLocalRepo _remote_label_SharedLocalRepo _remote_descr_SharedLocalRepo <<EOF_SharedLocalRepo +$(pkg version -U -R -r "${SHARED_LOCAL_REPO}" -n "${_ipackage}" -v) +EOF_SharedLocalRepo + read -r _remote_fpname_LocalRepo _remote_label_LocalRepo _remote_descr_LocalRepo <<EOF_LocalRepo +$(pkg version -U -R -r "${LOCAL_REPO}" -n "${_ipackage}" -v) +EOF_LocalRepo + + if [ -n "${option_verbose}" ]; then + print_title "${_ipackage}" "${_iversion}" "${_irepo}" + fi + if get_mapping "${_ipackage}" >/dev/null; then + _print_detail="1" + fi + if [ -n "${option_alldata}" ]; then + _print_detail="1" + else + if [ -n "${option_short}" ]; then + case "${_irepo}" in + "${FREEBSD_REPO}") + if [ -n "${_local_index_exists}" ]; then + if [ "${_index_label}" != '<' -a "${_index_label}" != '=' ]; then + _print_detail=1 + fi + fi + if [ "${_remote_label_FreeBSD}" != '=' -o "${_remote_label_SharedLocalRepo}" != '?' -o "${_remote_label_LocalRepo}" != '?' -o "${_remote_label_LocalBSDPorts}" != '?' ]; then + _print_detail=1 + fi + ;; + "${LOCALBSDPORTS_REPO}") + if [ -n "${_local_index_exists}" ]; then + if [ "${_index_label}" != '=' ]; then + _print_detail=1 + fi + fi + if [ "${_remote_label_FreeBSD}" != '>' -o "${_remote_label_LocalRepo}" != '?' -o "${_remote_label_SharedLocalRepo}" != '?' -o "${_remote_label_LocalBSDPorts}" = '?' -o "${_remote_label_LocalBSDPorts}" = '<' ]; then + _print_detail=1 + fi + ;; + "${SHARED_LOCAL_REPO}") + _print_detail=1 + ;; + "${LOCAL_REPO}") + _print_detail=1 + ;; + "${PORTS_DIRECT_INSTALLED_REPO}") + _print_detail=1 + ;; + *) + echo "ERROR: unhandled repository: ${_irepo}" >&2 + exit 1 + ;; + esac + else + if [ -n "${_local_index_exists}" ]; then + if [ "${_index_label}" != '?' -a "${_index_label}" != '=' ]; then + _print_detail=1 + fi + fi + if [ "${_remote_label_FreeBSD}" != '?' -a "${_remote_label_FreeBSD}" != '=' ]; then + _print_detail=1 + fi + if [ "${_remote_label_LocalBSDPorts}" != '?' -a "${_remote_label_LocalBSDPorts}" != '=' ]; then + _print_detail=1 + fi + if [ "${_remote_label_SharedLocalRepo}" != '?' -a "${_remote_label_SharedLocalRepo}" != '=' ]; then + _print_detail=1 + fi + if [ "${_remote_label_LocalRepo}" != '?' -a "${_remote_label_LocalRepo}" != '=' ]; then + _print_detail=1 + fi + fi + fi + if [ -n "${_print_detail}" ]; then + print_title "${_ipackage}" "${_iversion}" "${_irepo}" + if [ -n "${_local_index_exists}" ]; then + _index_version="$(get_immediate_index_version "${_ipackage}")" + print_detail_item "INDEX" "${_index_version}" "${_index_label}" "${_index_descr}" + fi + if [ -n "${option_alldata_FreeBSD}" -o "${_remote_label_FreeBSD}" != '?' ]; then + _remote_version_FreeBSD="$(pkg rquery -U -r "${FREEBSD_REPO}" '%v' "${_ipackage}")" + print_detail_item "${FREEBSD_REPO}" "${_remote_version_FreeBSD}" "${_remote_label_FreeBSD}" "${_remote_descr_FreeBSD}" + fi + if [ -n "${option_alldata_LocalBSDPorts}" -o "${_remote_label_LocalBSDPorts}" != '?' ]; then + _remote_version_LocalBSDPorts="$(pkg rquery -U -r "${LOCALBSDPORTS_REPO}" '%v' "${_ipackage}")" + print_detail_item "${LOCALBSDPORTS_REPO}" "${_remote_version_LocalBSDPorts}" "${_remote_label_LocalBSDPorts}" "${_remote_descr_LocalBSDPorts}" + fi + if [ -n "${option_alldata_SharedLocalRepo}" -o "${_remote_label_SharedLocalRepo}" != '?' ]; then + _remote_version_SharedLocalRepo="$(pkg rquery -U -r "${SHARED_LOCAL_REPO}" '%v' "${_ipackage}")" + print_detail_item "${SHARED_LOCAL_REPO}" "${_remote_version_SharedLocalRepo}" "${_remote_label_SharedLocalRepo}" "${_remote_descr_SharedLocalRepo}" + fi + if [ -n "${option_alldata_LocalRepo}" -o "${_remote_label_LocalRepo}" != '?' ]; then + _remote_version_LocalRepo="$(pkg rquery -U -r "${LOCAL_REPO}" '%v' "${_ipackage}")" + print_detail_item "${LOCAL_REPO}" "${_remote_version_LocalRepo}" "${_remote_label_LocalRepo}" "${_remote_descr_LocalRepo}" + fi + _mapped_package_name="$(get_mapping "${_ipackage}")" + if [ -n "${_mapped_package_name}" ] ; then + printf '%18s %s %s (%s)\n' "--------------->" "${_mapped_package_name}" "$(pkg rquery -U '%v' "${_mapped_package_name}")" "$(pkg rquery -U '%R' "${_mapped_package_name}")" + if [ -n "${_local_index_exists}" ]; then + print_detail_item "INDEX" "$(get_immediate_index_version "${_mapped_package_name}")" "" "" + fi + print_detail_item "${FREEBSD_REPO}" "$(pkg rquery -U -r "${FREEBSD_REPO}" '%v' "${_mapped_package_name}")" "" "" + print_detail_item "${LOCALBSDPORTS_REPO}" "$(pkg rquery -U -r "${LOCALBSDPORTS_REPO}" '%v' "${_mapped_package_name}")" "" "" + print_detail_item "${SHARED_LOCAL_REPO}" "$(pkg rquery -U -r "${SHARED_LOCAL_REPO}" '%v' "${_mapped_package_name}")" "" "" + print_detail_item "${LOCAL_REPO}" "$(pkg rquery -U -r "${LOCAL_REPO}" '%v' "${_mapped_package_name}")" "" "" + fi + fi + done +} + + +option_alldata="" +option_alldata_FreeBSD="" +option_alldata_LocalBSDPorts="" +opeion_alldata_SharedLocalRepo="" +option_alldata_LocalRepo="" +option_short="" +option_verbose="" while getopts "VAasv" _opt ; do case ${_opt} in @@ -388,26 +402,28 @@ ;; A) # Print for every package the status of all repositories - alldata_flag=1 - alldata_flag_LocalBSDPorts=1 - alldata_flag_LocalRepo=1 + option_alldata="1" + option_alldata_FreeBSD="1" + option_alldata_LocalBSDPorts="1" + option_alldata_SharedLocalRepo="1" + option_alldata_LocalRepo="1" ;; a) # Print the data of all repos that have the package - alldata_flag=1 + option_alldata="1" ;; s) # "short" output: if installed from FreeBSD repo: don't # report if only the index is newer - short_flag=1 + option_short="1" ;; v) # # Print all titles and repo of every installed package always. - # The output of the repo status nevertheless depends on the + # The output of the other repo status nevertheless depends on the # other flag settings. - # - verbose_flag=1 + # + option_verbose="1" ;; \?) exit 2 @@ -419,97 +435,9 @@ esac done -if [ -n "${short_flag}" -a -n "${alldata_flag}" ]; then +if [ -n "${option_short}" -a -n "${option_alldata}" ]; then echo "the -s option cannot be combined with -A or -a" >&2 exit 2 fi -installed_packages=$(pkg query '%n') -installed_data="$(pkg query '%n %v %R' $installed_packages)" - -get_remote_repo_versions ${LOCAL_REPO} -get_remote_repo_versions ${LOCALBSDPORTS_REPO} -get_remote_repo_versions ${FREEBSD_REPO} -get_local_index_versions - -while read lfqp llabel ldescr ; do - _installed_name=${lfqp%-*} - _installed_version=${lfqp##*-} - title_printed="" - get_repo_for_installed_package ${_installed_name} - get_mapping ${_installed_name} - if [ -n "${verbose_flag}" ] ; then - print_title "${lfqp}" "${repository}" - fi - if ! assert_local_version ${_installed_name} ${_installed_version} ; then - echo "Assertion failed: $lfqp ${_installed_name} ${_installed_version} ${llabel}" >&2 - exit 1 - fi - get_remote_repo_data ${LOCAL_REPO} ${_installed_name} - get_remote_repo_data ${LOCALBSDPORTS_REPO} ${_installed_name} - get_remote_repo_data ${FREEBSD_REPO} ${_installed_name} - _print_detail="" - if [ -n "${mapped_package_name}" ] ; then - _print_detail=1 - fi - if [ -n "${alldata_flag}" ]; then - _print_detail=1 - else - if [ -n "${short_flag}" ]; then - # - # NOTE: -s and -A/-a are incompatible: so "alldata_XXX" needs not - # to be checked! - # - case "${repository}" in - "${FREEBSD_REPO}") - if [ \( "${llabel}" != '<' -a "${llabel}" != '=' \) -o "${remote_label_FreeBSD}" != '=' -o "${remote_label_LocalRepo}" != '?' -o "${remote_label_LocalBSDPorts}" != '?' ]; then - _print_detail=1 - fi - ;; - "${LOCAL_REPO}") - _print_detail=1 - ;; - "${LOCALBSDPORTS_REPO}") - if [ "${llabel}" != '=' -o "${remote_label_FreeBSD}" != '>' -o "${remote_label_LocalRepo}" != '?' -o "${remote_label_LocalBSDPorts}" = '?' -o "${remote_label_LocalBSDPorts}" = '<' ]; then - _print_detail=1 - fi - ;; - "${PORTS_DIRECT_INSTALLED_REPO}") - _print_detail=1 - ;; - *) - echo "ERROR: unhandled repository: ${repository}" >&2 - exit 1 - ;; - esac - else - if [ \( \( "${llabel}" != '?' -a "${llabel}" != '=' \) -o \( "${remote_label_FreeBSD}" != '?' -a "${remote_label_FreeBSD}" != '=' \) -o \( "${remote_label_LocalBSDPorts}" != '?' -a "${remote_label_LocalBSDPorts}" != '=' \) -o \( "${remote_label_LocalRepo}" != '?' -a "${remote_label_LocalRepo}" != '=' \) \) -o \( "${repository}" = "${PORTS_DIRECT_INSTALLED_REPO}" \) ]; then - _print_detail=1 - fi - fi - fi - if [ -n "${_print_detail}" ]; then - print_title "${lfqp}" "${repository}" - echo " INDEX : ${llabel} ${ldescr}" - echo " FreeBSD : ${remote_label_FreeBSD} ${remote_descr_FreeBSD}" - if [ \( -n "${alldata_flag_LocalBSDPorts}" \) -o \( "${remote_label_LocalBSDPorts}" != '?' \) ] ; then - echo " LocalBSDPorts: ${remote_label_LocalBSDPorts} ${remote_descr_LocalBSDPorts}" - fi - if [ \( -n "${alldata_flag_LocalRepo}" \) -o \( "${remote_label_LocalRepo}" != '?' \) ] ; then - echo " LocalRepo : ${remote_label_LocalRepo} ${remote_descr_LocalRepo}" - fi - if [ -n "${mapped_package_name}" ] ; then - echo " ---> ${mapped_package_name}" - get_immediate_index_version "${mapped_package_name}" - get_immediate_remote_repo_version ${LOCAL_REPO} ${mapped_package_name} - get_immediate_remote_repo_version ${LOCALBSDPORTS_REPO} ${mapped_package_name} - get_immediate_remote_repo_version ${FREEBSD_REPO} ${mapped_package_name} - echo " INDEX : ${immediate_index_version}" - echo " FreeBSD : ${immediate_remote_repo_version_FreeBSD}" - echo " LocalBSDPorts: ${immediate_remote_repo_version_LocalBSDPorts}" - echo " LocalRepo : ${immediate_remote_repo_version_LocalRepo}" - fi - fi -done <<EOF856661111299999 -${local_index_versions} -EOF856661111299999 +check_ports
