#!/bin/sh # To create rc_port_fix.txt: # # find /usr/ports/ -type f -exec grep /etc/rc.subr {} \+ | cut -f1 -d: | sort -u | \ # grep -vE '/files/patch-|/files/pkg-install.in|/Makefile|/CHANGES|Mk/bsd.port.mk' > /tmp/rc_list.txt # for f in `cat /tmp/rc_list.txt`; do /tmp/rccheck.sh "${f}" >/dev/null || echo "${f}"; done > /tmp/rc_list2.txt # for f in `cat /tmp/rc_list2.txt`; do sha256 -r "${f}" ; done | sort -u -k1,1 | cut -f2 -d' ' | sort > /tmp/rc_list3.txt # for f in `cat /tmp/rc_list3.txt`; do echo "-- ${f} --"; /tmp/rccheck.sh "${f}"; done > /tmp/rc_port_fix.txt LANG=C readrc() { local line _var local f_flag='' e_flag='' local rcfile="$1" while read -r line; do if [ "${line%\\}" != "${line}" ]; then # escaped line if [ -n "${e_flag}" ]; then # continuous escaped line continue else # first escaped line # fail through to check if it's valid global line e_flag=true fi elif [ -n "${e_flag}" ]; then # last escaped line unset e_flag continue fi case "${line}" in # ignore empty lines and comments \#*|'') continue ;; # skip rc.subr/network.subr/gnome.subr include '. /etc/rc.subr'|'. /etc/network.subr'|'. %%GNOME_SUBR%%') continue ;; # other include lines are potentially dangerous (but only if global) '. '*) [ -z ${f_flag} ] && { echo "${line}"; rc=1; }; continue ;; # skip variable commands (export, true, unset) 'export '*|': ${'*|'unset '*) continue ;; # skip rc-script commands load_rc_config*|run_rc_command*) continue ;; esac # skip variable assignment commands _var="${line%%=*}" case "${_var}" in # % is hack for %%PORTNAME%%_* style variables "${line}"|*[!a-zA-Z0-9_%]*) ;; *) continue ;; esac unset _var # skip function declarations _var="${line%%()}" case "${_var}" in # % is hack for %%PORTNAME%%_* style function names # \s is for 'func ()' style declarations "${line}"|*[!a-zA-Z0-9_%[:space:]]*) ;; *) continue ;; esac # skip function body case "${line}" in }) unset f_flag; continue ;; esac case "${line}" in # allow opening bracket on the same line with function name *'() {'|*'(){'|{) f_flag=true; continue ;; esac if [ -z ${f_flag} ]; then rc=1 # maybe broken unset e_flag # invalid global line, print despite escape echo "${line}" fi done < "${rcfile}" } rc=0 readrc $1 exit ${rc}