Skip to content

Instantly share code, notes, and snippets.

@ShawnHuang ShawnHuang/google.sh forked from deanet/google.sh
Last active Dec 21, 2015

Embed
What would you like to do?
upload to google drive
if [ ! -f $1 ]
then
echo "please provide a file in arg"
exit -1
fi
#assign folder to upload
if [ -z "$2" ]
then
folderid="root"
else
folderid="$2"
fi
creditFile=credits.ini
if [ ! -f $creditFile ]
then
echo "please fill $creditFile (file has just been created)"
echo "username=$login
password=$pass">$creditFile
exit -1
fi
file="$1"
browser="Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0.1"
username=`cat credits.ini | grep username |cut -d \= -f 2`
password=`cat credits.ini | grep password |cut -d \= -f 2`
accountype="GOOGLE" #gooApps = HOSTED , gmail=GOOGLE
mime_type=`file -b --mime-type $file`
msg=$(/usr/bin/curl \
-v \
--data-urlencode Email=$username \
--data-urlencode Passwd=$password \
-d accountType=$accountype \
-d service=writely \
-d source=cURL \
"https://www.google.com/accounts/ClientLogin")
token=`echo "$msg" | grep Auth | cut -d \= -f 2`
uploadlink=`/usr/bin/curl \
-Sv \
-k \
--request POST \
-H "Content-Length: 0" \
-H "Authorization: GoogleLogin auth=${token}" \
-H "GData-Version: 3.0" \
-H "Content-Type: $mime_type" \
-H "Slug: $file" \
"https://docs.google.com/feeds/upload/create-session/default/private/full/folder:$folderid/contents?convert=false" \
-D /dev/stdout | grep "Location:" | sed s/"Location: "//`
/usr/bin/curl \
-Sv \
-k \
--request POST \
--data-binary "@$file" \
-H "Authorization: GoogleLogin auth=${token}" \
-H "GData-Version: 3.0" \
-H "Content-Type: $mime_type" \
-H "Slug: $file" "$uploadlink" \
-D /dev/stdout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.