Merge branch 'master' into new-schema

This commit is contained in:
Scott Lamb
2019-07-10 00:59:42 -07:00
7 changed files with 105 additions and 198 deletions

View File

@@ -67,7 +67,6 @@ fi
if [ -d "ui-dist" ]; then
sudo mkdir -p "${LIB_DIR}/ui"
sudo cp -R ui-dist/. "${LIB_DIR}/ui/"
sudo chown -R ${NVR_USER}:${NVR_GROUP} "${LIB_DIR}/ui/"
echo_info -x "Server UI installed..."
else
echo_fatal -x "Server UI failed to build or install..."
@@ -115,7 +114,7 @@ Environment=RUST_BACKTRACE=1
Type=simple
User=${NVR_USER}
Nice=-20
Restart=on-abnormal
Restart=on-failure
CPUAccounting=true
MemoryAccounting=true
BlockIOAccounting=true
@@ -124,13 +123,4 @@ BlockIOAccounting=true
WantedBy=multi-user.target
NVR_EOF
# Configure and start service
#
if [ -f "${SERVICE_PATH}" ]; then
echo_info -x 'Configuring system daemon...'
sudo systemctl daemon-reload
sudo systemctl enable ${SERVICE_NAME}
sudo systemctl restart ${SERVICE_NAME}
echo_info -x 'Getting system daemon status...'
sudo systemctl status ${SERVICE_NAME}
fi
sudo systemctl daemon-reload

View File

@@ -41,8 +41,6 @@ NODE_MIN_VERSION="8"
YARN_MIN_VERSION="1.0"
CARGO_MIN_VERSION="0.2"
RUSTC_MIN_VERSION="1.34"
FFMPEG_MIN_VERSION="55.1.101"
FFMPEG_RELEASE_VERSION="3.4"
normalizeDirPath()
{
@@ -80,11 +78,6 @@ catPrefix()
sed -e "s/^/$2/" < "$1"
}
mkdir_moonfire()
{
sudo -u "${NVR_USER}" -H mkdir "$@"
}
echo_multi()
{
local prefix=''
@@ -151,7 +144,6 @@ initEnvironmentVars()
. "${MOONFIRE_DIR}/prep.config"
fi
NVR_USER="${NVR_USER:-moonfire-nvr}"
NVR_GROUP="${NVR_GROUP:-$NVR_USER}"
NVR_PORT="${NVR_PORT:-8080}"
NVR_HOME_BASE="${NVR_HOME_BASE:-/var/lib}"
NVR_HOME="${NVR_HOME_BASE}/${NVR_USER}"
@@ -244,23 +236,6 @@ userExists()
return $(id -u "$1" >/dev/null 2>&1)
}
groupExists()
{
return $(id -g "$1" >/dev/null 2>&1)
}
moonfire()
{
case "$1" in
start)
sudo systemctl start "$2"
;;
stop)
sudo systemctl stop "$2"
;;
esac
}
sudo_warn()
{
echo_warn -x -p '!!!!! ' \
@@ -271,48 +246,18 @@ sudo_warn()
'------------------------------------------------------------------------------'
}
# Prepare for sqlite directory and set schema into db
#
setup_db()
{
if [ ! -d "${DB_DIR}" ]; then
echo_info -x 'Create database directory...'
mkdir_moonfire -p "${DB_DIR}"
fi
echo_info -x 'Ensure database is initialized...'
sudo -u "${NVR_USER}" -H -- "${SERVICE_BIN}" init --db-dir="${DB_DIR}"
}
# Make sure all sample directories and files owned by moonfire
#
fix_ownership()
{
sudo chown -R ${NVR_USER}:${NVR_USER} "$1"
echo_info -x "Fix ownership of files in \"$1\"..."
}
# Create user and groups if not there
# Create user, group, and database directory if not there
#
prep_moonfire_user()
{
echo_info -x "Create user/group and directories we need..."
if ! groupExists "${NVR_GROUP}"; then
sudo addgroup --quiet --system ${NVR_GROUP}
fi
if ! userExists "${NVR_USER}"; then
sudo adduser --quiet --system ${NVR_USER} \
--ingroup "${NVR_GROUP}" --home "${NVR_HOME}"
sudo useradd --system ${NVR_USER} --user-group --create-home --home-dir "${NVR_HOME}"
fi
if [ ! -d "${NVR_HOME}" ]; then
sudo mkdir "${NVR_HOME}"
sudo chown "${NVR_USER}:${NVR_GROUP}" "${NVR_HOME}"
fi
sudo chown ${NVR_USER}:${NVR_GROUP} "${NVR_HOME}"
sudo -u ${NVR_USER} -H sh -c 'cd && test -d db || mkdir --mode=700 db'
}
pre_install_prep()
{
prep_moonfire_user
setup_db
}

View File

@@ -38,32 +38,21 @@ makePrepConfig
export DEBIAN_FRONTEND=noninteractive
# Process command line options
#
while getopts ":f" opt; do
case $opt in
f) DONT_BUILD_FFMPEG=1
;;
:)
echo_fatal "Option -$OPTARG requires an argument."
;;
\?)
echo_fatal -x "Invalid option: -$OPTARG"
;;
esac
done
sudo_warn
# Setup all apt packages we need
#
echo_info -x 'Preparing and downloading packages we need...'
PKGS="build-essential \
libavcodec-dev \
libavformat-dev \
libavutil-dev \
libncurses5-dev \
libncursesw5-dev \
libsqlite3-dev \
libssl-dev \
pkgconf \
sqlite3 \
tzdata"
# Add yarn before NodeSource so it can all go in one update
@@ -102,42 +91,6 @@ sudo apt-get install -y $PKGS
sudo apt-get autoremove -y
echo_info -x
# Check for ffmpeg and install by building if necessary
# This needs to be done before building moonfire so it can
# find the right versions of the libraries.
#
ffv=`ffmpeg -version 2>/dev/null | extractVersion libavutil`
ffv=${ffv:-0}
if ! versionAtLeast "$ffv" "$FFMPEG_MIN_VERSION"; then
if [ "${DONT_BUILD_FFMPEG:-0}" -ne 0 ]; then
echo_warn -x "ffmpeg version (${ffv}) installed is too old for moonfire." \
"Suggest you manually install at least version $FFMPEG_MIN_VERSION of libavutil." \
"ffmpeg versions 2.x and 3.x all should work."
else
OLDDIR=`pwd`
cd ..
if [ -d FFmpeg ]; then
echo_info -x "Removing older FFmpeg directory..."
rm -fr FFmpeg
fi
echo_info -x "Fetching FFmpeg source..."
git clone --depth 1 -b "release/${FFMPEG_RELEASE_VERSION}" https://github.com/FFmpeg/FFmpeg.git
cd FFmpeg
pt=`uname -p 2>/dev/null`
if [ -z "${pt##*86*}" ]; then
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y yasm
fi
./configure --enable-shared
make
sudo make install
sudo ldconfig
cd "$OLDDIR"
OLDDIR=
fi
else
echo_info -x "FFmpeg is already usable..."
fi
# If cargo appears installed, initialize for using it so rustc can be found
#
initCargo