* Make it possible to skip existing dependencies and ports references in LEGAL

and continue with removal anyway. Requested by miwi@
* Pipe dependencies information (if any) through a PAGER because INDEX lines
  are very long and hard to read when wrapped
This commit is contained in:
Vasil Dimov 2007-01-19 15:49:49 +00:00
parent 39aa7a65ff
commit 0d451e0598
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=182805

View file

@ -2,7 +2,7 @@
# #
# rmport - remove port(s) from the FreeBSD Ports Collection. # rmport - remove port(s) from the FreeBSD Ports Collection.
# #
# Copyright 2006 Vasil Dimov # Copyright 2006-2007 Vasil Dimov
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -61,6 +61,18 @@ pkgname()
make -C ${PORTSDIR}/${1} -V PKGNAME make -C ${PORTSDIR}/${1} -V PKGNAME
} }
ask()
{
question=${1}
answer=x
while [ "${answer}" != "y" -a "${answer}" != "n" ] ; do
read -p "${question} [yn] " answer
done
echo ${answer}
}
# return category/port if arg is directly port's directory on the filesystem # return category/port if arg is directly port's directory on the filesystem
find_catport() find_catport()
{ {
@ -125,14 +137,10 @@ co_common()
# check if some ports depend on the given port # check if some ports depend on the given port
# XXX Very Little Chance (tm) for breaking INDEX exists: # XXX Very Little Chance (tm) for breaking INDEX exists:
# /usr/ports/INDEX may be outdated and not contain recently added dependencies # /usr/ports/INDEX may be outdated and not contain recently added dependencies
# Anyway, it is very unlikely for someone to make a port to depend on a port check_dep_core()
# that has EXPIRATION_DATE set, or /usr/ports/INDEX is really outdated - from
# before EXPIRATION_DATE being set
check_dep()
{ {
catport=${1} catport=${1}
persist=${2} alltorm=${2}
alltorm=${3}
pkgname=`pkgname ${catport}` pkgname=`pkgname ${catport}`
rmpkgs="" rmpkgs=""
@ -142,39 +150,66 @@ check_dep()
rmcatports="${rmcatports:+${rmcatports}|}${PORTSDIR}/${torm}/" rmcatports="${rmcatports:+${rmcatports}|}${PORTSDIR}/${torm}/"
done done
err=0
deps=`grep -E "${pkgname}" ${INDEX} |grep -vE "^(${rmpkgs})" || :`
if [ -n "${deps}" ] ; then
log "${catport}: some port(s) depend on ${pkgname}:"
printf "%s\n" "${deps}" >&2
err=1
fi
# check if some Makefiles mention the port to be deleted
portdir_grep="^[^#].*/`basename ${catport}`([[:space:]]|/|$)"
r="`find ${PORTSDIR} -mindepth 2 -maxdepth 3 \
\( -name "Makefile*" -or -path "*Mk/*.mk" \) \
|xargs grep -EH "${portdir_grep}" \
|grep -vE "^(${rmcatports})" || :`"
if [ -n "${r}" ] ; then
if [ ${err} -eq 1 ] ; then
echo >&2
fi
log "${catport}: some Makefiles mention ${portdir_grep}:"
printf "%s\n" "${r}" >&2
err=1
fi
return ${err}
}
check_dep()
{
catport=${1}
persist=${2}
alltorm=${3}
while : ; do while : ; do
log "${catport}: checking dependencies" log "${catport}: checking dependencies"
err=0 err=0
deps=`grep -E "${pkgname}" ${INDEX} |grep -vE "^(${rmpkgs})" || :` res="`check_dep_core ${catport} "${alltorm}" 2>&1`" || err=1
if [ -n "${deps}" ] ; then
log "${catport}: some port(s) depend on ${pkgname}:"
printf "%s\n" "${deps}" >&2
err=1
fi
# check if some Makefiles mention the port to be deleted
portdir_grep="^[^#].*/`basename ${catport}`([[:space:]]|/|$)"
r="`find ${PORTSDIR} -mindepth 2 -maxdepth 3 \
\( -name "Makefile*" -or -path "*Mk/*.mk" \) \
|xargs grep -EH "${portdir_grep}" \
|grep -vE "^(${rmcatports})" || :`"
if [ -n "${r}" ] ; then
log "${catport}: some Makefiles mention ${portdir_grep}:"
printf "%s\n" "${r}" >&2
err=1
fi
if [ ${err} -eq 0 ] ; then if [ ${err} -eq 0 ] ; then
break break
fi fi
printf "%s" "${res}" |${PAGER:-less}
if [ ${persist} -eq 0 ] ; then if [ ${persist} -eq 0 ] ; then
break break
fi fi
read -p 'deal with the above issues and hit <enter> when ready' dummy echo '' >&2
echo 'you can ignore the above issues and proceed anyway.' >&2
echo 'if this is the case, then either:' >&2
echo ' * these are false positives' >&2
echo ' * you want to break something' >&2
echo "or you can hit \`n' to repeat the check" >&2
answer=`ask "ignore the above issues"`
if [ "${answer}" = "y" ] ; then
break
fi
done done
} }
@ -267,7 +302,12 @@ check_LEGAL()
msg="${catport}: checking if ${checkstr} is in ports/LEGAL" msg="${catport}: checking if ${checkstr} is in ports/LEGAL"
log "${msg}" log "${msg}"
while grep -i ${checkstr} ports/LEGAL ; do while grep -i ${checkstr} ports/LEGAL ; do
read -p "${checkstr} is in ports/LEGAL, remove it and hit <enter> when ready" dummy echo "${checkstr} is in ports/LEGAL, remove it and hit <enter> when ready" >&2
echo "or hit \`s' to skip this issue and continue anyway" >&2
read answer
if [ "${answer}" = "s" ] ; then
break
fi
log "${msg}" log "${msg}"
done done
done done
@ -366,18 +406,6 @@ diff()
echo ${diffout} echo ${diffout}
} }
ask()
{
question=${1}
answer=x
while [ "${answer}" != "y" -a "${answer}" != "n" ] ; do
read -p "${question} [yn] " answer
done
echo ${answer}
}
# ask for confirmation and commit # ask for confirmation and commit
commit() commit()
{ {