Skip to content

Instantly share code, notes, and snippets.

@ShawnHuang
Forked from deanet/google.sh
Last active December 21, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ShawnHuang/6265462 to your computer and use it in GitHub Desktop.
Save ShawnHuang/6265462 to your computer and use it in GitHub Desktop.
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