moonfire-nvr/scripts/install.sh

127 lines
3.5 KiB
Bash
Raw Normal View History

#!/bin/bash
#
# This file is part of Moonfire NVR, a security camera network video recorder.
# Copyright (C) 2016-17 Scott Lamb <slamb@slamb.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the
# OpenSSL library under certain conditions as described in each
# individual source file, and distribute linked combinations including
# the two.
#
# You must obey the GNU General Public License in all respects for all
# of the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the
# file(s), but you are not obligated to do so. If you do not wish to do
# so, delete this exception statement from your version. If you delete
# this exception statement from all source files in the program, then
# also delete it here.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
. `dirname ${BASH_SOURCE[0]}`/script-functions.sh
# Determine directory path of this script
#
initEnvironmentVars
# Process command line options
#
while getopts ":s" opt; do
case $opt in
s) NO_SERVICE=1
;;
:)
echo_fatal "Option -$OPTARG requires an argument."
;;
\?)
echo_fatal "Invalid option: -$OPTARG"
;;
esac
done
sudo_warn
sudo install -m 755 target/release/moonfire-nvr ${SERVICE_BIN}
if [ -x "${SERVICE_BIN}" ]; then
echo_info -x "Server Binary installed..."
else
echo_info -x "Server build failed to install..."
exit 1
fi
if [ ! -d "${LIB_DIR}" ]; then
sudo mkdir "${LIB_DIR}"
fi
if [ -d "ui-dist" ]; then
sudo mkdir -p "${LIB_DIR}/ui"
sudo cp -R ui-dist/. "${LIB_DIR}/ui/"
echo_info -x "Server UI installed..."
else
echo_fatal -x "Server UI failed to build or install..."
fi
if [ "${NO_SERVICE:-0}" != 0 ]; then
echo_info -x "Not configuring systemctl service. Done"
exit 0
fi
# Make sure user was created
#
if ! userExists "${NVR_USER}"; then
echo_fatal -x "NVR_USER=${NVR_USER} was not created. Do so manually or run the setup script."
fi
pre_install_prep
# Prepare service files for socket when using priviliged port
#
SOCKET_SERVICE_PATH="/etc/systemd/system/${SERVICE_NAME}.socket"
if [ $NVR_PORT -lt 1024 ]; then
echo_fatal -x "NVR_PORT ($NVR_PORT) < 1024: priviliged ports not supported"
fi
# Prepare service files for moonfire
#
SERVICE_PATH="/etc/systemd/system/${SERVICE_NAME}.service"
sudo sh -c "cat > ${SERVICE_PATH}" <<NVR_EOF
[Unit]
Description=${SERVICE_DESC}
After=network-online.target
[Service]
ExecStart=${SERVICE_BIN} run \\
--db-dir=${DB_DIR} \\
--ui-dir=${LIB_DIR}/ui \\
--http-addr=0.0.0.0:${NVR_PORT} \\
--allow-unauthenticated-permissions='view_video: true'
Environment=TZ=:/etc/localtime
Environment=MOONFIRE_FORMAT=google-systemd
Environment=MOONFIRE_LOG=info
Environment=RUST_BACKTRACE=1
Type=simple
User=${NVR_USER}
Nice=-20
many improvements to install docs/procedures * in markdown files, use code fences rather than indented blocks. This is harder to screw up (one of them was off by a space so didn't render properly) and allows me to add info strings. * uniformly use "useradd" to create the user and group in all three places (install-manual.md, script-functions.sh, Dockerfile) rather than addgroup + adduser. Create a full home dir, which I suspect was the problem in #67. Don't allow customizing group name; it's always the same as the user. * install the sqlite3 package so that the "moonfire-nvr sql" command works properly. * remove "setup_db" function, which was out of place. Since the creation of the "moonfire-nvr init" command, this has to happen after installation of the binary. install.md gives instructions on this part anyway so remove it from the script. * give a proper command to create the db dir. It was creating it within the current directory, not within /var/lib/moonfire-nvr. Don't bother creating sample directory; "moonfire-nvr config" will do this. * when setting owners on a newly created directory, use a single "install -d" command rather than "mkdir" + "chown". * address confusion about whether sample file dirs need to be precreated. (Only when Moonfire NVR doesn't have write permissions on the parent.) * always just install the packaged version of ffmpeg rather than building our own. This has been usable since Debian/Raspbian 9 Stretch; Debian/Raspbian 10 Buster is out now so there's no excuse for still running Debian/Raspbian 8 Jessie. * don't chown the UI directory; it can be owned by root as with the binary. * in scripts/install.sh, don't enable/start the service yet. It hasn't been configured.
2019-07-10 02:48:06 -04:00
Restart=on-failure
CPUAccounting=true
MemoryAccounting=true
BlockIOAccounting=true
[Install]
WantedBy=multi-user.target
NVR_EOF
many improvements to install docs/procedures * in markdown files, use code fences rather than indented blocks. This is harder to screw up (one of them was off by a space so didn't render properly) and allows me to add info strings. * uniformly use "useradd" to create the user and group in all three places (install-manual.md, script-functions.sh, Dockerfile) rather than addgroup + adduser. Create a full home dir, which I suspect was the problem in #67. Don't allow customizing group name; it's always the same as the user. * install the sqlite3 package so that the "moonfire-nvr sql" command works properly. * remove "setup_db" function, which was out of place. Since the creation of the "moonfire-nvr init" command, this has to happen after installation of the binary. install.md gives instructions on this part anyway so remove it from the script. * give a proper command to create the db dir. It was creating it within the current directory, not within /var/lib/moonfire-nvr. Don't bother creating sample directory; "moonfire-nvr config" will do this. * when setting owners on a newly created directory, use a single "install -d" command rather than "mkdir" + "chown". * address confusion about whether sample file dirs need to be precreated. (Only when Moonfire NVR doesn't have write permissions on the parent.) * always just install the packaged version of ffmpeg rather than building our own. This has been usable since Debian/Raspbian 9 Stretch; Debian/Raspbian 10 Buster is out now so there's no excuse for still running Debian/Raspbian 8 Jessie. * don't chown the UI directory; it can be owned by root as with the binary. * in scripts/install.sh, don't enable/start the service yet. It hasn't been configured.
2019-07-10 02:48:06 -04:00
sudo systemctl daemon-reload