From f8cf9fc468f89f397ba8cdcb232a83e9c180b798 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Wed, 22 Nov 2023 00:28:07 +0100 Subject: [PATCH] Wrap `auth` to return HTTP responses. --- auth.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 auth.sh diff --git a/auth.sh b/auth.sh new file mode 100755 index 0000000..1661926 --- /dev/null +++ b/auth.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# Copyright (c) 2023 Jakub Czajka +# License: GPL-3.0 or later. + +. /etc/environment + +PERM_LINK="https\:\/\/myaccount\.google\.com\/permissions" + +with_hyperlink() { + echo "${1}" | sed s/${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 "$(with_hyperlink "${line}")" + exit 1 + ;; + *"Authentication URL"*) + echo "HTTP/1.1 307 Temporary Redirect" + echo "Location: $(echo ${line} | sed 's/^.*\s//')" + echo "" + ;; + esac + done -- 2.39.5