rework database handling
This commit is contained in:
parent
9ed6c1fd0d
commit
e0dd9b845a
@ -32,7 +32,7 @@ init_config_file() {
|
|||||||
cp ${FULLPATH} ${LIBATION_CONFIG_INTERNAL}/
|
cp ${FULLPATH} ${LIBATION_CONFIG_INTERNAL}/
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
warn "${FULLPATH} not found, using defaults"
|
warn "${FULLPATH} not found, creating empty file"
|
||||||
echo "{}" > ${LIBATION_CONFIG_INTERNAL}/${FILE}
|
echo "{}" > ${LIBATION_CONFIG_INTERNAL}/${FILE}
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -63,7 +63,6 @@ create_db() {
|
|||||||
warn "prexisting database found when creating"
|
warn "prexisting database found when creating"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
warn "database not found, creating one at ${DBFILE}"
|
|
||||||
if ! touch "${DBFILE}"; then
|
if ! touch "${DBFILE}"; then
|
||||||
error "unable to create database, check permissions on host"
|
error "unable to create database, check permissions on host"
|
||||||
exit 1
|
exit 1
|
||||||
@ -72,6 +71,46 @@ create_db() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setup_db() {
|
||||||
|
DBPATH=$1
|
||||||
|
dbpattern="*.db"
|
||||||
|
|
||||||
|
debug "using database directory ${DBPATH}"
|
||||||
|
|
||||||
|
# Figure out the right databse file
|
||||||
|
if [[ -z "${LIBATION_DB_FILE}" ]];
|
||||||
|
then
|
||||||
|
dbCount=$(find "${DBPATH}" -type f -name "${dbpattern}" | wc -l)
|
||||||
|
if [ "${dbCount}" -gt 1 ];
|
||||||
|
then
|
||||||
|
error "too many database files found, set LIBATION_DB_FILE to the filename you wish to use"
|
||||||
|
exit 1
|
||||||
|
elif [ "${dbCount}" -eq 1 ];
|
||||||
|
then
|
||||||
|
files=( ${DBPATH}/${dbpattern} )
|
||||||
|
FILE=${files[0]}
|
||||||
|
else
|
||||||
|
FILE="${DBPATH}/LibationContext.db"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
FILE="${DBPATH}/${LIBATION_DB_FILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
debug "planning to use database ${FILE}"
|
||||||
|
|
||||||
|
if [ -f "${FILE}" ]; then
|
||||||
|
info "database found at ${FILE}"
|
||||||
|
elif [ ${LIBATION_CREATE_DB} = "true" ];
|
||||||
|
then
|
||||||
|
warn "database not found, creating one at ${FILE}"
|
||||||
|
create_db ${FILE}
|
||||||
|
else
|
||||||
|
error "database not found and creation is disabled"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
ln -s "${FILE}" "${LIBATION_CONFIG_INTERNAL}/LibationContext.db"
|
||||||
|
}
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
info "scanning accounts"
|
info "scanning accounts"
|
||||||
/libation/LibationCli scan
|
/libation/LibationCli scan
|
||||||
@ -89,27 +128,15 @@ main() {
|
|||||||
update_settings Settings.json InProgress /tmp
|
update_settings Settings.json InProgress /tmp
|
||||||
|
|
||||||
info "loading database"
|
info "loading database"
|
||||||
FILE=LibationContext.db
|
|
||||||
# If user provides a separate database mount, use that
|
# If user provides a separate database mount, use that
|
||||||
if is_mounted "${LIBATION_DB_DIR}";
|
if is_mounted "${LIBATION_DB_DIR}";
|
||||||
then
|
then
|
||||||
debug "using database directory ${LIBATION_DB_DIR}"
|
DB_LOCATION=${LIBATION_DB_DIR}
|
||||||
if [ -f "${LIBATION_DB_DIR}/${FILE}" ]; then
|
|
||||||
info "database found in ${LIBATION_DB_DIR}"
|
|
||||||
else
|
|
||||||
create_db ${LIBATION_DB_DIR}/${FILE}
|
|
||||||
fi
|
|
||||||
ln -s /${LIBATION_DB_DIR}/${FILE} ${LIBATION_CONFIG_INTERNAL}/${FILE}
|
|
||||||
# Otherwise, use the config directory
|
# Otherwise, use the config directory
|
||||||
else
|
else
|
||||||
debug "using config directory ${LIBATION_CONFIG_DIR}"
|
DB_LOCATION=${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
|
||||||
|
setup_db ${DB_LOCATION}
|
||||||
|
|
||||||
# Try to warn if books dir wasn't mounted in
|
# Try to warn if books dir wasn't mounted in
|
||||||
if ! is_mounted "${LIBATION_BOOKS_DIR}";
|
if ! is_mounted "${LIBATION_BOOKS_DIR}";
|
||||||
@ -122,7 +149,7 @@ main() {
|
|||||||
SLEEP_TIME=-1
|
SLEEP_TIME=-1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${SLEEP_TIME}" = -1 ]; then
|
if [ "${SLEEP_TIME}" -eq -1 ]; then
|
||||||
info "running once"
|
info "running once"
|
||||||
else
|
else
|
||||||
info "running every ${SLEEP_TIME}"
|
info "running every ${SLEEP_TIME}"
|
||||||
@ -134,7 +161,7 @@ main() {
|
|||||||
run
|
run
|
||||||
|
|
||||||
# Liberate only once if SLEEP_TIME was set to -1
|
# Liberate only once if SLEEP_TIME was set to -1
|
||||||
if [ "${SLEEP_TIME}" = -1 ]; then
|
if [ "${SLEEP_TIME}" -eq -1 ]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@ -22,8 +22,11 @@ ENV SLEEP_TIME=-1
|
|||||||
ENV LIBATION_CONFIG_INTERNAL=/config-internal
|
ENV LIBATION_CONFIG_INTERNAL=/config-internal
|
||||||
ENV LIBATION_CONFIG_DIR=/config
|
ENV LIBATION_CONFIG_DIR=/config
|
||||||
ENV LIBATION_DB_DIR=/db
|
ENV LIBATION_DB_DIR=/db
|
||||||
|
ENV LIBATION_DB_FILE=
|
||||||
|
ENV LIBATION_CREATE_DB=true
|
||||||
ENV LIBATION_BOOKS_DIR=/data
|
ENV LIBATION_BOOKS_DIR=/data
|
||||||
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get -y upgrade && \
|
RUN apt-get update && apt-get -y upgrade && \
|
||||||
apt-get install -y jq && \
|
apt-get install -y jq && \
|
||||||
mkdir -m777 ${LIBATION_CONFIG_INTERNAL} ${LIBATION_BOOKS_DIR}
|
mkdir -m777 ${LIBATION_CONFIG_INTERNAL} ${LIBATION_BOOKS_DIR}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user