Teach portsnap how to ignore unwanted parts of the ports tree. A line

of the form "REFUSE foo" in portsnap.conf will result in parts of the
tree matching "^foo" being (a) not extracted by "portsnap extract", (b)
not updated by "portsnap update", and (c) not having any patches or new
ports downloaded by "portsnap fetch" or "portsnap cron". The example
shown in portsnap.conf demonstrates ignoring all the language categories.

As mentioned in portsnap.conf.5, the use of an imcomplete ports tree is
not officially supported; but this is something which many users have
requested, so I'm adding it anyway.

PR:		bin/85619 (but not the patch provided therein)
MFC after:	1 month
This commit is contained in:
Colin Percival 2005-09-06 19:28:37 +00:00
parent fba8a154bd
commit ff69e5b71e
3 changed files with 108 additions and 8 deletions

View File

@ -16,3 +16,9 @@ SERVERNAME=portsnap.FreeBSD.org
# a PGP-signed email from <security-officer@FreeBSD.org> telling you to
# change it and explaining why.
KEYPRINT=9b5feee6d69f170e3dd0a2c8e469ddbd64f13f978f2f3aede40c98633216c330
# Example of ignoring parts of the ports tree. If you know that you
# absolutely will not need certain parts of the tree, this will save
# some bandwidth and disk space. See the manual page for more details.
# REFUSE arabic chinese french german hebrew hungarian japanese
# REFUSE korean polish portuguese russian ukrainian vietnamese

View File

@ -87,14 +87,48 @@ is used.
.Pp
If more than one line of any of the above forms is included in
.Nm
then only the last one will take effect. Any lines not of the above
forms will be ignored.
then only the last one will take effect.
.Pp
Finally, a line of the form
.Dl REFUSE foo bar
will instruct
.Xr portsnap 8
to ignore parts of the ports tree with paths starting with
.Ar foo
or
.Ar bar ,
which are interpreted as extended regular expressions by
.Xr egrep 1 .
This will result in those parts of the tree not being updated
in the compressed snapshot when the
.Cm fetch
and
.Cm cron
commands are used and not being extracted when the
.Cm extract
command is used (unless a specific
.Ar path
is passed to
.Xr portsnap 8 ) ,
and if those parts of the ports tree are present they
will not be updated when the
.Cm update
command is used.
Unlike the other options, the parameters in REFUSE lines
accumulate and all such lines are considered.
.Bf Em
Note that operating with an incomplete ports tree is not
supported and may cause unexpected results.
.Ef
.Pp
Any lines not of the above forms will be ignored.
.Sh FILES
.Bl -tag -width "/etc/portsnap.conf"
.It /etc/portsnap.conf
Default location of the portsnap configuration file.
.El
.Sh SEE ALSO
.Xr egrep 1
.Xr fetch 1
.Xr portsnap 8
.Xr sha256 8

View File

