From ce980151c4ac0e0e74272101fcc791b46f30fc98 Mon Sep 17 00:00:00 2001 From: Mamoru Sakaue / MwGhennndo Date: Tue, 31 Jul 2012 06:08:07 +0900 Subject: [PATCH] Some bugs are fixed. modified: portsreinstall modified: portsreinstall.8 modified: portsreinstall.8~ modified: portsreinstall~ --- portsreinstall | 202 +++++++++++++++++++++++++++++++++++++----------------- portsreinstall.8 | 6 +- portsreinstall.8~ | 6 +- portsreinstall~ | 202 +++++++++++++++++++++++++++++++++++++----------------- 4 files changed, 284 insertions(+), 132 deletions(-) diff --git a/portsreinstall b/portsreinstall index 34c888b..b787b0f 100755 --- a/portsreinstall +++ b/portsreinstall @@ -10,7 +10,7 @@ # ================================================ APPNAME=`basename $0` -MYVERSION=1.1.0+toward_1.2.0_20120729234736 +MYVERSION=1.1.0+toward_1.2.0_20120731060658 PREFIX=${PREFIX:-/usr/local} CONFFILE=${PREFIX}/etc/${APPNAME}.conf @@ -521,9 +521,10 @@ register_globs () globlist1=$1 globlist2=$2 listpath=$3 - mode=$3 + mode=$4 dirpath=`dirname "$listpath"` - for glob in `echo $globlist1 | sed 's/,/ /g'` $globlist2 + echo "`echo "$globlist1" | sed 's/,/ /g'`" "$globlist2" | sed -E 's/ +/\ +/g' | grep -v '^$' | while read glob do if expr "@$glob" : '^@[^/][^/]*/[^/][^/]*$' > /dev/null 2> /dev/null then @@ -688,17 +689,19 @@ inspect_dependencies () pkg=`pkg_info -qO "$origin"` if [ -n "$pkg" ] then - $target_dir=${DBDIR}/initial/$origin + target_dir=${DBDIR}/initial/$origin [ -d "$target_dir" ] || mkdir -p "$target_dir" echo $pkg > $target_dir/installed_version pkg_info -qr "$pkg" | grep '^@pkgdep ' | sed 's/^@pkgdep[[:space:]]*//' | while read requirement do - pkg_info -o "$requirement" - done > $target_dir/requires + pkg_info -e "$requirement" || continue + pkg_info -qo "$requirement" >> $target_dir/requires + done pkg_info -qR "$pkg" | grep -v '^$' | while read dependent do - pkg_info -o "$dependent" - done > $target_dir/dependents + pkg_info -e "$dependent" || continue + pkg_info -qo "$dependent" >> $target_dir/dependents + done fi origin_src= if [ `echo $origin | grep -m 1 -E -f "${DBDIR}/REPLACE.grep_from_pattern.conflist" | wc -l` -eq 1 ] @@ -853,65 +856,55 @@ chk_if_target () local prefix _is_all _is_target _is_required _is_former_required _is_dependent _is_former_dependent _is_relevant prefix=$1 origin=$2 - _is_all=y - _is_target= - _is_required= - _is_former_required= - _is_dependent= - _is_former_dependent= - _is_relevant=y - if [ `cat "${DBDIR}/target_required_ports.specified" 2> /dev/null | wc -l` -gt 0 ] + if [ -e "${DBDIR}/requires/$origin/chk_if_target.param" ] then - _is_all= - if [ ! -f "${DBDIR}/requires/$origin/dependents.pattern" ] - then - str_escape_regexp_filter < "${DBDIR}/requires/$origin/dependents" | sed 's/^/^/;s/$/$/' > "${DBDIR}/requires/$origin/dependents.pattern" 2> /dev/null || : - fi - if [ -e "${DBDIR}/initial/$origin/dependents" -a ! -f "${DBDIR}/initial/$origin/dependents.pattern" ] - then - str_escape_regexp_filter < "${DBDIR}/initial/$origin/dependents" | sed 's/^/^/;s/$/$/' > "${DBDIR}/initial/$origin/dependents.pattern" 2> /dev/null || : - fi - if grep -m 1 -E "^`str_escape_regexp $origin`$" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null - then - _is_target=y - elif grep -m 1 -E -f "${DBDIR}/requires/$origin/dependents.pattern" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null - then - _is_required=y - elif [ -e "${DBDIR}/initial/$origin/dependents.pattern" ] + . "${DBDIR}/requires/$origin/chk_if_target.param" + else + _is_all=y + _is_target= + _is_required= + _is_former_required= + _is_dependent= + _is_former_dependent= + _is_relevant=y + if [ `cat "${DBDIR}/target_required_ports.specified" 2> /dev/null | wc -l` -gt 0 ] then - if grep -m 1 -E -f "${DBDIR}/initial/$origin/dependents.pattern" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null + _is_all= + if grep -m 1 -E "^`str_escape_regexp $origin`$" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null + then + _is_target=y + elif [ -e "${DBDIR}/requires/$origin/dependents.pattern" ] && grep -m 1 -E -f "${DBDIR}/requires/$origin/dependents.pattern" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null + then + _is_required=y + elif [ -e "${DBDIR}/initial/$origin/dependents.pattern" ] && grep -m 1 -E -f "${DBDIR}/initial/$origin/dependents.pattern" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null then _is_former_required=y fi fi - fi - if [ `cat "${DBDIR}/target_dependent_ports.specified" 2> /dev/null | wc -l` -gt 0 ] - then - _is_all= - if [ ! -f "${DBDIR}/requires/$origin/requires.pattern" ] - then - str_escape_regexp_filter < "${DBDIR}/requires/$origin/requires" | sed 's/^/^/;s/$/$/' > "${DBDIR}/requires/$origin/requires.pattern" 2> /dev/null || : - fi - if [ -e "${DBDIR}/initial/$origin/requires" -a ! -f "${DBDIR}/initial/$origin/requires.pattern" ] - then - str_escape_regexp_filter < "${DBDIR}/initial/$origin/requires" | sed 's/^/^/;s/$/$/' > "${DBDIR}/initial/$origin/requires.pattern" 2> /dev/null || : - fi - if [ -n "${_is_target}" ] || grep -m 1 -E "^`str_escape_regexp $origin`$" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null - then - _is_target=y - elif grep -m 1 -E -f "${DBDIR}/requires/$origin/requires.pattern" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null + if [ `cat "${DBDIR}/target_dependent_ports.specified" 2> /dev/null | wc -l` -gt 0 ] then - _is_dependent=y - fi - elif [ -e "${DBDIR}/initial/$origin/requires.pattern" ] - then - if grep -m 1 -E -f "${DBDIR}/initial/$origin/requires.pattern" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null + _is_all= + if [ -n "${_is_target}" ] || grep -m 1 -E "^`str_escape_regexp $origin`$" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null + then + _is_target=y + elif [ -e "${DBDIR}/requires/$origin/requires.pattern" ] && grep -m 1 -E -f "${DBDIR}/requires/$origin/requires.pattern" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null + then + _is_dependent=y + elif [ -e "${DBDIR}/initial/$origin/requires.pattern" ] && grep -m 1 -E -f "${DBDIR}/initial/$origin/requires.pattern" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null then _is_former_dependent=y fi fi + [ -n "${_is_all}${_is_target}${_is_required}${_is_former_required}${_is_dependent}${_is_former_dependent}" ] || _is_relevant= + echo _is_all=${_is_all} > ${TMPDIR}/chk_if_target:results + echo _is_target=${_is_target} >> ${TMPDIR}/chk_if_target:results + echo _is_required=${_is_required} >> ${TMPDIR}/chk_if_target:results + echo _is_former_required=${_is_former_required} >> ${TMPDIR}/chk_if_target:results + echo _is_dependent=${_is_dependent} >> ${TMPDIR}/chk_if_target:results + echo _is_former_dependent=${_is_former_dependent} >> ${TMPDIR}/chk_if_target:results + echo _is_relevant=${_is_relevant} >> ${TMPDIR}/chk_if_target:results + mv "${TMPDIR}"/chk_if_target:results "${DBDIR}/requires/$origin/chk_if_target.param" fi - [ -n "${_is_all}${_is_target}${_is_required}${_is_former_required}${_is_dependent}${_is_former_dependent}" ] || _is_relevant= eval ${prefix}_is_all=\$\{_is_all\} eval ${prefix}_is_target=\$\{_is_target\} eval ${prefix}_is_required=\$\{_is_required\} @@ -921,6 +914,21 @@ chk_if_target () eval ${prefix}_is_relevant=\$\{_is_relevant\} } +register_globs_only_installed () +{ + local src1 src2 + src1=$1 + src2=$2 + rm -f "${TMPDIR}/register_globs_only_installed:origins" + register_globs "$src1" "$src2" "${TMPDIR}/register_globs_only_installed:origins" + [ -e "${TMPDIR}/register_globs_only_installed:origins" ] || return 0 + while read origin + do + [ -z `pkg_info -qO "$origin"` ] || echo $origin + done < ${TMPDIR}/register_globs_only_installed:origins +} + + # ================================================== # ==================== MAIN ======================== # ================================================== @@ -1050,7 +1058,7 @@ load) exit ;; show) - [ -d "${DBDIR}" ] || { echo "ERROR: Database has not built yet." >&2; exit 1; } + [ -e "${DBDIR}/COMPLETE_PREPARATION" ] || { echo "ERROR: Database has not built yet." >&2; exit 1; } warn_update_ports _filter_skip_unchanged= _filter_only_target= @@ -1097,12 +1105,13 @@ show) _filter_only_target=y ;; requirements) + grandtitle="Dependencies based on the latest ports tree" title="The following ports are required by %s:" list=requires _for_each_matching_port=y ;; dependents) - + grandtitle="Dependencies based on the latest ports tree" title="The following ports depend on %s:" list=dependents _for_each_matching_port=y @@ -1112,19 +1121,21 @@ show) exit 1 ;; esac - [ -r "${DBDIR}/$list" ] || exit 0 + [ -n "${_for_each_matching_port}" -o -r "${DBDIR}/$list" ] || exit 0 [ -e "${DBDIR}"/saved_options.sh ] && . "${DBDIR}"/saved_options.sh if [ -n "${_for_each_matching_port}" ] then shift [ $# -gt 0 ] || { echo "ERROR: the argument as port glob is missing" >&2; exit 1; } + echo "[$grandtitle]" + echo isfirst=y for origin_target in `ports_glob "$@"` do + [ -e "${DBDIR}/requires/$origin_target/pkgtag" ] || continue [ "$isfirst" = y ] || echo isfirst=n - [ -e "${DBDIR}/requires/$origin_target/pkgtag" ] || { echo "WARNING: the database for $origin_target is not ready" >&2; continue; } - pkg_target=`cat "${DBDIR}/$pkgnamedb/$origin/pkgtag"` + pkg_target=`cat "${DBDIR}/$pkgnamedb/$origin_target/pkgtag"` printf "$title\n" "$origin_target ($pkg_target)" [ -e "${DBDIR}/requires/$origin_target/$list" ] || continue while read origin @@ -1345,8 +1356,38 @@ fi if [ ! -e "${DBDIR}/COMPLETE_PARSE_OPTION_TARGET_PORTS" ] then rm -f "${DBDIR}/target_dependent_ports.specified" "${DBDIR}/target_required_ports.specified" - register_globs "$target_dependent_ports" "$target_dependent_ports_form2" "${DBDIR}/target_dependent_ports.specified" - register_globs "$target_required_ports" "$target_required_ports_form2" "${DBDIR}/target_required_ports.specified" + register_globs_only_installed "$target_dependent_ports" "$target_dependent_ports_form2" > ${DBDIR}/target_dependent_ports.specified + register_globs_only_installed "$target_required_ports" "$target_required_ports_form2" > ${DBDIR}/target_required_ports.specified + if [ `cat "${DBDIR}"/target_dependent_ports.specified | wc -l` -gt 0 -a `cat "${DBDIR}"/target_required_ports.specified | wc -l` -gt 0 ] + then + echo "INFO: Ports/packages irrelevant to" + echo "----------------------------------------" + cat "${DBDIR}"/target_dependent_ports.specified + echo "----------------------------------------" + echo "nor their dependents, and irrelevant to" + echo "----------------------------------------" + cat "${DBDIR}"/target_required_ports.specified + echo "----------------------------------------" + echo "nor their requirements are skipped." + elif [ `cat "${DBDIR}"/target_dependent_ports.specified | wc -l` -gt 0 ] + then + echo "INFO: Ports/packages irrelevant to" + echo "----------------------------------------" + cat "${DBDIR}"/target_dependent_ports.specified + echo "----------------------------------------" + echo "nor their dependents are skipped." + elif [ `cat "${DBDIR}"/target_required_ports.specified | wc -l` -gt 0 ] + then + echo "INFO: Ports/packages irrelevant to" + echo "----------------------------------------" + cat "${DBDIR}"/target_required_ports.specified + echo "----------------------------------------" + echo "nor their requirements are skipped." + elif [ -n "$target_dependent_ports$target_dependent_ports_form2$target_required_ports$target_required_ports_form2" ] + then + echo "ERROR: Target ports are specified but none of them is valid." >&2 + exit 1 + fi touch "${DBDIR}/COMPLETE_PARSE_OPTION_TARGET_PORTS" fi @@ -1512,7 +1553,9 @@ rm -f "${DBDIR}/REQUIRE_CHK_NEW_TARGET" # Inspection of all dependencies if [ ! -e "${DBDIR}/COMPLETE_COLLECED_ALL_DEPENDENCIES" ] then - echo "Starting to inspect dependencies of installed packages at `timestamp`" + echo "Starting to inspect dependencies of the all installed packages at `timestamp`" + [ -z "$target_dependent_ports$target_dependent_ports_form2$target_required_ports$target_required_ports_form2" ] || \ + echo "INFO: Ports irrelevant to the targets are also inspected in order to get complete information." [ -d "${DBDIR}/requires" ] || mkdir -p "${DBDIR}/requires" touch "${DBDIR}/moved_or_lost.list" touch "${DBDIR}/target.inspected.list" @@ -1597,6 +1640,34 @@ then echo fi +# Preparation of matching patterns of dependencies +if [ ! -e "${DBDIR}/COMPLETE_PREPARATION_OF_MATCHING_PATTERNS_OF_DEPENDENCIES" ] +then + echo "Starting preparation of matching patterns of dependencies at `timestamp`" + if [ -f "${DBDIR}/prepare_matching_patterns_dependencies.remain" ] + then + echo "INFO: Restarting from the previously terminated point" + else + find "${DBDIR}/requires" -depth 2 -type d > ${DBDIR}/prepare_matching_patterns_dependencies.remain + fi + cp "${DBDIR}/prepare_matching_patterns_dependencies.remain" "${DBDIR}/prepare_matching_patterns_dependencies" + while read dbpath + do + portname=`basename "$dbpath"` + catpath=`dirname "$dbpath"` + catname=`basename "$catpath"` + origin=$catname/$portname + [ ! -e "${DBDIR}/requires/$origin/dependents" ] || str_escape_regexp_filter < ${DBDIR}/requires/$origin/dependents | sed 's/^/^/;s/$/$/' > ${DBDIR}/requires/$origin/dependents.pattern + [ ! -e "${DBDIR}/initial/$origin/dependents" ] || str_escape_regexp_filter < ${DBDIR}/initial/$origin/dependents | sed 's/^/^/;s/$/$/' > ${DBDIR}/initial/$origin/dependents.pattern + [ ! -e "${DBDIR}/requires/$origin/requires" ] || str_escape_regexp_filter < ${DBDIR}/requires/$origin/requires | sed 's/^/^/;s/$/$/' > ${DBDIR}/requires/$origin/requires.pattern + [ ! -e "${DBDIR}/initial/$origin/requires" ] || str_escape_regexp_filter < ${DBDIR}/initial/$origin/requires | sed 's/^/^/;s/$/$/' > ${DBDIR}/initial/$origin/requires.pattern + chk_if_target currentorigin "$origin" + sed -i '' 1d "${DBDIR}/prepare_matching_patterns_dependencies.remain" + done < ${DBDIR}/prepare_matching_patterns_dependencies + touch "${DBDIR}/COMPLETE_PREPARATION_OF_MATCHING_PATTERNS_OF_DEPENDENCIES" + echo +fi + # Inspection of necessary updates if [ ! -e "${DBDIR}/COMPLETE_NECESSARY_UPDATES" ] then @@ -1785,6 +1856,11 @@ fi # ------- Main operations ------- +if [ ! -e "${DBDIR}/COMPLETE_PREPARATION" ] +then + touch "${DBDIR}/COMPLETE_PREPARATION" +fi + if [ "$command" = prepare ] then echo "Done (skipped reinstallation) at `timestamp`" diff --git a/portsreinstall.8 b/portsreinstall.8 index 42713a4..a72b00f 100644 --- a/portsreinstall.8 +++ b/portsreinstall.8 @@ -179,7 +179,7 @@ If you want to continue the reinstallation process by resetting this option, exe \fB\-N\fR Renew option settings. This option is effective only with \fBredo\fR command. -Option settings for \fB\-s\fR, \fB\-q\fR and \fB\-d\R are reset according to the simultaneously given ones. +Option settings for \fB\-s\fR, \fB\-q\fR and \fB\-d\fR are reset according to the simultaneously given ones. .SH DETAILS This utility realizes smart reinstallation of a large number of ports by allowing you to run when when the machine is free and terminate when busy. Concretely, you can stop the process by CTRL+C anytime and restart quickly. @@ -230,7 +230,7 @@ If the problem will be resolved by manual reinstallation using pkg_add(1) or so .I glob where \fIglob\fR is the ports glob of the concerned port, and then restart this utility by .B portsreinstall redo -\. +command. .PP If you are familiar to the mechanism of Ports Collections system, in order to minimize package conflictions, it may be a good idea to delete packages which you don't think necessary before starting to use this utility. Don't be afraid to delete necessary dependencies because all required ports are automatically installed. @@ -263,7 +263,7 @@ Configuration file of portupgrade(1). .SH HISTORY \fBportsreinstall\fR has been developed as below. .TP -1.2.0 (29 July 2012) +1.2.0 (31 July 2012) [BUG FIX] Termination message is corrected (portsreinstall ok => portsreinstall ok add). [CHANGE] Functionalities of options \fB\-t\fR and \fB\-T\fR are changed so as to prevent deinstallation of irrelevant packages and detect obsolete installed dependencies. diff --git a/portsreinstall.8~ b/portsreinstall.8~ index 68db947..a1a54c5 100644 --- a/portsreinstall.8~ +++ b/portsreinstall.8~ @@ -179,7 +179,7 @@ If you want to continue the reinstallation process by resetting this option, exe \fB\-N\fR Renew option settings. This option is effective only with \fBredo\fR command. -Option settings for \fB\-s\fR, \fB\-q\fR and \fB\-d\R are reset according to the simultaneously given ones. +Option settings for \fB\-s\fR, \fB\-q\fR and \fB\-d\fR are reset according to the simultaneously given ones. .SH DETAILS This utility realizes smart reinstallation of a large number of ports by allowing you to run when when the machine is free and terminate when busy. Concretely, you can stop the process by CTRL+C anytime and restart quickly. @@ -230,7 +230,7 @@ If the problem will be resolved by manual reinstallation using pkg_add(1) or so .I glob where \fIglob\fR is the ports glob of the concerned port, and then restart this utility by .B portsreinstall redo -\. +command. .PP If you are familiar to the mechanism of Ports Collections system, in order to minimize package conflictions, it may be a good idea to delete packages which you don't think necessary before starting to use this utility. Don't be afraid to delete necessary dependencies because all required ports are automatically installed. @@ -266,7 +266,7 @@ Configuration file of portupgrade(1). 1.2.0 (29 July 2012) [BUG FIX] Termination message is corrected (portsreinstall ok => portsreinstall ok add). -[CHANGE] Functionalities of options \fB\-t\fR and \fB\-T\fR are changed so as to prevent deinstallation of irrelevant packages. +[CHANGE] Functionalities of options \fB\-t\fR and \fB\-T\fR are changed so as to prevent deinstallation of irrelevant packages and detect obsolete installed dependencies. [NEW] Options \fB\-X\fR, \fB\-r\fR and \fB\-R\fR are added so as to compensate a fact that \fB\-x\fR, \fB\-t\fR and \fB\-T\fR cannot specify package names with commas. diff --git a/portsreinstall~ b/portsreinstall~ index 83173dc..3b2397a 100755 --- a/portsreinstall~ +++ b/portsreinstall~ @@ -10,7 +10,7 @@ # ================================================ APPNAME=`basename $0` -MYVERSION=1.1.0+toward_1.2.0_20120729213245 +MYVERSION=1.1.0+toward_1.2.0_20120731055210 PREFIX=${PREFIX:-/usr/local} CONFFILE=${PREFIX}/etc/${APPNAME}.conf @@ -521,9 +521,10 @@ register_globs () globlist1=$1 globlist2=$2 listpath=$3 - mode=$3 + mode=$4 dirpath=`dirname "$listpath"` - for glob in `echo $globlist1 | sed 's/,/ /g'` $globlist2 + echo "`echo "$globlist1" | sed 's/,/ /g'`" "$globlist2" | sed -E 's/ +/\ +/g' | grep -v '^$' | while read glob do if expr "@$glob" : '^@[^/][^/]*/[^/][^/]*$' > /dev/null 2> /dev/null then @@ -688,17 +689,19 @@ inspect_dependencies () pkg=`pkg_info -qO "$origin"` if [ -n "$pkg" ] then - $target_dir=${DBDIR}/initial/$origin + target_dir=${DBDIR}/initial/$origin [ -d "$target_dir" ] || mkdir -p "$target_dir" echo $pkg > $target_dir/installed_version pkg_info -qr "$pkg" | grep '^@pkgdep ' | sed 's/^@pkgdep[[:space:]]*//' | while read requirement do - pkg_info -o "$requirement" - done > $target_dir/requires + pkg_info -e "$requirement" || continue + pkg_info -qo "$requirement" >> $target_dir/requires + done pkg_info -qR "$pkg" | grep -v '^$' | while read dependent do - pkg_info -o "$dependent" - done > $target_dir/dependents + pkg_info -e "$dependent" || continue + pkg_info -qo "$dependent" >> $target_dir/dependents + done fi origin_src= if [ `echo $origin | grep -m 1 -E -f "${DBDIR}/REPLACE.grep_from_pattern.conflist" | wc -l` -eq 1 ] @@ -853,65 +856,55 @@ chk_if_target () local prefix _is_all _is_target _is_required _is_former_required _is_dependent _is_former_dependent _is_relevant prefix=$1 origin=$2 - _is_all=y - _is_target= - _is_required= - _is_former_required= - _is_dependent= - _is_former_dependent= - _is_relevant=y - if [ `cat "${DBDIR}/target_required_ports.specified" 2> /dev/null | wc -l` -gt 0 ] + if [ -e "${DBDIR}/requires/$origin/chk_if_target.param" ] then - _is_all= - if [ ! -f "${DBDIR}/requires/$origin/dependents.pattern" ] - then - str_escape_regexp_filter < "${DBDIR}/requires/$origin/dependents" | sed 's/^/^/;s/$/$/' > "${DBDIR}/requires/$origin/dependents.pattern" 2> /dev/null || : - fi - if [ -e "${DBDIR}/initial/$origin/dependents" -a ! -f "${DBDIR}/initial/$origin/dependents.pattern" ] - then - str_escape_regexp_filter < "${DBDIR}/initial/$origin/dependents" | sed 's/^/^/;s/$/$/' > "${DBDIR}/initial/$origin/dependents.pattern" 2> /dev/null || : - fi - if grep -m 1 -E "^`str_escape_regexp $origin`$" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null - then - _is_target=y - elif grep -m 1 -E -f "${DBDIR}/requires/$origin/dependents.pattern" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null - then - _is_required=y - elif [ -e "${DBDIR}/initial/$origin/dependents.pattern" ] + . "${DBDIR}/requires/$origin/chk_if_target.param" + else + _is_all=y + _is_target= + _is_required= + _is_former_required= + _is_dependent= + _is_former_dependent= + _is_relevant=y + if [ `cat "${DBDIR}/target_required_ports.specified" 2> /dev/null | wc -l` -gt 0 ] then - if grep -m 1 -E -f "${DBDIR}/initial/$origin/dependents.pattern" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null + _is_all= + if grep -m 1 -E "^`str_escape_regexp $origin`$" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null + then + _is_target=y + elif [ -e "${DBDIR}/requires/$origin/dependents.pattern" ] && grep -m 1 -E -f "${DBDIR}/requires/$origin/dependents.pattern" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null + then + _is_required=y + elif [ -e "${DBDIR}/initial/$origin/dependents.pattern" ] && grep -m 1 -E -f "${DBDIR}/initial/$origin/dependents.pattern" "${DBDIR}/target_required_ports.specified" > /dev/null 2> /dev/null then _is_former_required=y fi fi - fi - if [ `cat "${DBDIR}/target_dependent_ports.specified" 2> /dev/null | wc -l` -gt 0 ] - then - _is_all= - if [ ! -f "${DBDIR}/requires/$origin/requires.pattern" ] - then - str_escape_regexp_filter < "${DBDIR}/requires/$origin/requires" | sed 's/^/^/;s/$/$/' > "${DBDIR}/requires/$origin/requires.pattern" 2> /dev/null || : - fi - if [ -e "${DBDIR}/initial/$origin/requires" -a ! -f "${DBDIR}/initial/$origin/requires.pattern" ] - then - str_escape_regexp_filter < "${DBDIR}/initial/$origin/requires" | sed 's/^/^/;s/$/$/' > "${DBDIR}/initial/$origin/requires.pattern" 2> /dev/null || : - fi - if [ -n "${_is_target}" ] || grep -m 1 -E "^`str_escape_regexp $origin`$" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null - then - _is_target=y - elif grep -m 1 -E -f "${DBDIR}/requires/$origin/requires.pattern" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null + if [ `cat "${DBDIR}/target_dependent_ports.specified" 2> /dev/null | wc -l` -gt 0 ] then - _is_dependent=y - fi - elif [ -e "${DBDIR}/initial/$origin/requires.pattern" ] - then - if grep -m 1 -E -f "${DBDIR}/initial/$origin/requires.pattern" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null + _is_all= + if [ -n "${_is_target}" ] || grep -m 1 -E "^`str_escape_regexp $origin`$" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null + then + _is_target=y + elif [ -e "${DBDIR}/requires/$origin/requires.pattern" ] && grep -m 1 -E -f "${DBDIR}/requires/$origin/requires.pattern" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null + then + _is_dependent=y + elif [ -e "${DBDIR}/initial/$origin/requires.pattern" ] && grep -m 1 -E -f "${DBDIR}/initial/$origin/requires.pattern" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null then _is_former_dependent=y fi fi + [ -n "${_is_all}${_is_target}${_is_required}${_is_former_required}${_is_dependent}${_is_former_dependent}" ] || _is_relevant= + echo _is_all=${_is_all} > ${TMPDIR}/chk_if_target:results + echo _is_target=${_is_target} >> ${TMPDIR}/chk_if_target:results + echo _is_required=${_is_required} >> ${TMPDIR}/chk_if_target:results + echo _is_former_required=${_is_former_required} >> ${TMPDIR}/chk_if_target:results + echo _is_dependent=${_is_dependent} >> ${TMPDIR}/chk_if_target:results + echo _is_former_dependent=${_is_former_dependent} >> ${TMPDIR}/chk_if_target:results + echo _is_relevant=${_is_relevant} >> ${TMPDIR}/chk_if_target:results + mv "${TMPDIR}"/chk_if_target:results "${DBDIR}/requires/$origin/chk_if_target.param" fi - [ -n "${_is_all}${_is_target}${_is_required}${_is_former_required}${_is_dependent}${_is_former_dependent}" ] || _is_relevant= eval ${prefix}_is_all=\$\{_is_all\} eval ${prefix}_is_target=\$\{_is_target\} eval ${prefix}_is_required=\$\{_is_required\} @@ -921,6 +914,21 @@ chk_if_target () eval ${prefix}_is_relevant=\$\{_is_relevant\} } +register_globs_only_installed () +{ + local src1 src2 + src1=$1 + src2=$2 + rm -f "${TMPDIR}/register_globs_only_installed:origins" + register_globs "$src1" "$src2" "${TMPDIR}/register_globs_only_installed:origins" + [ -e "${TMPDIR}/register_globs_only_installed:origins" ] || return 0 + while read origin + do + [ -z `pkg_info -qO "$origin"` ] || echo $origin + done < ${TMPDIR}/register_globs_only_installed:origins +} + + # ================================================== # ==================== MAIN ======================== # ================================================== @@ -1050,7 +1058,7 @@ load) exit ;; show) - [ -d "${DBDIR}" ] || { echo "ERROR: Database has not built yet." >&2; exit 1; } + [ -e "${DBDIR}/COMPLETE_PREPARATION" ] || { echo "ERROR: Database has not built yet." >&2; exit 1; } warn_update_ports _filter_skip_unchanged= _filter_only_target= @@ -1097,12 +1105,13 @@ show) _filter_only_target=y ;; requirements) + grandtitle="Dependencies based on the latest ports tree" title="The following ports are required by %s:" list=requires _for_each_matching_port=y ;; dependents) - + grandtitle="Dependencies based on the latest ports tree" title="The following ports depend on %s:" list=dependents _for_each_matching_port=y @@ -1112,19 +1121,21 @@ show) exit 1 ;; esac - [ -r "${DBDIR}/$list" ] || exit 0 + [ -n "${_for_each_matching_port}" -o -r "${DBDIR}/$list" ] || exit 0 [ -e "${DBDIR}"/saved_options.sh ] && . "${DBDIR}"/saved_options.sh if [ -n "${_for_each_matching_port}" ] then shift [ $# -gt 0 ] || { echo "ERROR: the argument as port glob is missing" >&2; exit 1; } + echo "[$grandtitle]" + echo isfirst=y for origin_target in `ports_glob "$@"` do + [ -e "${DBDIR}/requires/$origin_target/pkgtag" ] || continue [ "$isfirst" = y ] || echo isfirst=n - [ -e "${DBDIR}/requires/$origin_target/pkgtag" ] || { echo "WARNING: the database for $origin_target is not ready" >&2; continue; } - pkg_target=`cat "${DBDIR}/$pkgnamedb/$origin/pkgtag"` + pkg_target=`cat "${DBDIR}/$pkgnamedb/$origin_target/pkgtag"` printf "$title\n" "$origin_target ($pkg_target)" [ -e "${DBDIR}/requires/$origin_target/$list" ] || continue while read origin @@ -1345,8 +1356,38 @@ fi if [ ! -e "${DBDIR}/COMPLETE_PARSE_OPTION_TARGET_PORTS" ] then rm -f "${DBDIR}/target_dependent_ports.specified" "${DBDIR}/target_required_ports.specified" - register_globs "$target_dependent_ports" "$target_dependent_ports_form2" "${DBDIR}/target_dependent_ports.specified" - register_globs "$target_required_ports" "$target_required_ports_form2" "${DBDIR}/target_required_ports.specified" + register_globs_only_installed "$target_dependent_ports" "$target_dependent_ports_form2" > ${DBDIR}/target_dependent_ports.specified + register_globs_only_installed "$target_required_ports" "$target_required_ports_form2" > ${DBDIR}/target_required_ports.specified + if [ `cat "${DBDIR}"/target_dependent_ports.specified | wc -l` -gt 0 -a `cat "${DBDIR}"/target_required_ports.specified | wc -l` -gt 0 ] + then + echo "INFO: Ports/packages irrelevant to" + echo "----------------------------------------" + cat "${DBDIR}"/target_dependent_ports.specified + echo "----------------------------------------" + echo "nor their dependents, and irrelevant to" + echo "----------------------------------------" + cat "${DBDIR}"/target_required_ports.specified + echo "----------------------------------------" + echo "nor their requirements are skipped." + elif [ `cat "${DBDIR}"/target_dependent_ports.specified | wc -l` -gt 0 ] + then + echo "INFO: Ports/packages irrelevant to" + echo "----------------------------------------" + cat "${DBDIR}"/target_dependent_ports.specified + echo "----------------------------------------" + echo "nor their dependents are skipped." + elif [ `cat "${DBDIR}"/target_required_ports.specified | wc -l` -gt 0 ] + then + echo "INFO: Ports/packages irrelevant to" + echo "----------------------------------------" + cat "${DBDIR}"/target_required_ports.specified + echo "----------------------------------------" + echo "nor their requirements are skipped." + elif [ -n "$target_dependent_ports$target_dependent_ports_form2$target_required_ports$target_required_ports_form2" ] + then + echo "ERROR: Target ports are specified but none of them is valid." >&2 + exit 1 + fi touch "${DBDIR}/COMPLETE_PARSE_OPTION_TARGET_PORTS" fi @@ -1512,7 +1553,9 @@ rm -f "${DBDIR}/REQUIRE_CHK_NEW_TARGET" # Inspection of all dependencies if [ ! -e "${DBDIR}/COMPLETE_COLLECED_ALL_DEPENDENCIES" ] then - echo "Starting to inspect dependencies of installed packages at `timestamp`" + echo "Starting to inspect dependencies of the all installed packages at `timestamp`" + [ -z "$target_dependent_ports$target_dependent_ports_form2$target_required_ports$target_required_ports_form2" ] || \ + echo "INFO: Ports irrelevant to the targets are also inspected in order to get complete information." [ -d "${DBDIR}/requires" ] || mkdir -p "${DBDIR}/requires" touch "${DBDIR}/moved_or_lost.list" touch "${DBDIR}/target.inspected.list" @@ -1597,6 +1640,34 @@ then echo fi +# Preparation of matching patterns of dependencies +if [ ! -e "${DBDIR}/COMPLETE_PREPARATION_OF_MATCHING_PATTERNS_OF_DEPENDENCIES" ] +then + echo "Starting preparation of matching patterns of dependencies at `timestamp`" + if [ -f "${DBDIR}/prepare_matching_patterns_dependencies.remain" ] + then + echo "INFO: Restarting from the previously terminated point" + else + find "${DBDIR}/requires" -depth 2 -type d > ${DBDIR}/prepare_matching_patterns_dependencies.remain + fi + cp "${DBDIR}/prepare_matching_patterns_dependencies.remain" "${DBDIR}/prepare_matching_patterns_dependencies" + while read dbpath + do + portname=`basename "$dbpath"` + catpath=`dirname "$dbpath"` + catname=`basename "$catpath"` + origin=$catname/$portname + [ ! -e "${DBDIR}/requires/$origin/dependents" ] || str_escape_regexp_filter < ${DBDIR}/requires/$origin/dependents | sed 's/^/^/;s/$/$/' > ${DBDIR}/requires/$origin/dependents.pattern + [ ! -e "${DBDIR}/initial/$origin/dependents" ] || str_escape_regexp_filter < ${DBDIR}/initial/$origin/dependents | sed 's/^/^/;s/$/$/' > ${DBDIR}/initial/$origin/dependents.pattern + [ ! -e "${DBDIR}/requires/$origin/requires" ] || str_escape_regexp_filter < ${DBDIR}/requires/$origin/requires | sed 's/^/^/;s/$/$/' > ${DBDIR}/requires/$origin/requires.pattern + [ ! -e "${DBDIR}/initial/$origin/requires" ] || str_escape_regexp_filter < ${DBDIR}/initial/$origin/requires | sed 's/^/^/;s/$/$/' > ${DBDIR}/initial/$origin/requires.pattern + chk_if_target currentorigin "$origin" + sed -i '' 1d "${DBDIR}/prepare_matching_patterns_dependencies.remain" + done < ${DBDIR}/prepare_matching_patterns_dependencies + touch "${DBDIR}/COMPLETE_PREPARATION_OF_MATCHING_PATTERNS_OF_DEPENDENCIES" + echo +fi + # Inspection of necessary updates if [ ! -e "${DBDIR}/COMPLETE_NECESSARY_UPDATES" ] then @@ -1785,6 +1856,11 @@ fi # ------- Main operations ------- +if [ ! -e "${DBDIR}/COMPLETE_PREPARATION" ] +then + touch "${DBDIR}/COMPLETE_PREPARATION" +fi + if [ "$command" = prepare ] then echo "Done (skipped reinstallation) at `timestamp`" -- 2.11.0