-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathupdate_scripts
executable file
·42 lines (35 loc) · 1.38 KB
/
update_scripts
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
#!/bin/bash
startpoint=73
cmdpoint=1087
endpoint=1117
lenient="no"
sourcedir="./installers"
scriptlist=$(ls "$sourcedir")
template="$sourcedir/template"
startcheck=$(sed -n "$startpoint"p $template | grep "^# template")
cmdcheck=$(sed -n "$cmdpoint"p $template | grep "^# script custom routines")
endcheck=$(sed -n "$endpoint"p $template | grep "^exit 0")
if [ -n "$startcheck" ] && [ -n "$endcheck" ]; then
echo "lines specified match template expected patterns"
else
echo "lines specified do not match template expected patterns"
exit 1
fi
for script in ${scriptlist[@]}; do
validcheck=$(sed -n "$startpoint","$startpoint"p "$sourcedir/$script" | grep "template")
if [ -n "$validcheck" ]; then
if [ "$lenient" == "yes" ]; then
endpoint=$((endpoint + 10))
blockcheck=$(sed -n "$startpoint","$endpoint"p "$sourcedir/$script" | grep "custom commands in this scope")
else
blockcheck=$(sed -n "$cmdpoint","$endpoint"p "$sourcedir/$script" | grep "custom commands in this scope")
fi
if [ -n "$blockcheck" ]; then
echo "processing $script ..."
variable=$(head -n "$startpoint" "$sourcedir/$script" | sed -e "$ d")
common=$(sed -n "$startpoint","$endpoint"p "$template")
{ echo "$variable" ; echo "" ; echo "$common"; } > "$sourcedir/$script"
fi
fi
done
exit 0