address setup_db bitrot (#58)

This commit is contained in:
Scott Lamb 2018-05-01 07:31:38 -07:00
parent f2888e2b32
commit 23b221c5ed

View File

@ -150,7 +150,6 @@ initEnvironmentVars()
if [ -r "${MOONFIRE_DIR}/prep.config" ]; then if [ -r "${MOONFIRE_DIR}/prep.config" ]; then
. "${MOONFIRE_DIR}/prep.config" . "${MOONFIRE_DIR}/prep.config"
fi fi
SRC_DIR="$(resolvePath "$MOONFIRE_DIR/src")"
NVR_USER="${NVR_USER:-moonfire-nvr}" NVR_USER="${NVR_USER:-moonfire-nvr}"
NVR_GROUP="${NVR_GROUP:-$NVR_USER}" NVR_GROUP="${NVR_GROUP:-$NVR_USER}"
NVR_PORT="${NVR_PORT:-8080}" NVR_PORT="${NVR_PORT:-8080}"
@ -281,16 +280,12 @@ sudo_warn()
# #
setup_db() setup_db()
{ {
DB_NAME=${1:-db}
if [ ! -d "${DB_DIR}" ]; then if [ ! -d "${DB_DIR}" ]; then
echo_info -x 'Create database directory...' echo_info -x 'Create database directory...'
mkdir_moonfire -p "${DB_DIR}" mkdir_moonfire -p "${DB_DIR}"
fi fi
DB_PATH="${DB_DIR}/${DB_NAME}" echo_info -x 'Ensure database is initialized...'
if [ ! -f "${DB_PATH}" ]; then sudo -u "${NVR_USER}" -H -- "${SERVICE_BIN}" init --db-dir="${DB_DIR}"
echo_info -x 'Create database and initialize...'
sudo -u "${NVR_USER}" -H sqlite3 "${DB_PATH}" < "${SRC_DIR}/schema.sql"
fi
} }
# Make sure all sample directories and files owned by moonfire # Make sure all sample directories and files owned by moonfire
@ -362,7 +357,7 @@ fix_localtime()
pre_install_prep() pre_install_prep()
{ {
prep_moonfire_user prep_moonfire_user
setup_db db setup_db
prep_sample_file_dir prep_sample_file_dir
fix_localtime fix_localtime
} }