#!/bin/bash themetmp=/tmp/themetmp.$$ if [ -z "$1" ] then echo "Error: please specify path to your template.php ie: sites/all/themes/mytheme/template.php" exit fi if [ ! -f "$1" ] then echo "Error: Unable to open $1" exit fi if [ ! -f "update.php" ] then echo "Error: Please run from the drupal base dir" exit fi template_file=$1 export template_file theme_funcs="theme" # build a list of known function prefixes # @todo we assume you dnt have a _ in your function overrides theme_func_str=`grep "^function" $template_file|awk '{print $2}'|awk -F_ '{print $1}'|sort|uniq|grep -E "\w+"` for t in $theme_func_str do theme_funcs="$theme_funcs|$t" done export theme_funcs # build an index of known functions echo "Building function index.." grep -ir "^function theme" sites/all/modules includes modules themes|grep -viE "(svn|cvs)" > $themetmp echo "Getting theme overrides" #get a list of overrides from the template.php overrides=`grep -iE "^function ($theme_funcs)" $template_file|awk '{print $2}'|awk -F \( '{print $1}'|sed -r 's/^[a-z]+//g'` for f in $overrides do func=`grep "theme$f\W" $themetmp` if [ $? -eq 0 ] then # check our original file with the original declaration orig_file=`echo $func|awk -F: '{print $1}'` echo "{ if (match(\$0,\"function theme$f\") || o==1) { print; o=1; if (match(\$0,\"^}\")) { o=0; }} }" > /tmp/o awk -f /tmp/o $orig_file >/tmp/orig-def echo "{ if (match(\$0,\"function ($theme_funcs)$f\") || o==1) { print; o=1; if (match(\$0,\"^}\")) { o=0; }} }" > /tmp/n awk -f /tmp/n $template_file >/tmp/new-def echo -e "\n\n ------ diff for theme$f ----- \n\n" diff --side-by-side /tmp/orig-def /tmp/new-def else echo "**** $f not found to be declared" fi done rm -f "$themetmp" rm -f /tmp/n rm -f /tmp/0