diff --git a/Docker/liberate.sh b/Docker/liberate.sh index 9991b1eb..40ef534a 100755 --- a/Docker/liberate.sh +++ b/Docker/liberate.sh @@ -13,7 +13,9 @@ info() { } debug() { - log "debug" "$1" + if [ "${LOG_LEVEL}" = "debug" ]; then + log "debug" "$1" + fi } log() { @@ -45,6 +47,26 @@ update_settings() { 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() { info "scanning accounts" /libation/LibationCli scan @@ -68,28 +90,31 @@ main() { update_settings Settings.json Books /data update_settings Settings.json InProgress /tmp - # If user provides a separate database use that info "loading database" FILE=LibationContext.db - if [ -f "${LIBATION_DB_DIR}/${FILE}" ]; then - 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 - warn "no database found, creating one in ${LIBATION_CONFIG_DIR}" - if ! touch ${LIBATION_CONFIG_DIR}/${FILE}; then - error "unable to create database, check permissions on host" - exit 1 + # 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 + info "database found in ${LIBATION_DB_DIR}" + else + create_db ${LIBATION_DB_DIR}/${FILE} 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 # Try to warn if books dir wasn't mounted in - if [ -z "$(mount | grep ${LIBATION_BOOKS_DIR})" ] + if [ ! is_mounted ${LIBATION_BOOKS_DIR} ]; then warn "${LIBATION_BOOKS_DIR} does not appear to be mounted, books will not be saved" fi