forked from jo-hannes/craftbeerpi_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·50 lines (41 loc) · 1.43 KB
/
install.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
#!/bin/bash
# SPDX-License-Identifier: MIT
# Copyright 2021 Johannes Eigner <[email protected]>
# Install craftbeerpi_exporter on your system
set -e
# main
function main
{
readonly destPath="/usr/bin/"
readonly systemdUnitDir="/etc/systemd/system/"
# check if we have root rights
if [[ $EUID -ne 0 ]]; then
echo "Error: This script must be run as root"
exit 1
fi
# check if destination path exists
if [[ ! -d "${destPath}" ]]; then
echo "Error: Target directory '${destPath}' does not exist"
echo " You may need to create it first with:"
echo " mkdir -p ${destPath}"
exit 1
fi
# install required packages
# shellcheck disable=SC2046
apt install $(grep -v '#' requirementsDebian.txt)
# install the exporter
install -o root -g root -m 0755 craftbeerpi_exporter.py "${destPath}/craftbeerpi_exporter"
# install systemd service file
install -o root -g root -m 0755 craftbeerpi_exporter.service "${systemdUnitDir}/craftbeerpi_exporter.service"
# add extra options
if [[ $# -gt 0 ]]; then
sed -i "/ExecStart/s/$/ $*/" "${systemdUnitDir}/craftbeerpi_exporter.service"
fi
# enable and install craftbeerpi_exporter.service
systemctl daemon-reload
systemctl enable craftbeerpi_exporter.service
systemctl start craftbeerpi_exporter.service
echo "craftbeerpi_exporter successfully installed"
exit 0
}
main "$@"