Adding support for deployment_key for git_pull addon (#196)

* adding support for deployment_key for git_pull addon

* safer usage of bash vars

* fixed $HOME vs ~ typo

* more specific schema for deployment_key_protocol

* adding ssh-client to git pull addon image

* only ...-client package needed

* Pump version to 2.0
This commit is contained in:
Alex Barcelo
2017-10-29 10:22:40 +01:00
committed by Pascal Vizeli
parent 0e117c07ee
commit ea5d7b5920
3 changed files with 21 additions and 2 deletions

View File

@@ -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 /

View File

@@ -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": {

View File

@@ -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"