]> git.mar77i.info Git - mar77i.info/commitdiff
first commit
authormar77i <mar77i@protonmail.ch>
Fri, 17 Nov 2023 20:09:23 +0000 (21:09 +0100)
committermar77i <mar77i@protonmail.ch>
Sun, 19 Nov 2023 23:44:51 +0000 (00:44 +0100)
.gitignore [new file with mode: 0644]
gitweb-theme.css [new file with mode: 0644]
post-receive.sh [new file with mode: 0755]
remote_as_root.sh [new file with mode: 0755]
update_system.sh [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..9d88a30
--- /dev/null
@@ -0,0 +1,2 @@
+id_ed25519
+id_ed25519.pub
diff --git a/gitweb-theme.css b/gitweb-theme.css
new file mode 100644 (file)
index 0000000..ed3d0a8
--- /dev/null
@@ -0,0 +1,17 @@
+body {
+    color: #dfd9ac;
+    background-color: #252436;
+    border: 1px solid #2d2a49;
+}
+
+.page_header, .page_footer {
+    background-color: #2d2a49 !important;
+}
+
+a {
+    color: #b5a17b !important;
+}
+
+a:visited {
+    color: #7a749d !important;
+}
diff --git a/post-receive.sh b/post-receive.sh
new file mode 100755 (executable)
index 0000000..8440fcc
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+
+read -r -d '' hook <<'EOF'
+#!/usr/bin/env bash
+while read _ _ refname; do
+    if [[ "${refname}" == refs/heads/master ]]; then
+        . <(git show master:post-receive.sh)
+        break
+    fi
+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)"
+
+print_and_run() {
+    printf ">>>"
+    for (( i = 1; i < $# + 1; i++ )); do
+        printf ' %q' "${!i}"
+    done
+    printf "\n"
+    "$@"
+}
+
+update_hook() {
+    print_and_run bash -c "cat >${post_receive} <<'EOF'"$'\n'"${hook}"$'\nEOF\n'
+}
+
+if [[ "${1}" == --install ]]; then
+    if (( $# > 1 )); then
+        echo "Error: No further arguments expected." >&2
+        exit 1
+    fi
+    update_hook "${post_receive}"
+    exit
+fi
+
+[[ "${hook_hash}" != "${current_hash}" ]] && update_hook "${post_receive}"
+[[ -x "${post_receive}" ]] || chmod 755 "${post_receive}"
+
+update_gitweb_theme() {
+    local theme_css_dest="/usr/share/gitweb/static/gitweb-theme.css"
+    print_and_run bash -c "git show master:gitweb-theme.css > ${theme_css_dest}"
+}
+
+tasks=(update_gitweb_theme)
+
+for task in "${tasks[@]}"; do
+    "${task}"
+done
diff --git a/remote_as_root.sh b/remote_as_root.sh
new file mode 100755 (executable)
index 0000000..5f441c6
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+# this works if the remote has pam_ssh_agent_auth with the local id_ed25519.pub set up
+
+script="$(realpath -e "${0}")"
+script_dir="${script%/*}"
+
+get_ssh_agent_socket() {
+    local tmpdir="${TMPDIR:-/tmp}"
+    local former_nullglob_set=0 found=0 output
+    shopt -q nullglob && former_nullglob_set=1
+    shopt -s nullglob
+    for SSH_AUTH_SOCK in "${tmpdir}"/ssh-*/agent.*; do
+        output="$(ssh-add -l 2>&1)"
+        [[ "${output}" == "Error connecting to agent: Connection refused" ]] && continue
+        export SSH_AUTH_SOCK
+        found=1
+        break
+    done
+    (( found == 0 )) && . <(ssh-agent)
+    (( former_nullglob_set )) || shopt -u nullglob
+    return 0
+}
+
+add_ssh_key() {
+    local privkey="${script_dir}/${1}"
+    [[ ! -f "${privkey}" ]] && ssh-keygen -t "${1}" -b 521 -f "${privkey}"
+    grep -qE "^$(ssh-keygen -lf "${privkey}"|sed -r 's/([][{}|()+?])/\\\1/g')\$" \
+        <(ssh-add -l) || ssh-add "${privkey}"
+}
+
+get_ssh_agent_socket
+add_ssh_key id_ed25519
+
+script_b64="$(gzip -9<"${2}"|base64 -w0)"
+launcher="$(printf '%q' '. <(printf "%s" "'"${script_b64}"'"|base64 -d|gunzip)')"
+ssh -o ForwardX11=no -At "${1}" sudo bash -c "${launcher}"
diff --git a/update_system.sh b/update_system.sh
new file mode 100644 (file)
index 0000000..39e7862
--- /dev/null
@@ -0,0 +1,13 @@
+print_and_run() {
+    printf ">>>"
+    for (( i = 1; i < $# + 1; i++ )); do
+        printf ' %q' "${!i}"
+    done
+    printf "\n"
+    "$@"
+}
+
+print_and_run pacman -Syu
+print_and_run pacdiff -f -o
+cd
+print_and_run bash