download-gdrive.sh 1.0 KB

1234567891011121314151617181920212223242526272829
  1. #!/bin/sh
  2. # This script downloads all files from a Google drive into a local directory.
  3. # It relies on https://github.com/glotlabs/gdrive, which expects to find
  4. # google drive credentials on /root/.config/gdrive3.
  5. #
  6. # Limitations: does not export Google Docs.
  7. #
  8. # Environment variables:
  9. # LOCAL_FOLDER_PATH: the directory where the files will be downloaded. Must exist.
  10. # ACCOUNT: the email address of the accoumt to use.
  11. [[ -d "$LOCAL_FOLDER_PATH" ]] || mkdir -p "$LOCAL_FOLDER_PATH"
  12. [[ -z "$ACCOUNT" ]] && echo "ACCOUNT must be set to an email address" >&2 && exit 1
  13. echo "Copying all Google drive files to $LOCAL_FOLDER_PATH"
  14. cd "$LOCAL_FOLDER_PATH"
  15. gdrive account switch "$ACCOUNT"
  16. for folder in $(gdrive files list | grep folder | cut -d' ' -f1)
  17. do
  18. echo "Downloading folder with id $folder"
  19. gdrive files download --recursive "$folder" || exit 10
  20. done
  21. for document in $(gdrive files list | grep regular | cut -d' ' -f1)
  22. do
  23. echo "Downloading file with id $document"
  24. gdrive files download "$document" || exit 10
  25. done