This repository has been archived by the owner on Mar 15, 2019. It is now read-only.
forked from pducharme/UniFi-Video-Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
104 lines (82 loc) · 2.77 KB
/
run.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
#!/bin/bash
set -e
# Options fed into unifi-video script
unifi_video_opts=""
# Graceful shutdown, used by trapping SIGTERM
function graceful_shutdown {
echo -n "Stopping unifi-video... "
if /usr/sbin/unifi-video --nodetach stop; then
echo "done."
exit 0
else
echo "failed."
exit 1
fi
}
# Trap SIGTERM for graceful exit
trap graceful_shutdown SIGTERM
# Change user nobody's UID to custom or match unRAID.
export PUID
PUID=$(echo "${PUID}" | sed -e 's/^[ \t]*//')
if [[ ! -z "${PUID}" ]]; then
echo "[info] PUID defined as '${PUID}'" | ts '%Y-%m-%d %H:%M:%.S'
else
echo "[warn] PUID not defined (via -e PUID), defaulting to '99'" | ts '%Y-%m-%d %H:%M:%.S'
export PUID="99"
fi
# Set user unify-video to specified user id (non unique)
usermod -o -u "${PUID}" unifi-video &>/dev/null
# Change group users to GID to custom or match unRAID.
export PGID
PGID=$(echo "${PGID}" | sed -e 's/^[ \t]*//')
if [[ ! -z "${PGID}" ]]; then
echo "[info] PGID defined as '${PGID}'" | ts '%Y-%m-%d %H:%M:%.S'
else
echo "[warn] PGID not defined (via -e PGID), defaulting to '100'" | ts '%Y-%m-%d %H:%M:%.S'
export PGID="100"
fi
# Set group users to specified group id (non unique)
groupmod -o -g "${PGID}" unifi-video &>/dev/null
# Create logs directory
mkdir -p /var/lib/unifi-video/logs
# check for presence of perms file, if it exists then skip setting
# permissions, otherwise recursively set on volume mappings for host
if [[ ! -f "/var/lib/unifi-video/perms.txt" ]]; then
echo "[info] Setting permissions recursively on volume mappings..." | ts '%Y-%m-%d %H:%M:%.S'
volumes=( "/var/lib/unifi-video" )
set +e
chown -R "${PUID}":"${PGID}" "${volumes[@]}"
exit_code_chown=$?
find "${volumes[@]}" -type d -exec chmod 775 '{}' ';'
exit_code_chmod_dirs=$?
find "${volumes[@]}" -type f -exec chmod 664 '{}' ';'
exit_code_chmod_files=$?
set -e
if (( exit_code_chown != 0 || exit_code_chmod_dirs != 0 || exit_code_chmod_files != 0)); then
echo "[warn] Unable to chown/chmod ${volumes[*]}, assuming SMB mountpoint"
fi
echo "This file prevents permissions from being applied/re-applied to /config, if you want to reset permissions then please delete this file and restart the container." > /var/lib/unifi-video/perms.txt
else
echo "[info] Permissions already set for volume mappings" | ts '%Y-%m-%d %H:%M:%.S'
fi
set +e
# No debug mode set via env, default to off
if [[ -z ${DEBUG} ]]; then
DEBUG=0
fi
# Run with --debug if DEBUG=1
if [[ ${DEBUG} -eq 1 ]]; then
echo "[debug] Running unifi-video service with --debug."
unifi_video_opts="--debug"
fi
# Run the unifi-video daemon the unifi-video way
echo -n "Starting unifi-video... "
if /usr/sbin/unifi-video "${unifi_video_opts}" start; then
echo "done."
else
echo "failed."
exit 1
fi
while true; do
sleep 1
done