mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-17 05:04:21 +01:00
Add first version of simple git sync (#162)
* Add first version of simple git sync * fix lint
This commit is contained in:
13
git_pull/Dockerfile
Normal file
13
git_pull/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM %%BASE_IMAGE%%
|
||||
|
||||
# Add env
|
||||
ENV LANG C.UTF-8
|
||||
|
||||
# Setup base
|
||||
RUN apk add --no-cache jq curl git
|
||||
|
||||
# Copy data
|
||||
COPY run.sh /
|
||||
RUN chmod a+x /run.sh
|
||||
|
||||
CMD [ "/run.sh" ]
|
||||
26
git_pull/config.json
Normal file
26
git_pull/config.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "GIT pull",
|
||||
"version": "0.1",
|
||||
"slug": "git_pull",
|
||||
"description": "Simple git pull to update local config.",
|
||||
"url": "https://home-assistant.io/addons/git_pull/",
|
||||
"startup": "services",
|
||||
"boot": "manual",
|
||||
"options": {
|
||||
"repositorie": null,
|
||||
"auto_restart": false,
|
||||
"repeat": {
|
||||
"active": false,
|
||||
"interval": 300
|
||||
}
|
||||
},
|
||||
"schema": {
|
||||
"repositorie": "url",
|
||||
"auto_restart": "bool",
|
||||
"repeat": {
|
||||
"active": "bool",
|
||||
"interval": "int"
|
||||
}
|
||||
},
|
||||
"image": "homeassistant/{arch}-addon-git_pull"
|
||||
}
|
||||
43
git_pull/run.sh
Normal file
43
git_pull/run.sh
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
CONFIG_PATH=/data/options.json
|
||||
|
||||
REPOSITORIE=$(jq --raw-output '.repositorie' $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)
|
||||
|
||||
# init config repositorie
|
||||
if [ ! -d /config/.git ]; then
|
||||
echo "[Info] cleanup config folder and clone from repositorie"
|
||||
rm -rf /config/*
|
||||
|
||||
if ! git clone "$REPOSITORIE" /config 2&> /dev/null; then
|
||||
echo "[Error] can't clone $REPOSITORIE into /config"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Run duckdns
|
||||
cd /config
|
||||
while true; do
|
||||
|
||||
echo "[Info] pull from $REPOSITORIE"
|
||||
git pull 2&> /dev/null || true
|
||||
|
||||
if [ "$AUTO_RESTART" == "true" ]; then
|
||||
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
|
||||
|
||||
if [ ! -z "$changed_files" ]; then
|
||||
echo "[Info] files changed, restart Home-Assistant"
|
||||
curl -s http://172.17.0.2/homeassistant/restart 2&> /dev/null || true
|
||||
fi
|
||||
fi
|
||||
|
||||
# do we repeat?
|
||||
if [ -z "$REPEAT_ACTIVE" ]; then
|
||||
exit 0
|
||||
fi
|
||||
sleep "$REPEAT_INTERVAL"
|
||||
done
|
||||
Reference in New Issue
Block a user