. /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"
<!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;
</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>"