diff options
-rw-r--r-- | etc/portsnap.conf | 6 | ||||
-rw-r--r-- | share/man/man5/portsnap.conf.5 | 38 | ||||
-rw-r--r-- | usr.sbin/portsnap/portsnap/portsnap.sh | 72 |
3 files changed, 108 insertions, 8 deletions
diff --git a/etc/portsnap.conf b/etc/portsnap.conf index 665061e..3497edb 100644 --- a/etc/portsnap.conf +++ b/etc/portsnap.conf @@ -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 diff --git a/share/man/man5/portsnap.conf.5 b/share/man/man5/portsnap.conf.5 index eeae1f1..ba632166 100644 --- a/share/man/man5/portsnap.conf.5 +++ b/share/man/man5/portsnap.conf.5 @@ -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 diff --git a/usr.sbin/portsnap/portsnap/portsnap.sh b/usr.sbin/portsnap/portsnap/portsnap.sh index 38098e7..de263f0 100644 --- a/usr.sbin/portsnap/portsnap/portsnap.sh +++ b/usr.sbin/portsnap/portsnap/portsnap.sh @@ -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 '|'` |