From 7e21c7b379935ebd1befc4553f86d338db80580b Mon Sep 17 00:00:00 2001 From: Ravinou Date: Sat, 16 Sep 2023 19:23:29 +0200 Subject: [PATCH] fix: stop container if init failed --- Dockerfile | 2 +- docker-bw-init.sh | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 50fd771..2c2eafd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN useradd -m -g borgwarehouse borgwarehouse WORKDIR /home/borgwarehouse/app -RUN git clone -b v2.0 https://github.com/Ravinou/borgwarehouse.git . +COPY . . RUN chown -R borgwarehouse:borgwarehouse * .* diff --git a/docker-bw-init.sh b/docker-bw-init.sh index 3207e42..4114e10 100755 --- a/docker-bw-init.sh +++ b/docker-bw-init.sh @@ -1,24 +1,36 @@ #!/bin/bash +set -e + SSH_DIR="/home/borgwarehouse/.ssh" AUTHORIZED_KEYS_FILE="$SSH_DIR/authorized_keys" REPOS_DIR="/home/borgwarehouse/repos" -if [ ! -d "$SSH_DIR" ]; then - echo "The .ssh directory does not exist, creating..." - mkdir -p "$SSH_DIR" - chmod 700 "$SSH_DIR" -fi +create_ssh_directory() { + if [ ! -d "$SSH_DIR" ]; then + echo "The .ssh directory does not exist, creating..." + mkdir -p "$SSH_DIR" + chmod 700 "$SSH_DIR" + fi +} -if [ ! -f "$AUTHORIZED_KEYS_FILE" ]; then - echo "The authorized_keys file does not exist, creating..." - touch "$AUTHORIZED_KEYS_FILE" - chmod 600 "$AUTHORIZED_KEYS_FILE" -fi +create_authorized_keys_file() { + if [ ! -f "$AUTHORIZED_KEYS_FILE" ]; then + echo "The authorized_keys file does not exist, creating..." + touch "$AUTHORIZED_KEYS_FILE" + chmod 600 "$AUTHORIZED_KEYS_FILE" + fi +} -if [ ! -d "$REPOS_DIR" ]; then - echo "The repos directory does not exist, creating..." - mkdir -p "$REPOS_DIR" -fi +create_repos_directory() { + if [ ! -d "$REPOS_DIR" ]; then + echo "The repos directory does not exist, creating..." + mkdir -p "$REPOS_DIR" + fi +} -exec "$@" +create_ssh_directory +create_authorized_keys_file +create_repos_directory + +exec "$@" \ No newline at end of file