]> git.mar77i.info Git - mar77i.info/blob - post-receive.sh
move admin stuff to admin
[mar77i.info] / post-receive.sh
1 #!/usr/bin/env bash
2
3 read -r -d '' hook <<'EOF'
4 #!/usr/bin/env bash
5 while read _ _ refname; do
6 if [[ "${refname}" == refs/heads/master ]]; then
7 . <(git show master:post-receive.sh)
8 break
9 fi
10 done
11 EOF
12
13 hook_hash="$(printf '%s' "${hook}"|sha256sum| cut -d\ -f1)"
14 [[ -f "${dest}" ]] && current_hash="$(sha256sum hooks/post-receive| cut -d\ -f1)"
15
16 print_and_run() {
17 printf ">>>"
18 for (( i = 1; i < $# + 1; i++ )); do
19 printf ' %q' "${!i}"
20 done
21 printf "\n"
22 "$@"
23 }
24
25 update_post_receive_hook() {
26 local stat_cmd="\$(stat -c %a hooks/post-receive)"
27 print_and_run bash -c "cat >hooks/post-receive <<'EOF'"$'\n'"${hook}"$'\nEOF\n'
28 print_and_run bash -c "[[ ${stat_cmd} == 755 ]] || chmod 755 hooks/post-receive"
29 }
30
31 if [[ "${1}" == --install ]]; then
32 if (( $# > 1 )); then
33 echo "Error: No further arguments expected." >&2
34 exit 1
35 fi
36 update_post_receive_hook
37 exit
38 fi
39
40 [[ "${hook_hash}" != "${current_hash}" ]] && update_post_receive_hook
41
42 echo "There's currently nothing to do" | tee "${HOME}/webroot/www.mar77i.info/index.html"