From: Amélia Coutard-Sander Date: Fri, 6 Dec 2024 00:51:36 +0000 (+0100) Subject: Better, slightly more general client X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=HEAD;p=git-over-gnunet.git Better, slightly more general client --- diff --git a/git-remote-gnunet b/git-remote-gnunet index 521a95e..ba4c417 100755 --- a/git-remote-gnunet +++ b/git-remote-gnunet @@ -2,11 +2,10 @@ shopt -s lastpipe -if [[ "$2" = gnunet://* ]]; then - echo "${2:9}" -else - echo "$2" -fi | awk ' +case "$2" in +gnunet://*) echo "${2:9}" ;; +*) echo "$2" ;; +esac | awk ' match($0, /(([^@]*)@)?([^/]*)(\/.*)?/, a) { printf "%s\n%s\n%s\n", a[2], a[3], a[4] } ' | { read -r username && read -r gnsname && read -r path && ! grep '.'; } if test "$?" != "0"; then @@ -19,7 +18,7 @@ while read -r cmd arg; do case "$cmd" in capabilities) printf '%s\n' 'connect' '' ;; connect) break ;; - *) echo >&2 "Error: Git remote helper protocol."; exit 1 ;; + *) echo >&2 "Error: Git remote helper protocol failure."; exit 1 ;; esac done @@ -43,20 +42,22 @@ mkfifo "$fifo" || { echo 2>&1 "Failed to create the fifo."; exit 1; } echo; cat "$fifo" -; } | socat stdio tcp4:"$ip":9418 | { - { if test "" != "$username"; then - read -r cyphertext - case "$cyphertext" in + { while read -r line; do + case "$line" in "Error: "*) - echo >&2 "$cyphertext" + echo >&2 "$line" rm "$fifo" exit 1 ;; "Key:"*) - plaintext="$(gnunet-identity -e "$username" -R "${cyphertext:4}")" || { rm "$fifo"; exit 1; } + plaintext="$(gnunet-identity -e "$username" -R "${line:4}")" || { rm "$fifo"; exit 1; } printf '%s\n' "$plaintext" | sha256sum ;; + "") break ;; + *) echo >&2 "Error: Git/GNUnet handler protocol failure."; exit 1 ;; esac; - fi; } > "$fifo"; + done; } > "$fifo"; + echo ''; cat; } rm "$fifo"