11#! /bin/bash
22
33action=$1
4+ single=$2
45
5- systemctl $action " camera-streamer-libcamera.service"
6+ [ -n " $single " ] || systemctl $action " camera-streamer-libcamera.service"
67
78# iterate over all the camera confs in /boot/camera-streamer
89for conf in /boot/camera-streamer/* .conf; do
@@ -14,7 +15,47 @@ for conf in /boot/camera-streamer/*.conf; do
1415 # get the name of the camera
1516 name=$( basename " $conf " .conf)
1617
17- # enable the camera
18- systemctl $action " camera-streamer-usb@$name .path"
18+ if [[ " $single " != " " ]] && [[ " $single " != " $name " ]]; then
19+ # if we are only doing a single camera, skip the others
20+ continue
21+ fi
22+
23+ source $conf
24+
25+ if [[ " $action " == " start" ]] || [[ " $action " == " restart" ]]; then
26+ # generate some additional files/config if we are starting this for the first time
27+ reload=" no"
28+
29+ # Add runtime path unit file that starts the service when the device is plugged in
30+ path_dir=" /run/systemd/system"
31+ if [[ ! -e " $path_dir /camera-streamer-usb-$name .path" ]] || [[ ! $( grep -q " PathExists=$DEVICE " " $path_dir /camera-streamer-usb-$name .path" ) ]]; then
32+ cat > " $path_dir /camera-streamer-usb-$name .path" << EOF
33+ [Unit]
34+ Description=camera-streamer $name autolaunch
35+ After=network.target
36+
37+ [Path]
38+ PathExists=$DEVICE
39+ Unit=camera-streamer-usb@$name .service
40+ EOF
41+ reload=" yes"
42+ fi
43+
44+ # Add path dependency to service file via runtime override
45+ override_dir=" /run/systemd/system/camera-streamer-usb@$name .service.d"
46+ override_conf=" $override_dir /override.conf"
47+ if [[ ! -e " $override_conf " ]] || [[! $( grep -q " ConditionPathExists=$DEVICE " " $override_conf " ) ]]; then
48+ mkdir -p " $override_dir "
49+ cat > " $override_conf " << EOF
50+ [Unit]
51+ ConditionPathExists=$DEVICE
52+ EOF
53+ reload=" yes"
54+ fi
55+ [[ " $reload " == " yes" ]] && systemctl daemon-reload || true
56+ fi
57+
58+ # do the action
59+ systemctl $action " camera-streamer-usb-$name .path"
1960 systemctl $action " camera-streamer-usb@$name .service"
2061done
0 commit comments