1#!/bin/sh 2# redundant-opt-files.sh 3# Written by John Marino (marino@FreeBSD.org) 4# 5# This script checks every option file against the default options of 6# its port. If they are identical, it writes the full path of the ports 7# option directory (typically in /var/db/ports) to stdout. 8# It is typically used by Synth users to identify options files that can 9# deleted in order to prevent future configuration check failures. 10 11portsdir=${PORTSDIR:-/usr/mports} 12if [ ! -d "${portsdir}" ]; then 13 echo "The ${portsdir} ports directory does not exist" 14 echo "There is nothing more to do." 15 exit 16fi 17 18db_dir=$(/usr/bin/make -C ${portsdir}/devel/gmake -V PORT_DBDIR 2>/dev/null) 19 20if [ ! -d "${db_dir}" ]; then 21 echo "The ${db_dir} ports option directory does not exist" 22 echo "There is nothing more to do." 23 exit 24fi 25 26catport() { 27 local category 28 local port 29 local workstr=${1#${db_dir}/} 30 local words=$(echo ${workstr} | /usr/bin/tr "_" " "); 31 for word in ${words}; do 32 category=${word} 33 break; 34 done 35 port=${workstr#${category}_} 36 echo ${portsdir}/$category/$port 37} 38 39identical_options() { 40 local origin=$(catport $1) 41 if [ ! -d ${origin} ]; then 42 # origin no longer exists, list it anyway without testing further 43 echo $1 44 return 45 fi 46 local selected_pristine=$(/usr/bin/make -C ${origin} \ 47 -V SELECTED_OPTIONS PORT_DBDIR=/dev/null) 48 local selected_now=$(/usr/bin/make -C ${origin} -V SELECTED_OPTIONS) 49 local deselected_pristine=$(/usr/bin/make -C ${origin} \ 50 -V DESELECTED_OPTIONS PORT_DBDIR=/dev/null) 51 local deselected_now=$(/usr/bin/make -C ${origin} -V DESELECTED_OPTIONS) 52 if [ "${selected_pristine}" = "${selected_now}" -a \ 53 "${deselected_pristine}" = "${deselected_now}" ]; then 54 echo $1 55 fi; 56} 57 58optdirs=$(/usr/bin/find -s "${db_dir}" -type d -depth 1) 59 60for dossier in ${optdirs}; do 61 identical_options ${dossier} 62done 63