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:
parent
624d0e4eaf
commit
2028d5f0b1
1 changed files with 61 additions and 23 deletions
|
@ -27,16 +27,23 @@
|
||||||
|
|
||||||
# Configurations
|
# Configurations
|
||||||
|
|
||||||
|
# Sapmple BLOCKLIST
|
||||||
|
|
||||||
BLOCKLISTS="japanese/libreoffice editors/libreoffice \
|
BLOCKLISTS="japanese/libreoffice editors/libreoffice \
|
||||||
www/chromium www/firefox \
|
www/chromium www/firefox \
|
||||||
www/linux-widevine-cdm"
|
www/linux-widevine-cdm"
|
||||||
|
|
||||||
|
# Resulting and temporary directories/files
|
||||||
|
|
||||||
PORTSDIR=/usr/ports
|
PORTSDIR=/usr/ports
|
||||||
LISTDIR=/poudriere
|
LISTDIR=/poudriere
|
||||||
LISTFILE=pkglist.all
|
LISTFILE=pkglist.all
|
||||||
TMPDIR=/tmp
|
TMPDIR=/tmp
|
||||||
TMPFILE=${LISTFILE}-`id -u`-`date "+%Y%m%d%H%M%S"`
|
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 Output = ${LISTDIR}/${LISTFILE}
|
||||||
echo Temporary = ${TMPDIR}/${TMPFILE}
|
echo Temporary = ${TMPDIR}/${TMPFILE}
|
||||||
|
|
||||||
|
@ -44,41 +51,72 @@ echo Temporary = ${TMPDIR}/${TMPFILE}
|
||||||
|
|
||||||
|
|
||||||
# Cleanup old lists if exists, and rotate list.
|
# 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}.old ] ; then rm ${LISTDIR}/${LISTFILE}.old ; fi
|
||||||
if [ -f ${LISTDIR}/${LISTFILE} ] ; then mv ${LISTDIR}/${LISTFILE} ${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
|
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
|
for PORT in $( pkg query -a '%o' | sort -u )
|
||||||
PORT=`pkg query %o ${PACKAGE}`
|
do
|
||||||
FLAVOR=`pkg info -A ${PACKAGE} | fgrep "flavor" | cut -f 4 -w`
|
# Unset the flag to mark the port to be ignored for listing.
|
||||||
FLG=NO
|
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
|
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
|
if [ ${PORT} = ${NONEED} ] ; then FLG="YES" ; fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Turn on the flag if the port is listed in MOVED without successor.
|
||||||
fgrep "${PORT}||" ${PORTSDIR}/MOVED > /dev/null
|
fgrep "${PORT}||" ${PORTSDIR}/MOVED > /dev/null
|
||||||
RET=$?
|
RET=$?
|
||||||
if [ 0 -eq $((RET)) ] ; then FLG="YES" ; fi
|
if [ 0 -eq $((RET)) ] ; then FLG="YES" ; fi
|
||||||
if [ -n ${FLAVOR} ] ; then
|
|
||||||
fgrep "${PORT}@${FLAVOR}||" ${PORTSDIR}/MOVED > /dev/null
|
# 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=$?
|
RET=$?
|
||||||
if [ 0 -eq $((RET)) ] ; then FLG="YES" ; fi
|
if [ 0 -eq $((RET)) ] ; then FLG="YES" ; fi
|
||||||
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
|
if [ "NO" = ${FLG} ] ; then
|
||||||
if [ -z ${FLAVOR} ] ; then
|
echo "${PORT}@${FLVR}" >> ${TMPDIR}/${TMPFILE}
|
||||||
echo ${PORT} >> ${TMPDIR}/${TMPFILE}
|
|
||||||
else
|
|
||||||
echo ${PORT}@${FLAVOR} >> ${TMPDIR}/${TMPFILE}
|
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
done
|
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}
|
chmod 666 ${LISTDIR}/${LISTFILE}
|
||||||
rm ${TMPDIR}/${TMPFILE}
|
rm ${TMPDIR}/${TMPFILE}
|
||||||
|
|
Loading…
Reference in a new issue