Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison sbin/check-ports @ 151:27b7454140be
Determine INDEXDIR and INDEXFILE dynamically from the packager configuration via "pkg config"
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 03 Nov 2019 19:37:43 +0100 |
| parents | 937c96ffe358 |
| children | 29e708b524e1 |
comparison
equal
deleted
inserted
replaced
| 150:937c96ffe358 | 151:27b7454140be |
|---|---|
| 65 | 65 |
| 66 # | 66 # |
| 67 # For the workaround of the bug in pkg rquery -I | 67 # For the workaround of the bug in pkg rquery -I |
| 68 # | 68 # |
| 69 : ${PORTSDIR:=/usr/ports} | 69 : ${PORTSDIR:=/usr/ports} |
| 70 : ${INDEXDIR:=${PORTSDIR}} | |
| 71 : ${INDEXFILE:=@@INDEXFILE@@} | |
| 72 | 70 |
| 73 | 71 |
| 74 test_exists_local_index() { | 72 test_exists_local_index() { |
| 75 : 'Determine whether there exists a ports directory with an index | 73 : 'Determine whether there exists a ports directory with an index |
| 76 file. | 74 file. |
| 80 ' | 78 ' |
| 81 pkg version -I -n DUMMY >/dev/null 2>/dev/null | 79 pkg version -I -n DUMMY >/dev/null 2>/dev/null |
| 82 } | 80 } |
| 83 | 81 |
| 84 | 82 |
| 83 get_index_directory() { | |
| 84 : 'Ask the packager configuration for the `INDEXDIR` and/or `PORTSDIR` | |
| 85 configuration value: either `INDEXDIR` or -- if `INDEXDIR` is empty -- | |
| 86 `PORTSDIR` is used. | |
| 87 | |
| 88 Output (stdout) | |
| 89 the directory where the index database file lives | |
| 90 | |
| 91 ' | |
| 92 local _dir | |
| 93 | |
| 94 _dir="$(pkg config INDEXDIR)" | |
| 95 if [ -z "${_dir}" ]; then | |
| 96 _dir="$(pkg config PORTSDIR)" | |
| 97 fi | |
| 98 printf '%s' "${_dir}" | |
| 99 } | |
| 100 | |
| 101 | |
| 85 get_immediate_index_version() { | 102 get_immediate_index_version() { |
| 86 : 'Determine for package `_package` the version of the package in the | 103 : 'Determine for package `_package` the version of the package in the |
| 87 local ports index. | 104 local ports index. |
| 88 | 105 |
| 89 Args: | 106 Args: |
| 90 _package: the package name to search for | 107 _package: the package name to search for |
| 91 | 108 |
| 92 Input (Globals): | |
| 93 INDEXDIR: the directory where to search the index file | |
| 94 INDEXFILE: the name of the index file | |
| 95 | |
| 96 Returns: | 109 Returns: |
| 97 0 on success, 1 on errors or if the package is not in the local | 110 0 on success, 1 on errors or if the package is not in the local |
| 98 ports index | 111 ports index |
| 99 | 112 |
| 100 Output (stdout): | 113 Output (stdout): |
| 101 the version number of `_package` in the local ports index | 114 the version number of `_package` in the local ports index |
| 102 | 115 |
| 103 ' | 116 ' |
| 104 local _package _line _fqpn _n _lines | 117 local _package _line _fqpn _n _lines |
| 118 local _indexdir _indexfile | |
| 105 | 119 |
| 106 _package="$1" | 120 _package="$1" |
| 107 | 121 |
| 108 # _val=$(pkg rquery -I "${_package}" | cut -f 1 -d '|') | 122 # _val=$(pkg rquery -I "${_package}" | cut -f 1 -d '|') |
| 109 # _rv=$? | 123 # _rv=$? |
| 110 # immediate_index_version=${_val##*-} | 124 # immediate_index_version=${_val##*-} |
| 111 # return ${_rv} | 125 # return ${_rv} |
| 112 | 126 |
| 113 if [ -r "${INDEXDIR}/${INDEXFILE}" ] ; then | 127 _indexdir="$(get_index_directory)" |
| 128 _indexfile="$(pkg config INDEXFILE)" | |
| 129 | |
| 130 if [ -r "${_indexdir}/${_indexfile}" ] ; then | |
| 114 # | 131 # |
| 115 # Note: Direct piping does not set immediate_index_version at return correctly | 132 # Note: Direct piping does not set immediate_index_version at return correctly |
| 116 # "_line" is set correctly and parsing works, but the return 0 seems to kill | 133 # "_line" is set correctly and parsing works, but the return 0 seems to kill |
| 117 # some of the previous effects. | 134 # some of the previous effects. |
| 118 # | 135 # |
| 119 # "grep" does a fast pre-selection, reading, parsing and comparing is done for | 136 # "grep" does a fast pre-selection, reading, parsing and comparing is done for |
| 120 # exact matching. | 137 # exact matching. |
| 121 # | 138 # |
| 122 _lines=$(egrep '^'"${_package}" "${INDEXDIR}/${INDEXFILE}") | 139 _lines=$(egrep '^'"${_package}" "${_indexdir}/${_indexfile}") |
| 123 while read _line ; do | 140 while read _line ; do |
| 124 _fqpn="${_line%%|*}" | 141 _fqpn="${_line%%|*}" |
| 125 _n=${_fqpn%-*} | 142 _n=${_fqpn%-*} |
| 126 if [ "${_package}" = "${_n}" ] ; then | 143 if [ "${_package}" = "${_n}" ] ; then |
| 127 printf '%s' "${_fqpn##*-}" | 144 printf '%s' "${_fqpn##*-}" |
