From 9cdfbff2bc874509c23f4285f3f1f9d6adc0d7f4 Mon Sep 17 00:00:00 2001 From: Matteo Ruina Date: Wed, 9 Jun 2021 22:55:23 +0200 Subject: [PATCH] Create cronjob from entrypoint --- Dockerfile | 3 --- entrypoint.sh | 15 ++++++++++++++- withings-sync | 1 - 3 files changed, 14 insertions(+), 5 deletions(-) delete mode 100644 withings-sync diff --git a/Dockerfile b/Dockerfile index 0e999e7..d41d610 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,9 +15,6 @@ RUN apt-get update && \ pip install --no-cache-dir git+https://github.com/jaroslawhartman/withings-sync.git@"${WITHINGS_SYNC_COMMIT}" COPY entrypoint.sh /entrypoint.sh -COPY withings-sync /etc/cron.d/withings-sync - -RUN chmod 0644 /etc/cron.d/withings-sync ENTRYPOINT ["/tini", "--"] CMD ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index 0a94b1b..524f599 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,6 +2,11 @@ set -eu +garmin_username="${GARMIN_USERNAME:-UNSET}" +garmin_password="${GARMIN_PASSWORD:-UNSET}" +env_file="/root/env.sh" +cron_file="/etc/cron.d/withings-sync" + # trap ctrl-c and call ctrl_c() trap ctrl_c INT @@ -14,7 +19,15 @@ echo "Starting cron..." /etc/init.d/cron start echo "Setting environment variables for cron..." -printenv | sed 's/^\(.*\)$/export \1/g' > /root/cron_env.sh +touch "${env_file}" +echo "export GARMIN_USERNAME=${garmin_username}" >> "${env_file}" +echo "export GARMIN_PASSWORD=${garmin_password}" >> "${env_file}" + +echo "Setting up cronjob..." +cat << EOF > "${cron_file}" +0 10 * * * root . "${env_file}"; /usr/local/bin/withings-sync -v >> /var/log/withings-sync.log 2>&1 +EOF +chmod 0644 "${cron_file}" while true; do diff --git a/withings-sync b/withings-sync deleted file mode 100644 index f106f27..0000000 --- a/withings-sync +++ /dev/null @@ -1 +0,0 @@ -0 10 * * * root . /root/cron_env.sh; /usr/local/bin/withings-sync -v >> /var/log/cron-withings-sync.log 2>&1