]> git.ekhem.eu.org Git - gdrive_proxy.git/commitdiff
Clear /tmp before downloading a file.
authorJakub Czajka <jakub@ekhem.eu.org>
Wed, 22 Nov 2023 21:52:47 +0000 (22:52 +0100)
committerJakub Czajka <jakub@ekhem.eu.org>
Mon, 4 Dec 2023 02:18:42 +0000 (03:18 +0100)
download.sh

index 2cc5bf9ea0418f4db23789bbf22c314c1b993e71..420d4e701a6f0c8e29b2f9deea9aa4219adf2d0e 100755 (executable)
@@ -5,7 +5,14 @@
 . /etc/environment
 
 # Replace %2F with '/' and remove %0D%0A.
-NAME=$(echo ${NAME_ON_DRIVE} | sed 's/%2F/\//g; s/%0D%0A//g')
+FULL_NAME=$(echo ${NAME_ON_DRIVE} | sed 's/%2F/\//g; s/%0D%0A//g')
+BASE_NAME=$(basename "${FULL_NAME}")
+
+# Clear /tmp for download.
+if [ -e "/tmp/${BASE_NAME}" ]
+then
+    rm -rf "/tmp/${BASE_NAME}"
+fi
 
 echo "HTTP/1.1 200 OK"
 echo "Content-Type: text/html"
@@ -13,7 +20,7 @@ echo "
 <!DOCTYPE html>
 <html>
 <head>
-  <meta http-equiv='Refresh' content='0;URL=/$(basename ${NAME})' />
+  <meta http-equiv='Refresh' content='0;URL=/${BASE_NAME}' />
   <style>
     body {
       white-space: pre-wrap;
@@ -21,9 +28,9 @@ echo "
   </style>
 </head>
 <body>"
-echo "Downloading ${NAME}"
+echo "Downloading ${FULL_NAME}"
 python3 -u -m gdrive_knife 2>&1 download --token ${gdrive_auth_token} \
-    --key ${gdrive_encryption_key} --leave-as-archive ${NAME} /tmp
+    --key ${gdrive_encryption_key} --leave-as-archive ${FULL_NAME} /tmp
 echo "\
 </body>
 </html>"