diff --git a/git_pull/Dockerfile b/git_pull/Dockerfile index f857872..bde16e5 100644 --- a/git_pull/Dockerfile +++ b/git_pull/Dockerfile @@ -5,7 +5,7 @@ FROM $BUILD_FROM ENV LANG C.UTF-8 # Setup base -RUN apk add --no-cache jq curl git +RUN apk add --no-cache jq curl git openssh-client # Copy data COPY run.sh / diff --git a/git_pull/config.json b/git_pull/config.json index 3a2dae7..f55a9e2 100644 --- a/git_pull/config.json +++ b/git_pull/config.json @@ -1,6 +1,6 @@ { "name": "Git pull", - "version": "1.1", + "version": "2.0", "slug": "git_pull", "description": "Simple git pull to update the local configuration", "url": "https://home-assistant.io/addons/git_pull/", @@ -9,6 +9,8 @@ "hassio_api": true, "map": ["config:rw"], "options": { + "deployment_key": [], + "deployment_key_protocol": "rsa", "repository": null, "auto_restart": false, "repeat": { @@ -17,6 +19,8 @@ } }, "schema": { + "deployment_key": ["str"], + "deployment_key_protocol": "match(rsa|dsa|ecdsa|ed25519|rsa)", "repository": "url", "auto_restart": "bool", "repeat": { diff --git a/git_pull/run.sh b/git_pull/run.sh index 1513aa3..317a739 100644 --- a/git_pull/run.sh +++ b/git_pull/run.sh @@ -3,11 +3,26 @@ set -e CONFIG_PATH=/data/options.json +DEPLOYMENT_KEY=$(jq --raw-output ".deployment_key[]" $CONFIG_PATH) +DEPLOYMENT_KEY_PROTOCOL=$(jq --raw-output ".deployment_key_protocol" $CONFIG_PATH) REPOSITORY=$(jq --raw-output '.repository' $CONFIG_PATH) AUTO_RESTART=$(jq --raw-output '.auto_restart' $CONFIG_PATH) REPEAT_ACTIVE=$(jq --raw-output '.repeat.active' $CONFIG_PATH) REPEAT_INTERVAL=$(jq --raw-output '.repeat.interval' $CONFIG_PATH) +# prepare the private key, if provided +if [ ! -z "$DEPLOYMENT_KEY" ]; then + echo "[Info] setup deployment_key on id_${DEPLOYMENT_KEY_PROTOCOL}" + + mkdir -p ~/.ssh + while read -r line; do + echo "$line" >> "${HOME}/.ssh/id_${DEPLOYMENT_KEY_PROTOCOL}" + done <<< "$DEPLOYMENT_KEY" + + chmod 600 "${HOME}/.ssh/id_${DEPLOYMENT_KEY_PROTOCOL}" +fi + + # init config repositorie if [ ! -d /config/.git ]; then echo "[Info] cleanup config folder and clone from repositorie"