#!/bin/sh # # Copyright (c) 2024 Tomoaki AOKI # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # 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} # End configurations section. # 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 # Generate list of all installed, not orphaned and not in BLOCKLIST ports. 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 # 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 # Finish the list to be unique lines only. sort ${TMPDIR}/${TMPFILE} | uniq > ${LISTDIR}/${LISTFILE} chmod 666 ${LISTDIR}/${LISTFILE} rm ${TMPDIR}/${TMPFILE}