-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage-simulation-service.sh
111 lines (88 loc) · 2.46 KB
/
package-simulation-service.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
#!/bin/bash
# makes the simulation-service deb package
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
WORK_DIR=$PWD
VER=$(cd $SCRIPT_DIR; git rev-parse --short HEAD)
PACKAGE_NAME="simulation-service-0.$VER-all"
OUT_DIR="$WORK_DIR/$PACKAGE_NAME"
cd $WORK_DIR
mkdir -p "$OUT_DIR/DEBIAN"
function tar_pipe() {
SRC="$1"
DEST="$2"
mkdir -p "$DEST"
ls "$SRC" | xargs tar -C "$SRC" -cf - | tar -C "$DEST" -xf -
}
tar_pipe "$SCRIPT_DIR/simulation-service-prototype" "$OUT_DIR"
cat <<EOF > "$OUT_DIR/DEBIAN/control"
Package: simulation-service
Version: 0.$VER
Architecture: all
Essential: no
Priority: optional
Depends: dronology, dronology-gcs
Maintainer: Michael Murphy
Description: Scripts and service units for running simulations
EOF
### postinst
cat <<EOF > "$OUT_DIR/DEBIAN/postinst"
#!/bin/bash
# postinst script for simulation-service
setup_dronology_user() {
if ! getent group dronology >/dev/null; then
addgroup --quiet --system dronology
fi
if ! getent passwd dronology >/dev/null; then
adduser \
--quiet \
--system \
--ingroup dronology \
--shell /usr/sbin/nologin \
--gecos "Dronology Service" \
--no-create-home \
--home /var/lib/dronology \
--disabled-login \
dronology
fi
}
setup_dronology_user
function setup_helper_script() {
chmod 555 "\$1"
chown root:root "\$1"
}
setup_helper_script "/usr/local/bin/simulator-cleanup"
setup_helper_script "/usr/local/bin/simulator-logs"
setup_helper_script "/usr/local/bin/simulator-start"
setup_helper_script "/usr/local/bin/simulator-stop"
function setup_env_file() {
chmod 664 "\$1"
chown dronology:dronology "\$1"
}
setup_env_file "/var/lib/dronology/simulator.env"
function setup_systemd_unit() {
chmod 664 "\$1"
chown root:root "\$1"
}
setup_systemd_unit "/etc/systemd/system/simulator.service"
setup_systemd_unit "/etc/systemd/system/simulator-cleanup.service"
setup_systemd_unit "/etc/systemd/system/simulator-cleanup.timer"
systemctl daemon-reload
EOF
chmod 755 "$OUT_DIR/DEBIAN/postinst"
### prerm
cat <<EOF >>"$OUT_DIR/DEBIAN/prerm"
#!/bin/bash
# prerm script for simulation-service
systemctl stop simulator.service
systemctl disable simulator-cleanup.timer
systemctl stop simulator-cleanup.timer
EOF
chmod 755 "$OUT_DIR/DEBIAN/prerm"
### postrm
cat <<EOF >"$OUT_DIR/DEBIAN/postrm"
#!/bin/bash
# postrm script for simulation-service
systemctl daemon-reload
EOF
chmod 755 "$OUT_DIR/DEBIAN/postrm"
dpkg-deb --build "$OUT_DIR"