]> git.ameliathe1st.gay Git - git-over-gnunet.git/commitdiff
Better, slightly more general client trunk
authorAmélia Coutard-Sander <git@ameliathe1st.gay>
Fri, 6 Dec 2024 00:51:36 +0000 (01:51 +0100)
committerAmélia Coutard-Sander <git@ameliathe1st.gay>
Fri, 6 Dec 2024 00:51:36 +0000 (01:51 +0100)
git-remote-gnunet

index 521a95e2a708b99dcf9020cf745732759a37925a..ba4c4173cf8cfec2a45c0549f613d0c7d56f7f87 100755 (executable)
@@ -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"