]> git.ekhem.eu.org Git - gdrive_proxy.git/commitdiff
Wrap `auth` to return HTTP responses.
authorJakub Czajka <jakub@ekhem.eu.org>
Tue, 21 Nov 2023 23:28:07 +0000 (00:28 +0100)
committerJakub Czajka <jakub@ekhem.eu.org>
Mon, 4 Dec 2023 02:17:03 +0000 (03:17 +0100)
auth.sh [new file with mode: 0755]

diff --git a/auth.sh b/auth.sh
new file mode 100755 (executable)
index 0000000..1661926
--- /dev/null
+++ b/auth.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+. /etc/environment
+
+PERM_LINK="https\:\/\/myaccount\.google\.com\/permissions"
+
+with_hyperlink() {
+    echo "${1}" | sed s/${PERM_LINK}/"<a href=\"${PERM_LINK}\">link<\/a>"/
+}
+
+python3 -u -m gdrive_knife auth \
+       --credentials ${gdrive_credentials} \
+       --token ${gdrive_auth_token} \
+       --on_success https://drive.${private_domain} \
+       --on_token https://drive.${private_domain}/auth \
+       --port 3030 \
+  | while read -r line
+    do
+        case "${line}" in
+            *"Reset permissions"*)
+                echo "HTTP/1.1 403 Forbidden"
+                echo "Content-Type: text/html"
+                echo ""
+               echo "<body>$(with_hyperlink "${line}")</body>"
+                exit 1
+            ;;
+            *"Authentication URL"*)
+                echo "HTTP/1.1 307 Temporary Redirect"
+               echo "Location: $(echo ${line} | sed 's/^.*\s//')"
+               echo ""
+           ;;
+        esac
+    done