-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_workflows.sh
More file actions
executable file
·70 lines (65 loc) · 1.78 KB
/
fix_workflows.sh
File metadata and controls
executable file
·70 lines (65 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#
#
parentdir="`dirname $(readlink -f "$0")`/.."
parentdir=`readlink -f $parentdir`
if test x"$" = x"-log" ; then
logfile=$2
shift 2
else
logfile="$parentdir/noderenames.log"
fi
if ! test -f "$logfile" ; then
echo "Logfile '$logfile' not found"
printusage=true
else
printusage=false
fi
if $printusage || test -f "$1" ; then : ; else
echo
echo "Usage: $0 [-log <logfile>] <workflowfile> [<worflowfile2> ... ]"
echo
echo "This script renames path names in workflow jsons after node path renames"
echo "logfile defaults to '$parentdir/noderenames.log'"
exit
fi
while [ -f "$1" ] ; do
echo "File: $1"
sedcmd=""
echo "Substitutions"
exec 4<"$logfile"
while read -u 4 src arrow dst ; do
if [ x"$arrow" = x"->" ] ; then
pattern="\\<"`echo "$src" | sed -e's/\./\\./'`"\\>"
if grep -q "$pattern" "$1" || { echo "$sedcmd" | grep -q "$pattern" ; } ; then
echo "$src -> $dst"
sedcmd="${sedcmd}s/$pattern/$dst/g;"
fi
else
echo "ignoring illformated line: $src $arrow $dst[...]"
fi
done
exec 4<&-
if [ x"$sedcmd" != x"" ] ; then
tmpfile=`mktemp`
# replace .. by . ; remove leading ".
sedcmd="${sedcmd}"'s/\.\+/./;s/\(= *"\)\./\1/;'
sed -e"/import_path/{$sedcmd};/function/{$sedcmd}" "$1" > "$tmpfile"
echo "Result: "
if diff "$1" "$tmpfile" ; then : ; else
# file differs
if test -f "$1".bak ; then
echo "Refuse to overwrite backup file '$1.bak' - remove & try again"
finalmsg="$finalmsg
Refused to overwrite backup file '$1.bak' - remove & try again"
else
mv "$1" "$1".bak
mv $tmpfile "$1"
finalmsg="$finalmsg
Fixed and created backup file '$1.bak'"
fi
fi
fi
shift
done
echo "$finalmsg"