-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubs.sh
executable file
·95 lines (80 loc) · 2.07 KB
/
subs.sh
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# Makes substitutions for variables in output file.
# Expects environment variables to be set.
# Should not be run manually
# Check required variables are defined
if [ -z $OUTPUT ]; then
>&2 echo "OUTPUT has not been defined"
exit 1
fi
# Validate variables
if [ ! -f $OUTPUT ]; then
>&2 echo "OUTPUT file '$OUTPUT' does not exist"
exit 2
fi
# Insert of hook scripts
if [ -f $PRE_START_SCRIPT ]; then
# Insert after BEGIN tag
sed -i "/### BEGIN PRE_START_SCRIPT ###/{
r $PRE_START_SCRIPT
}" $OUTPUT
fi
if [ -f $POST_START_SCRIPT ]; then
# Insert after BEGIN tag
sed -i "/### BEGIN POST_START_SCRIPT ###/{
r $POST_START_SCRIPT
}" $OUTPUT
fi
if [ -f $PRE_STOP_SCRIPT ]; then
# Insert after BEGIN tag
sed -i "/### BEGIN PRE_STOP_SCRIPT ###/{
r $PRE_STOP_SCRIPT
}" $OUTPUT
fi
if [ -f $POST_STOP_SCRIPT ]; then
# Insert after BEGIN tag
sed -i "/### BEGIN POST_STOP_SCRIPT ###/{
r $POST_STOP_SCRIPT
}" $OUTPUT
fi
if [ -f $PRE_RESTART_SCRIPT ]; then
# Insert after BEGIN tag
sed -i "/### BEGIN PRE_RESTART_SCRIPT ###/{
r $PRE_RESTART_SCRIPT
}" $OUTPUT
fi
if [ -f $POST_RESTART_SCRIPT ]; then
# Insert after BEGIN tag
sed -i "/### BEGIN POST_RESTART_SCRIPT ###/{
r $POST_RESTART_SCRIPT
}" $OUTPUT
fi
if [ -f $PRE_PAUSE_SCRIPT ]; then
# Insert after BEGIN tag
sed -i "/### BEGIN PRE_PAUSE_SCRIPT ###/{
r $PRE_PAUSE_SCRIPT
}" $OUTPUT
fi
if [ -f $POST_PAUSE_SCRIPT ]; then
# Insert after BEGIN tag
sed -i "/### BEGIN POST_PAUSE_SCRIPT ###/{
r $POST_PAUSE_SCRIPT
}" $OUTPUT
fi
if [ -f $PRE_UNPAUSE_SCRIPT ]; then
# Insert after BEGIN tag
sed -i "/### BEGIN PRE_UNPAUSE_SCRIPT ###/{
r $PRE_UNPAUSE_SCRIPT
}" $OUTPUT
fi
if [ -f $POST_UNPAUSE_SCRIPT ]; then
# Insert after BEGIN tag
sed -i "/### BEGIN POST_UNPAUSE_SCRIPT ###/{
r $POST_UNPAUSE_SCRIPT
}" $OUTPUT
fi
# Basic variable substitutions - done after hook scripts to allow use of tags
# in user hook scripts
sed -i "s/<DESCRIPTION>/$DESCRIPTION/g" $OUTPUT
sed -i "s/<SERVICE>/$SERVICE/g" $OUTPUT
sed -i "s/<CONTAINER>/$CONTAINER/g" $OUTPUT