From 9e55b47f77ff4d2771f48f11bf87994b15acd800 Mon Sep 17 00:00:00 2001 From: Ravinou Date: Sat, 23 Sep 2023 18:09:10 +0200 Subject: [PATCH] feat: add cronjobs to docker --- Dockerfile | 4 +++- docker-bw-init.sh | 7 +++++++ docs/sudoers/10-borgwarehouse | 9 --------- helpers/shells/deleteRepo.sh | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 docs/sudoers/10-borgwarehouse diff --git a/Dockerfile b/Dockerfile index be056d3..86c67fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,14 @@ FROM node:18-bookworm-slim RUN apt-get update && \ - apt-get install -y curl git jq borgbackup openssh-server sudo && \ + apt-get install -y curl git jq jc borgbackup openssh-server sudo cron && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* RUN echo "borgwarehouse ALL=(ALL) NOPASSWD: /usr/sbin/service ssh restart" >> /etc/sudoers +RUN echo "borgwarehouse ALL=(ALL) NOPASSWD: /usr/sbin/service cron restart" >> /etc/sudoers + RUN groupadd borgwarehouse RUN useradd -m -g borgwarehouse borgwarehouse diff --git a/docker-bw-init.sh b/docker-bw-init.sh index 6fc9315..a621f06 100755 --- a/docker-bw-init.sh +++ b/docker-bw-init.sh @@ -40,11 +40,18 @@ check_repos_directory() { fi } +add_cron_job() { + local CRON_JOB="* * * * * curl --request POST --url 'http://localhost:3000/api/cronjob/checkStatus' --header 'Authorization: Bearer $CRONJOB_KEY'; curl --request POST --url 'http://localhost:3000/api/cronjob/getStorageUsed' --header 'Authorization: Bearer $CRONJOB_KEY'" + echo "$CRON_JOB" | crontab -u borgwarehouse - +} + init_ssh_server check_ssh_directory create_authorized_keys_file check_repos_directory +add_cron_job sudo service ssh restart +sudo service cron restart exec "$@" \ No newline at end of file diff --git a/docs/sudoers/10-borgwarehouse b/docs/sudoers/10-borgwarehouse deleted file mode 100644 index 4857f17..0000000 --- a/docs/sudoers/10-borgwarehouse +++ /dev/null @@ -1,9 +0,0 @@ -borgwarehouse ALL=(ALL) NOPASSWD: /usr/sbin/userdel -rf [[\:xdigit\:]]* -borgwarehouse ALL=(ALL) NOPASSWD: /usr/sbin/useradd -d /var/borgwarehouse/[[\:xdigit\:]]* -s /bin/bash -m --badname [[\:xdigit\:]]* -borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/mkdir -p /var/borgwarehouse/[[\:xdigit\:]]*/repos/repo[[\:digit\:]]*, /usr/bin/mkdir -p /var/borgwarehouse/[[\:xdigit\:]]*/.ssh -borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/touch /var/borgwarehouse/[[\:xdigit\:]]*/.ssh/authorized_keys -borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/chmod -R 750 /var/borgwarehouse/[[\:xdigit\:]]*, /usr/bin/chmod 600 /var/borgwarehouse/[[\:xdigit\:]]*/.ssh/authorized_keys -borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/chown -R [[\:xdigit\:]]*\:borgwarehouse /var/borgwarehouse/[[\:xdigit\:]]* -borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/tee /var/borgwarehouse/[[\:xdigit\:]]*/.ssh/authorized_keys -borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/sed -ri s|*|g /var/borgwarehouse/[[\:xdigit\:]]*/.ssh/authorized_keys -borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/du -s -- [[\:xdigit\:]]* diff --git a/helpers/shells/deleteRepo.sh b/helpers/shells/deleteRepo.sh index 62ca7ad..8883193 100755 --- a/helpers/shells/deleteRepo.sh +++ b/helpers/shells/deleteRepo.sh @@ -34,7 +34,7 @@ if [ ${#repositoryName} != 8 ]; then fi # Delete the repository and the line associated in the authorized_keys file -if [ -d "$1" ]; then +if [ -d "${pool}/${repositoryName}" ]; then # Delete the repository rm -rf "${pool}/${repositoryName}" # Delete the line in the authorized_keys file