|
Bogdan Timofte
authored
3 weeks ago
|
1
|
#!/usr/bin/env bash
|
|
|
2
|
|
|
|
3
|
set -euo pipefail
|
|
|
4
|
|
|
|
5
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
6
|
APP_NAME="rpi-camera-importer"
|
|
|
7
|
BIN_PATH="/usr/local/bin/${APP_NAME}"
|
|
|
8
|
RUNTIME_DIR="/usr/local/lib/${APP_NAME}"
|
|
|
9
|
CONFIG_DIR="/etc/rpi-camera-importer"
|
|
|
10
|
CONFIG_FILE="${CONFIG_DIR}/cameras.conf"
|
|
|
11
|
UDEV_RULE="/etc/udev/rules.d/99-rpi-camera-importer.rules"
|
|
|
12
|
ATTACH_UNIT="/etc/systemd/system/rpi-camera-importer-attach@.service"
|
|
|
13
|
|
|
|
14
|
require_root() {
|
|
|
15
|
if [[ "${EUID}" -ne 0 ]]; then
|
|
|
16
|
echo "This script must run as root"
|
|
|
17
|
exit 1
|
|
|
18
|
fi
|
|
|
19
|
}
|
|
|
20
|
|
|
|
21
|
install_dependencies() {
|
|
|
22
|
echo "Dependency installation at deploy is disabled."
|
|
|
23
|
echo "Dependencies are checked at runtime by rpi-camera-importer."
|
|
|
24
|
}
|
|
|
25
|
|
|
|
26
|
install_files() {
|
|
|
27
|
install -d /usr/local/bin
|
|
|
28
|
install -d "$RUNTIME_DIR"
|
|
|
29
|
install -d "$CONFIG_DIR"
|
|
|
30
|
|
|
|
31
|
install -m 0755 "${SCRIPT_DIR}/scripts/rpi-camera-importer.sh" "$BIN_PATH"
|
|
|
32
|
install -m 0755 "${SCRIPT_DIR}/scripts/rpi-camera-disk-handler.sh" "${RUNTIME_DIR}/rpi-camera-disk-handler.sh"
|
|
|
33
|
install -m 0755 "${SCRIPT_DIR}/scripts/rpi-camera-udev-wrapper.sh" "${RUNTIME_DIR}/rpi-camera-udev-wrapper.sh"
|
|
|
34
|
install -m 0755 "${SCRIPT_DIR}/scripts/autonas-media-importer.sh" "${RUNTIME_DIR}/autonas-media-importer.sh"
|
|
|
35
|
|
|
|
36
|
if [[ ! -f "$CONFIG_FILE" ]]; then
|
|
|
37
|
install -m 0644 "${SCRIPT_DIR}/config/cameras.conf" "$CONFIG_FILE"
|
|
|
38
|
else
|
|
|
39
|
echo "Config already exists, preserving: $CONFIG_FILE"
|
|
|
40
|
fi
|
|
|
41
|
|
|
|
42
|
install -m 0644 "${SCRIPT_DIR}/config/99-rpi-camera-importer.rules" "$UDEV_RULE"
|
|
|
43
|
install -m 0644 "${SCRIPT_DIR}/config/rpi-camera-importer-attach@.service" "$ATTACH_UNIT"
|
|
|
44
|
}
|
|
|
45
|
|
|
|
46
|
activate() {
|
|
|
47
|
systemctl daemon-reload
|
|
|
48
|
udevadm control --reload-rules
|
|
|
49
|
udevadm trigger --subsystem-match=block --action=add
|
|
|
50
|
}
|
|
|
51
|
|
|
|
52
|
main() {
|
|
|
53
|
require_root
|
|
|
54
|
install_dependencies
|
|
|
55
|
install_files
|
|
|
56
|
activate
|
|
|
57
|
|
|
|
58
|
echo "Installed ${APP_NAME}"
|
|
|
59
|
echo "Wizard: ${APP_NAME} wizard"
|
|
|
60
|
echo "Logs: journalctl -u rpi-camera-importer-attach@<UUID>.service -f"
|
|
|
61
|
}
|
|
|
62
|
|
|
|
63
|
main "$@"
|