list-dependencies-from-patches.sh (858B)
1 #!/bin/bash 2 3 # Simple tool to list dependencies in form suitable for tsort utility. 4 # Run this script like this: 5 # /some/path/list-dependencies-from-patches.sh *.sql | tsort | tac 6 # To get patches in order that satisfies dependencies while loading them. 7 8 grep -hiE '^[[:space:]]*select _v.register_patch\(' "$@" | \ 9 sed 's/^[^(]*(//' | while read LINE 10 do 11 export PATCH_NAME="$( echo "$LINE" | cut -d\' -f2 )" 12 echo "$LINE" | sed "s/^[^']*'[^']\\+'[[:space:]]*,[[:space:]]*//" | \ 13 perl -ne ' 14 my @w; 15 if ( s/^ARRAY\s*\[// ) { 16 s/\].*//; 17 @w = /\047([^\047]+)\047/g; 18 } 19 push @w, $ENV{"PATCH_NAME"} if ( 0 == @w ) || ( 0 == ( @w % 2 ) ); 20 printf "%s %s\n", $ENV{"PATCH_NAME"}, $_ for @w; 21 ' 22 done