]> git.mar77i.info Git - mar77i.info/commitdiff
use stat %a to update the post-receive hook
authormar77i <mar77i@protonmail.ch>
Sun, 19 Nov 2023 23:40:40 +0000 (00:40 +0100)
committermar77i <mar77i@protonmail.ch>
Sun, 19 Nov 2023 23:45:00 +0000 (00:45 +0100)
post-receive.sh

index 8440fccc1d9430581a8adc17844673927208b0c2..ef9aa68de10ed7746050ff50bed73dc20c5f6b6d 100755 (executable)
@@ -11,8 +11,7 @@ done
 EOF
 
 hook_hash="$(printf '%s' "${hook}"|sha256sum| cut -d\  -f1)"
-post_receive="hooks/post-receive"
-[[ -f "${dest}" ]] && current_hash="$(sha256sum "${post_receive}"| cut -d\  -f1)"
+[[ -f "${dest}" ]] && current_hash="$(sha256sum hooks/post-receive| cut -d\  -f1)"
 
 print_and_run() {
     printf ">>>"
@@ -23,8 +22,10 @@ print_and_run() {
     "$@"
 }
 
-update_hook() {
-    print_and_run bash -c "cat >${post_receive} <<'EOF'"$'\n'"${hook}"$'\nEOF\n'
+update_post_receive_hook() {
+    local stat_cmd="\$(stat -c %a hooks/post-receive)"
+    print_and_run bash -c "cat >hooks/post-receive <<'EOF'"$'\n'"${hook}"$'\nEOF\n'
+    print_and_run bash -c "[[ ${stat_cmd} == 755 ]] || chmod 755 hooks/post-receive"
 }
 
 if [[ "${1}" == --install ]]; then
@@ -32,12 +33,11 @@ if [[ "${1}" == --install ]]; then
         echo "Error: No further arguments expected." >&2
         exit 1
     fi
-    update_hook "${post_receive}"
+    update_post_receive_hook
     exit
 fi
 
-[[ "${hook_hash}" != "${current_hash}" ]] && update_hook "${post_receive}"
-[[ -x "${post_receive}" ]] || chmod 755 "${post_receive}"
+[[ "${hook_hash}" != "${current_hash}" ]] && update_post_receive_hook
 
 update_gitweb_theme() {
     local theme_css_dest="/usr/share/gitweb/static/gitweb-theme.css"