@ -81,6 +81,7 @@ init_params() {
DDSTATS=""
INDEXONLY=""
SERVERNAME=""
REFUSE=""
}
# Parse the command line
@ -173,6 +174,8 @@ default_conffile() {
# Read {KEYPRINT, SERVERNAME, WORKDIR, PORTSDIR} from the configuration
# file if they haven't already been set. If the configuration
# file doesn't exist, do nothing.
# Also read REFUSE (which cannot be set via the command line) if it is
# present in the configuration file.
parse_conffile() {
if [ -r "${CONFFILE}" ]; then
for X in KEYPRINT WORKDIR PORTSDIR SERVERNAME; do
@ -182,6 +185,13 @@ parse_conffile() {
cut -f 2- -d '=' | tail -1`
fi
done
if grep -qE "^REFUSE[[:space:]]" ${CONFFILE}; then
REFUSE="^(`
grep -E "^REFUSE[[:space:]]" "${CONFFILE}" |
cut -c 7- | xargs echo | tr ' ' '|'
`)"
fi
fi
}
@ -668,6 +678,21 @@ fetch_update() {
cut -f 2 -d '|'`.gz > INDEX.new
fetch_index_sanity || return 1
# If we have decided to refuse certain updates, construct a hybrid index which
# is equal to the old index for parts of the tree which we don't want to
# update, and equal to the new index for parts of the tree which gets updates.
# This means that we should always have a "complete snapshot" of the ports
# tree -- with the caveat that it isn't actually a snapshot.
if [ ! -z "${REFUSE}" ]; then
echo "Refusing to download updates for ${REFUSE}" \
>${QUIETREDIR}
grep -Ev "${REFUSE}" INDEX.new > INDEX.tmp
grep -E "${REFUSE}" INDEX |
sort -m -k 1,1 -t '|' - INDEX.tmp > INDEX.new
rm -f INDEX.tmp
fi
# Generate a list of wanted ports patches
join -t '|' -o 1.2,2.2 INDEX INDEX.new |
fetch_make_patchlist > patchlist
@ -761,14 +786,34 @@ extract_indices() {
echo "done."
}
# Create .portsnap.INDEX
# Create .portsnap.INDEX; if we are REFUSEing to touch certain directories,
# merge the values from any exiting .portsnap.INDEX file.
extract_metadata() {
sort ${WORKDIR}/INDEX > ${PORTSDIR}/.portsnap.INDEX
if [ -z "${REFUSE}" ]; then
sort ${WORKDIR}/INDEX > ${PORTDIR}/.portsnap.INDEX
elif [ -f ${PORTSDIR}/.portsnap.INDEX ]; then
grep -E "${REFUSE}" ${PORTSDIR}/.portsnap.INDEX \
> ${PORTSDIR}/.portsnap.INDEX.tmp
grep -vE "${REFUSE}" ${WORKDIR}/INDEX | sort |
sort -m - ${PORTSDIR}/.portsnap.INDEX.tmp \
> ${PORTSDIR}/.portsnap.INDEX
rm -f ${PORTSDIR}/.portsnap.INDEX.tmp
else
grep -vE "${REFUSE}" ${WORKDIR}/INDEX | sort \
> ${PORTSDIR}/.portsnap.INDEX
fi
}
# Do the actual work involved in "extract"
extract_run() {
if ! grep "^${EXTRACTPATH}" ${WORKDIR}/INDEX | while read LINE; do
if !
if ! [ -z "${EXTRACTPATH}" ]; then
grep "^${EXTRACTPATH}" ${WORKDIR}/INDEX
elif ! [ -z "${REFUSE}" ]; then
grep -vE "${REFUSE}" ${WORKDIR}/INDEX
else
cat ${WORKDIR}/INDEX
fi | while read LINE; do
FILE=`echo ${LINE} | cut -f 1 -d '|'`
HASH=`echo ${LINE} | cut -f 2 -d '|'`
echo ${PORTSDIR}/${FILE}
@ -813,14 +858,29 @@ update_run() {
return 0
fi
# If we are REFUSEing to touch certain directories, don't remove files
# from those directories (even if they are out of date)
echo -n "Removing old files and directories... "
sort ${WORKDIR}/INDEX | comm -23 ${PORTSDIR}/.portsnap.INDEX - |
cut -f 1 -d '|' | lam -s "${PORTSDIR}/" - | xargs rm -rf
if ! [ -z "${REFUSE}" ]; then
sort ${WORKDIR}/INDEX |
comm -23 ${PORTSDIR}/.portsnap.INDEX - | cut -f 1 -d '|' |
grep -vE "${REFUSE}" |
lam -s "${PORTSDIR}/" - | xargs rm -rf
else
sort ${WORKDIR}/INDEX |
comm -23 ${PORTSDIR}/.portsnap.INDEX - | cut -f 1 -d '|' |
lam -s "${PORTSDIR}/" - | xargs rm -rf
fi
echo "done."
# Install new files
echo "Extracting new files:"
if ! sort ${WORKDIR}/INDEX |
if !
if ! [ -z "${REFUSE}" ]; then
grep -vE "${REFUSE}" ${WORKDIR}/INDEX | sort
else
sort ${WORKDIR}/INDEX
fi |
comm -13 ${PORTSDIR}/.portsnap.INDEX - |
while read LINE; do
FILE=`echo ${LINE} | cut -f 1 -d '|'`