Rework run script to support db mount better

This commit is contained in:
Aaron Reisman 2024-10-21 14:02:52 -05:00
parent ade693bebb
commit ac8c090c4c

View File

@ -13,7 +13,9 @@ info() {
} }
debug() { debug() {
if [ "${LOG_LEVEL}" = "debug" ]; then
log "debug" "$1" log "debug" "$1"
fi
} }
log() { log() {
@ -45,6 +47,26 @@ update_settings() {
mv ${LIBATION_CONFIG_INTERNAL}/${FILE}.tmp ${LIBATION_CONFIG_INTERNAL}/${FILE} mv ${LIBATION_CONFIG_INTERNAL}/${FILE}.tmp ${LIBATION_CONFIG_INTERNAL}/${FILE}
} }
is_mounted() {
DIR=$1
return $(mount | grep ${DIR})
}
create_db() {
FILE=$1
if [ -f "${FILE}" ]; then
warn "prexisting database found when creating"
return 0
else
warn "database not found, creating one at ${FILE}"
if ! touch "${FILE}"; then
error "unable to create database, check permissions on host"
exit 1
fi
return 1
fi
}
run() { run() {
info "scanning accounts" info "scanning accounts"
/libation/LibationCli scan /libation/LibationCli scan
@ -68,28 +90,31 @@ main() {
update_settings Settings.json Books /data update_settings Settings.json Books /data
update_settings Settings.json InProgress /tmp update_settings Settings.json InProgress /tmp
# If user provides a separate database use that
info "loading database" info "loading database"
FILE=LibationContext.db FILE=LibationContext.db
# If user provides a separate database mount, use that
if [ is_mounted ${LIBATION_DB_DIR} ];
then
debug using database directory `${LIBATION_DB_DIR}`
if [ -f "${LIBATION_DB_DIR}/${FILE}" ]; then if [ -f "${LIBATION_DB_DIR}/${FILE}" ]; then
info "database found in ${LIBATION_DB_DIR}" info "database found in ${LIBATION_DB_DIR}"
ln -s /${LIBATION_DB_DIR}/${FILE} ${LIBATION_CONFIG_INTERNAL}/${FILE}
# If user provides database in config use that
elif [ -f "${LIBATION_CONFIG_DIR}/${FILE}" ]; then
info "database found in ${LIBATION_CONFIG_DIR}"
ln -s /${LIBATION_CONFIG_DIR}/${FILE} ${LIBATION_CONFIG_INTERNAL}/${FILE}
# We didn't get a database
else else
warn "no database found, creating one in ${LIBATION_CONFIG_DIR}" create_db ${LIBATION_DB_DIR}/${FILE}
if ! touch ${LIBATION_CONFIG_DIR}/${FILE}; then
error "unable to create database, check permissions on host"
exit 1
fi fi
ln -s ${LIBATION_CONFIG_DIR}/${FILE} ${LIBATION_CONFIG_INTERNAL}/${FILE} ln -s /${LIBATION_DB_DIR}/${FILE} ${LIBATION_CONFIG_INTERNAL}/${FILE}
# Otherwise, use the config directory
else
debug using config directory `${LIBATION_CONFIG_DIR}`
if [ -f "${LIBATION_CONFIG_DIR}/${FILE}" ]; then
info "database found in ${LIBATION_CONFIG_DIR}"
else
create_db ${LIBATION_CONFIG_DIR}/${FILE}
fi
ln -s /${LIBATION_CONFIG_DIR}/${FILE} ${LIBATION_CONFIG_INTERNAL}/${FILE}
fi fi
# Try to warn if books dir wasn't mounted in # Try to warn if books dir wasn't mounted in
if [ -z "$(mount | grep ${LIBATION_BOOKS_DIR})" ] if [ ! is_mounted ${LIBATION_BOOKS_DIR} ];
then then
warn "${LIBATION_BOOKS_DIR} does not appear to be mounted, books will not be saved" warn "${LIBATION_BOOKS_DIR} does not appear to be mounted, books will not be saved"
fi fi