diff --git a/Dockerfile b/Dockerfile index 442d963..6be52a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,8 @@ LABEL "repository"="https://github.com/ttionya/vaultwarden-backup" \ COPY scripts/*.sh /app/ RUN chmod +x /app/*.sh \ - && apk add --no-cache bash sqlite p7zip heirloom-mailx tzdata + && apk add --no-cache bash heirloom-mailx p7zip sqlite supercronic tzdata \ + && ln -sf /tmp/localtime /etc/localtime \ + && mkdir -m 777 /bitwarden ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index 470e2e7..7aa4dad 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -37,16 +37,13 @@ if [[ "$1" == "restore" ]]; then fi function configure_timezone() { - if [[ ! -f /etc/localtime || ! -f /etc/timezone ]]; then - cp -f "/usr/share/zoneinfo/${TIMEZONE}" /etc/localtime - echo "${TIMEZONE}" > /etc/timezone - fi + ln -sf "/usr/share/zoneinfo/${TIMEZONE}" /tmp/localtime } function configure_cron() { - local FIND_CRON_COUNT=$(crontab -l | grep -c 'backup.sh') - if [[ ${FIND_CRON_COUNT} -eq 0 ]]; then - echo "${CRON} bash /app/backup.sh > /dev/stdout" >> /etc/crontabs/root + local FIND_CRON_COUNT="$(grep -c 'backup.sh' "${CRON_CONFIG_FILE}" 2> /dev/null)" + if [[ "${FIND_CRON_COUNT}" -eq 0 ]]; then + echo "${CRON} bash /app/backup.sh" >> "${CRON_CONFIG_FILE}" fi } @@ -56,4 +53,4 @@ configure_timezone configure_cron # foreground run crond -crond -l 2 -f +supercronic -passthrough-logs -quiet "${CRON_CONFIG_FILE}" diff --git a/scripts/includes.sh b/scripts/includes.sh index 373a14e..a36eda4 100644 --- a/scripts/includes.sh +++ b/scripts/includes.sh @@ -1,6 +1,7 @@ #!/bin/bash ENV_FILE="/.env" +CRON_CONFIG_FILE="${HOME}/crontabs" BACKUP_DIR="/bitwarden/backup" RESTORE_DIR="/bitwarden/restore" RESTORE_EXTRACT_DIR="/bitwarden/extract"