-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmakeInstallers.sh
executable file
·150 lines (119 loc) · 4.19 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
#!/bin/bash
#
# Script to make installers for OQM- Base Station.
#
# Intended to be run from the dir this resides
#
# Author: Greg Stewart
#
# Requires packages:
# Ubuntu:
# - dpkg-dev
# - rpm
# - rpmlint
# - jq
#
# TODO:: Figure out how logs work
cd "$(dirname "$0")" || exit
srcDir="installerSrc"
configFile="$srcDir/installerProperties.json"
buildDir="build/installers"
debDir="oqmCoreAPiDeb"
#
# Clean
#
rm -rf "$buildDir"
#
# Setup
#
mkdir -p "$buildDir"
#
# Debian build
#
mkdir "$buildDir/$debDir"
mkdir "$buildDir/$debDir/DEBIAN"
mkdir -p "$buildDir/$debDir/etc/systemd/system/"
mkdir -p "$buildDir/$debDir/etc/oqm/static/core/api/"
mkdir -p "$buildDir/$debDir/etc/oqm/serviceConfig/core/api/"
mkdir -p "$buildDir/$debDir/etc/oqm/config/configs/"
mkdir -p "$buildDir/$debDir/etc/oqm/proxyConfig.d/"
mkdir -p "$buildDir/$debDir/usr/share/applications"
install -m 755 -D "$srcDir/uiEntry.json" "$buildDir/$debDir/etc/oqm/static/core/api/"
install -m 755 -D "$srcDir/core-api-config.list" "$buildDir/$debDir/etc/oqm/serviceConfig/core/api/"
install -m 755 -D "$srcDir/20-coreApi.json" "$buildDir/$debDir/etc/oqm/config/configs/"
install -m 755 -D "$srcDir/core-api-proxy-config.json" "$buildDir/$debDir/etc/oqm/proxyConfig.d/"
serviceFile="oqm-core-api.service"
serviceFileEscaped="$serviceFile" # "$(systemd-escape "$serviceFile")"
cp "$srcDir/$serviceFile" "$buildDir/$debDir/etc/systemd/system/$serviceFileEscaped"
sed -i "s/\${version}/$(./gradlew -q printVersion)/" "$buildDir/$debDir/etc/systemd/system/$serviceFileEscaped"
# 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 >> "$buildDir/$debDir/DEBIAN/control"
Package: $(cat "$configFile" | jq -r '.packageName')
Version: $(./gradlew -q printVersion)
Section: Open QuarterMaster
Maintainer: $(cat "$configFile" | jq -r '.maintainer.name')
Architecture: all
Description: $(cat "$configFile" | jq -r '.description')
Homepage: $(cat "$configFile" | jq -r '.homepage')
Depends: $(cat "$configFile" | jq -r '.dependencies.deb')
Licence: $(cat "$configFile" | jq -r '.copyright.licence')
EOT
cat <<EOT >> "$buildDir/$debDir/DEBIAN/copyright"
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Open QuarterMaster Core API
Upstream-Contact: $(cat "$configFile" | jq -r '.copyright.contact')
Source: $(cat "$configFile" | jq -r '.homepage')
Files: *
Copyright: $(cat "$configFile" | jq -r '.copyright.copyright')
License: $(cat "$configFile" | jq -r '.copyright.licence')
EOT
cat <<EOT >> "$buildDir/$debDir/DEBIAN/preinst"
#!/bin/bash
mkdir -p /etc/oqm/serviceConfig/core/api/files/
if [ ! -f "/etc/oqm/serviceConfig/core/api/user-config.list" ]; then
cat <<EOF >> "/etc/oqm/serviceConfig/core/api/user-config.list"
# Add your own config here.
# Configuration here will override those in core-api-config.list
# Reference: https://github.com/Epic-Breakfast-Productions/OpenQuarterMaster/blob/main/software/oqm-core-api/docs/BuildingAndDeployment.adoc
EOF
fi
EOT
chmod +x "$buildDir/$debDir/DEBIAN/preinst"
cat <<EOT >> "$buildDir/$debDir/DEBIAN/postinst"
#!/bin/bash
systemctl daemon-reload
# restart proxy after we add config
systemctl enable "$serviceFileEscaped"
systemctl start "$serviceFileEscaped"
EOT
chmod +x "$buildDir/$debDir/DEBIAN/postinst"
cat <<EOT >> "$buildDir/$debDir/DEBIAN/prerm"
#!/bin/bash
systemctl disable "$serviceFileEscaped"
systemctl stop "$serviceFileEscaped"
EOT
chmod +x "$buildDir/$debDir/DEBIAN/prerm"
cat <<EOT >> "$buildDir/$debDir/DEBIAN/postrm"
#!/bin/bash
systemctl daemon-reload
# Remove docker image
if [[ "$(docker images -q oqm-core-api 2> /dev/null)" != "" ]]; then
docker rmi oqm-core-api
echo "Removed docker image."
else
echo "Docker image was already gone."
fi
if [ $( docker ps -a | grep oqm-core-api | wc -l ) -gt 0 ]; then
docker rm oqm-core-api
echo "Removed docker container."
else
echo "Docker container was already gone."
fi
#systemctl restart "open\\x2bquarter\\x2bmaster\\x2dinfra\\x2dnginx.service"
EOT
chmod +x "$buildDir/$debDir/DEBIAN/postrm"
dpkg-deb --build "$buildDir/$debDir" "$buildDir"
#
# RPM build
#