-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmakeInstallers.sh
executable file
·173 lines (135 loc) · 4.7 KB
/
makeInstallers.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
#
# Script to make installers for The plugins of Open QuarterMaster.
#
# Author: Greg Stewart
#
# Requires packages:
# Ubuntu:
# - dpkg-dev
# - rpm
# - rpmlint
# - jq
#
cd "$(dirname "$0")" || exit
mainConfigFile="properties.json"
buildDir="build"
debDir="PluginsDeb"
# All
packages=("mss-controller")
# Ready for deployment
#packages=("mss-controller-plugin")
#
# Clean
#
rm -rf "$buildDir"
#
# Setup
#
mkdir "$buildDir"
for curPackage in ${packages[@]}; do
packageInstallerSrc="$curPackage/snhInstallerSrc"
packageConfigFile="$packageInstallerSrc/properties.json"
packageDebDir="$buildDir/$curPackage/$debDir"
pushd ./$curPackage/
pluginVersion="$(./gradlew -q printVersion)"
popd
echo "Creating deb installer for $curPackage version $pluginVersion"
#
# Debian build
#
mkdir -p "$packageDebDir"
mkdir "$packageDebDir/DEBIAN"
mkdir -p "$packageDebDir/etc/systemd/system/"
mkdir -p "$packageDebDir/etc/oqm/config/configs/"
serviceFiles=()
for i in `find "./$packageInstallerSrc" -name "*.service" -type f -printf '%f\n'`; do
[ -f "./$packageInstallerSrc/$i" ] || break
serviceFile="$i"
echo "Service file: $serviceFile"
# serviceFileEscaped="$(systemd-escape "$serviceFile")" # TODO:: verify works
serviceFileEscaped="$serviceFile"
cp "$packageInstallerSrc/$serviceFile" "$packageDebDir/etc/systemd/system/$serviceFileEscaped"
sed -i "s/\${version}/$pluginVersion/" "$packageDebDir/etc/systemd/system/$serviceFileEscaped"
serviceFiles+=("$serviceFileEscaped")
done
cp "$packageInstallerSrc/50-plugin-$curPackage.json" "$packageDebDir/etc/oqm/config/configs/"
if [ -f "$packageInstallerSrc/$curPackage-snapshot-restore.sh" ]; then
mkdir -p "$packageDebDir/etc/oqm/snapshots/scripts/"
cp "$packageInstallerSrc/$curPackage-snapshot-restore.sh" "$packageDebDir/etc/oqm/snapshots/scripts/"
fi
if [ -f "$packageInstallerSrc/infra-$curPackage-proxy-config.json" ]; then
mkdir -p "$packageDebDir/etc/oqm/proxyConfig.d/"
cp "$packageInstallerSrc/infra-$curPackage-proxy-config.json" "$packageDebDir/etc/oqm/proxyConfig.d/"
fi
if [ -f "$packageInstallerSrc/plugin-$curPackage-client.json" ]; then
mkdir -p "$packageDebDir/etc/oqm/kcClients/"
cp "$packageInstallerSrc/plugin-$curPackage-client.json" "$packageDebDir/etc/oqm/kcClients/"
fi
# TODO:: license information https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
# https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
cat <<EOT >> "$packageDebDir/DEBIAN/control"
Package: $(cat "$packageConfigFile" | jq -r '.packageName')
Version: $pluginVersion
Section: Open QuarterMaster
Maintainer: $(cat "$mainConfigFile" | jq -r '.maintainer.name')
Developer: EBP
Architecture: all
Description: $(cat "$packageConfigFile" | jq -r '.description')
Homepage: $(cat "$packageConfigFile" | jq -r '.homepage')
Depends: docker, docker.io, open+quarter+master-manager-station+captain (>= 2.0.0)$(cat "$packageConfigFile" | jq -r '.dependencies.deb')
EOT
cat <<EOT >> "$packageDebDir/DEBIAN/copyright"
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: $(cat "$packageConfigFile" | jq -r '.packageName')
Upstream-Contact: $(cat "$mainConfigFile" | jq -r '.copyright.contact')
Source: $(cat "$packageConfigFile" | jq -r '.homepage')
Files: *
Copyright: $(cat "$mainConfigFile" | jq -r '.copyright.copyright')
License: $(cat "$mainConfigFile" | jq -r '.copyright.licence')
EOT
cat <<EOT >> "$packageDebDir/DEBIAN/preinst"
#!/bin/bash
EOT
chmod +x "$packageDebDir/DEBIAN/preinst"
cat <<EOT >> "$packageDebDir/DEBIAN/postinst"
#!/bin/bash
EOT
chmod +x "$packageDebDir/DEBIAN/postinst"
cat <<EOT >> "$packageDebDir/DEBIAN/prerm"
#!/bin/bash
EOT
chmod +x "$packageDebDir/DEBIAN/prerm"
cat <<EOT >> "$packageDebDir/DEBIAN/postrm"
#!/bin/bash
EOT
chmod +x "$packageDebDir/DEBIAN/postrm"
if [ ${#serviceFiles[@]} -ne 0 ]; then
cat <<EOT >> "$packageDebDir/DEBIAN/postinst"
systemctl daemon-reload
systemctl enable ${serviceFiles[@]@Q}
systemctl start ${serviceFiles[@]@Q}
EOT
cat <<EOT >> "$packageDebDir/DEBIAN/prerm"
systemctl disable ${serviceFiles[@]@Q}
systemctl stop ${serviceFiles[@]@Q}
echo "Stopped ${serviceFiles[@]@Q}"
EOT
cat <<EOT >> "$packageDebDir/DEBIAN/postrm"
systemctl daemon-reload
EOT
fi
fileKeys=($(jq -r '.files | keys[]' "$packageConfigFile"))
for fileKey in ${fileKeys[@]}; do
curFile="$packageDebDir$fileKey"
mkdir -p "$(dirname "$curFile")"
fileInSrc="$(jq -r ".files.\"$fileKey\"" "$packageConfigFile")"
# echo "Config file content: $curConfigFileContent"
echo "Adding file: $fileInSrc to directory $fileKey";
cp -r "$packageInstallerSrc/$fileInSrc" "$curFile"
done;
dpkg-deb --build "$packageDebDir" "$buildDir"
#
# RPM build
#
done