57f7b2cc5c1ee2120401751eba82ca9d249be3de
[noc.git] / ansible / files / torwaechter / post-receive
1 #!/bin/sh
2 ## (c) Bernhard Tittelbach 2017-10-28, Tschunk-License
3 ## (c) nicoo               2018-05-20, Tschunk-License
4 ## this is the post-recieve hook installed in /home/tuergit/keys.git/hooks/
5
6 set -eu
7
8 keys_branch=$(git config hooks.keys_branch 2>/dev/null)
9 keys_file=$(git config hooks.keys_file 2>/dev/null)
10 keys_pipe_to=$(git config hooks.keys_pipe_to 2>/dev/null)
11
12 keys_branch=${keys_branch:-master}
13 keys_file=${keys_file:-keys}
14 keys_pipe_to=${keys_pipe_to:-/usr/local/bin/update-keys-from-stdin.sh}
15
16 changedcommits=$( grep "refs/heads/${keys_branch}" | sed 's/\([0-9a-f]\+\)\s\+\([0-9a-f]\+\)\s\+.*/\1..\2/;' )
17
18 catgitkeyfile() {
19         git show "${keys_branch}:${keys_file}"
20 }
21
22 if git whatchanged --oneline $changedcommits | grep -qe "^:.*${keys_file}\$"; then
23   echo "./$keys_file changed in pushed commits. Updating keys in firmware!"
24   ## update door
25   catgitkeyfile | ${keys_pipe_to}
26 else
27   echo "./$keys_file not changed, not updating keys in firmware"
28 fi