Last active
January 3, 2019 09:23
-
-
Save 0i0/0ff2630fdb0dd6f9e7a5ffa4886e8ad0 to your computer and use it in GitHub Desktop.
bash script to download large files from google drive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## description: script to download large files from google drive | |
## version 0.1 | |
## author: 0i0 (https://github.com/0i0) | |
usage="$(basename "$0") [-h] link filename-- program to download a file from google drive link | |
where: | |
-h show this help text | |
link set the link | |
filename set the filename" | |
while getopts ':h' option; do | |
case "$option" in | |
h) echo "$usage" | |
exit | |
;; | |
esac | |
done | |
if [ -z "$1" ] | |
then | |
echo "No argument supplied" | |
echo "$usage" | |
exit | |
fi | |
if [ -z "$2" ] | |
then | |
echo "No filename supplied" | |
echo "$usage" | |
exit | |
fi | |
if [[ ! $1 = *"https://drive.google.com"* ]]; then | |
echo "not sure its a google drive link | |
was looking for https://drive.google.com | |
" | |
exit | |
fi | |
# get the query strin | |
query=$(echo $1|awk -F\? '{print $2}') | |
# parse the query string to get id | |
saveIFS=$IFS | |
IFS='=&' | |
parm=($query) | |
IFS=$saveIFS | |
for ((i=0; i<${#parm[@]}; i+=2)) | |
do | |
declare var_${parm[i]}=${parm[i+1]} | |
done | |
id=$var_id | |
filename=$2 | |
echo "Downloading $1" | |
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id='$id -O- | awk -F"confirm=" '{printf substr($2,0,5)}')&id="$id -O $filename && rm -rf /tmp/cookies.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment