Significantly speed up by decreasing calls of pkg, Introduing the idea by DutchDaemon@FreeBSD.org. https://lists.freebsd.org/archives/freebsd-ports/2024-July/006334.html

This commit is contained in:
Tomoaki AOKI [aka Junchoon] 2024-07-07 18:28:56 +09:00
parent 624d0e4eaf
commit 2028d5f0b1

View file

@ -27,16 +27,23 @@
# Configurations
# Sapmple BLOCKLIST
BLOCKLISTS="japanese/libreoffice editors/libreoffice \
www/chromium www/firefox \
www/linux-widevine-cdm"
# Resulting and temporary directories/files
PORTSDIR=/usr/ports
LISTDIR=/poudriere
LISTFILE=pkglist.all
TMPDIR=/tmp
TMPFILE=${LISTFILE}-`id -u`-`date "+%Y%m%d%H%M%S"`
# Show users the output and temporary files, as they include
# user ID and date, thus, changes on every run by default.
echo Output = ${LISTDIR}/${LISTFILE}
echo Temporary = ${TMPDIR}/${TMPFILE}
@ -44,41 +51,72 @@ echo Temporary = ${TMPDIR}/${TMPFILE}
# Cleanup old lists if exists, and rotate list.
# Users running this script must have permission to chmod them.
if [ -f ${LISTDIR}/${LISTFILE}.old ] ; then rm ${LISTDIR}/${LISTFILE}.old ; fi
if [ -f ${LISTDIR}/${LISTFILE} ] ; then mv ${LISTDIR}/${LISTFILE} ${LISTDIR}/${LISTFILE}.old ; fi
if [ -f ${LISTDIR}/${LISTFILE}.old ] ; then chmod 666 ${LISTDIR}/${LISTFILE}.old ; fi
# Regenerate list with newly installed ports.
# Generate list of all installed, not orphaned and not in BLOCKLIST ports.
for PACKAGE in `pkg query -a %n` ; do
PORT=`pkg query %o ${PACKAGE}`
FLAVOR=`pkg info -A ${PACKAGE} | fgrep "flavor" | cut -f 4 -w`
FLG=NO
for NONEED in ${BLOCKLISTS} ; do
if [ -n ${FLAVOR} ] ; then
if [ ${PORT}@${FLAVOR} = ${NONEED} ] ; then FLG="YES" ; fi
fi
if [ ${PORT} = ${NONEED} ] ; then FLG="YES" ; fi
done
fgrep "${PORT}||" ${PORTSDIR}/MOVED > /dev/null
RET=$?
if [ 0 -eq $((RET)) ] ; then FLG="YES" ; fi
if [ -n ${FLAVOR} ] ; then
fgrep "${PORT}@${FLAVOR}||" ${PORTSDIR}/MOVED > /dev/null
for PORT in $( pkg query -a '%o' | sort -u )
do
# Unset the flag to mark the port to be ignored for listing.
FLG="NO"
# Obtain list of flavors used on any of the pkg built with the port.
FLAVOR=$( pkg info -A "${PORT}" | grep "flavor" | awk '{print $NF}' )
# Cases without flavor used.
if [ "x${FLAVOR}" = "x" ]
then
# Turn on the flag if the port is listed in BLOCKLIST.
for NONEED in ${BLOCKLISTS} ; do
if [ ${PORT} = ${NONEED} ] ; then FLG="YES" ; fi
done
# Turn on the flag if the port is listed in MOVED without successor.
fgrep "${PORT}||" ${PORTSDIR}/MOVED > /dev/null
RET=$?
if [ 0 -eq $((RET)) ] ; then FLG="YES" ; fi
fi
if [ "NO" = ${FLG} ] ; then
if [ -z ${FLAVOR} ] ; then
echo ${PORT} >> ${TMPDIR}/${TMPFILE}
else
echo ${PORT}@${FLAVOR} >> ${TMPDIR}/${TMPFILE}
# Write the port to temporary list if the flag is not set.
if [ "NO" = ${FLG} ] ; then
echo "${PORT}" >> ${TMPDIR}/${TMPFILE}
fi
else
# Cases that flavors are used.
# Variable FLAVOR can include multiple flavors, so loop
# to handle all of them.
for FLVR in ${FLAVOR}
do
# Turn on the flag if the port with and without the flavor
# is listed in BLOCKLIST.
for NONEED in ${BLOCKLISTS} ; do
if [ ${PORT}@${FLVR} = ${NONEED} ] ; then FLG="YES" ; fi
if [ ${PORT} = ${NONEED} ] ; then FLG="YES" ; fi
done
# Turn on the flag if the port with and without the flavor
# is listed in MOVED without successor.
fgrep "${PORT}||" ${PORTSDIR}/MOVED > /dev/null
RET=$?
if [ 0 -eq $((RET)) ] ; then FLG="YES" ; fi
fgrep "${PORT}@${FLVR}||" ${PORTSDIR}/MOVED > /dev/null
RET=$?
if [ 0 -eq $((RET)) ] ; then FLG="YES" ; fi
# Write the port with and without the flavor to temporary list
# if the flag is not set.
if [ "NO" = ${FLG} ] ; then
echo "${PORT}@${FLVR}" >> ${TMPDIR}/${TMPFILE}
fi
done
fi
done
sort ${TMPDIR}/${LISTFILE} | uniq > ${LISTDIR}/${LISTFILE}
# Finish the list to be unique lines only.
sort ${TMPDIR}/${TMPFILE} | uniq > ${LISTDIR}/${LISTFILE}
chmod 666 ${LISTDIR}/${LISTFILE}
rm ${TMPDIR}/${TMPFILE}