Path: blob/main/Tools/scripts/redundant-opt-files.sh
16462 views
#!/bin/sh1# redundant-opt-files.sh2# Written by John Marino ([email protected])3#4# This script checks every option file against the default options of5# its port. If they are identical, it writes the full path of the ports6# option directory (typically in /var/db/ports) to stdout.7# It is typically used by Synth users to identify options files that can8# deleted in order to prevent future configuration check failures.910portsdir=${PORTSDIR:-/usr/ports}11if [ ! -d "${portsdir}" ]; then12echo "The ${portsdir} ports directory does not exist"13echo "There is nothing more to do."14exit15fi1617db_dir=$(/usr/bin/make -C ${portsdir}/devel/gmake -V PORT_DBDIR 2>/dev/null)1819if [ ! -d "${db_dir}" ]; then20echo "The ${db_dir} ports option directory does not exist"21echo "There is nothing more to do."22exit23fi2425catport() {26local category27local port28local workstr=${1#${db_dir}/}29local words=$(echo ${workstr} | /usr/bin/tr "_" " ");30for word in ${words}; do31category=${word}32break;33done34port=${workstr#${category}_}35echo ${portsdir}/$category/$port36}3738identical_options() {39local origin=$(catport $1)40if [ ! -d ${origin} ]; then41# origin no longer exists, list it anyway without testing further42echo $143return44fi45local selected_pristine=$(/usr/bin/make -C ${origin} \46-V SELECTED_OPTIONS PORT_DBDIR=/dev/null)47local selected_now=$(/usr/bin/make -C ${origin} -V SELECTED_OPTIONS)48local deselected_pristine=$(/usr/bin/make -C ${origin} \49-V DESELECTED_OPTIONS PORT_DBDIR=/dev/null)50local deselected_now=$(/usr/bin/make -C ${origin} -V DESELECTED_OPTIONS)51if [ "${selected_pristine}" = "${selected_now}" -a \52"${deselected_pristine}" = "${deselected_now}" ]; then53echo $154fi;55}5657optdirs=$(/usr/bin/find -s "${db_dir}" -type d -depth 1)5859for dossier in ${optdirs}; do60identical_options ${dossier}61done626364