From 825074abc0f22dc633bf5082775c516c310b419e Mon Sep 17 00:00:00 2001 From: bradnelson Date: Tue, 3 Aug 2010 17:30:53 -0700 Subject: [PATCH] Making default to LOGNAME work correctly. Modifying gsdcurl to accept username and password from the environment. Switching cros_download_latest_image to use gsdcurl Merge branch 'master' of ssh://chromiumos-git/crosutils Switching back to MixedCase. Wrong style guide... Switching to match external style guide. Dropping unneeded arg as per review. Fixing copyright. Making the prompts go to stderr. Renaming for tab completion. Adding gsdcurl utility for pulling for Google Storage for Developers. BUG=None TEST=None Review URL: http://codereview.chromium.org/3060043 --- bin/cros_gsdcurl.py | 70 ++++++++++++++++++++++++++++++++++++++ cros_download_latest_image | 14 +++++--- 2 files changed, 80 insertions(+), 4 deletions(-) create mode 100755 bin/cros_gsdcurl.py diff --git a/bin/cros_gsdcurl.py b/bin/cros_gsdcurl.py new file mode 100755 index 0000000000..e046fe2795 --- /dev/null +++ b/bin/cros_gsdcurl.py @@ -0,0 +1,70 @@ +#!/usr/bin/python +# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + + +import getpass +import os +import re +import subprocess +import sys +import tempfile +import urllib + + +def Authenticate(): + # Authenticate. + default_username = os.environ.get('LOGNAME', '') + username = os.environ.get('GSDCURL_USERNAME') + if username is None: + sys.stderr.write('Username [' + default_username + ']: ') + username = raw_input() + if username == '': + username = default_username + '@google.com' + elif '@' not in username: + username = username + '@google.com' + passwd = os.environ.get('GSDCURL_PASSWORD') + if passwd is None: + sys.stderr.write('Password: ') + passwd = urllib.quote_plus(getpass.getpass(prompt='')) + cmd = [ + 'curl', '--silent', 'https://www.google.com/accounts/ClientLogin', + '-d', 'Email=' + username, + '-d', 'Passwd=' + passwd, + '-d', 'accountType=GOOGLE', + '-d', 'source=Google-gsdcurl-ver1', + '-d', 'service=cds', + ] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE) + (p_stdout, _) = p.communicate() + assert p.returncode == 0 + m = re.search('\nAuth=([^\n]+)\n', p_stdout) + if not m: + sys.stderr.write('BAD LOGIN\n') + sys.exit(1) + auth = m.group(1) + return auth + + +def DoCurl(auth, argv): + (_, cookies) = tempfile.mkstemp(prefix='gsdcookie') + cmd = [ + 'curl', '-L', + '-b', cookies, '-c', cookies, + '--header', 'Authorization: GoogleLogin auth=' + auth, + ] + argv[1:] + try: + p = subprocess.Popen(cmd) + return p.wait() + finally: + os.remove(cookies) + + +def main(argv): + auth = Authenticate() + return DoCurl(auth, argv) + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/cros_download_latest_image b/cros_download_latest_image index a0715d9189..f749d8fb6f 100755 --- a/cros_download_latest_image +++ b/cros_download_latest_image @@ -30,19 +30,25 @@ IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" if [ $FLAGS_board = x86-generic ]; then if [ "$FLAGS_incremental" -eq "$FLAGS_TRUE" ]; then - URL_PREFIX="http://codg174.jail.google.com/archive/x86-generic-inc" + URL_PREFIX="https://sandbox.google.com/storage/chromeos-archive/x86-generic-bin" else - URL_PREFIX="http://codg163.jail.google.com/archive/x86-generic-rel" + URL_PREFIX="https://sandbox.google.com/storage/chromeos-archive/x86-generic-rel" fi else die "Unrecognized board: $FLAGS_board" fi -LATEST_BUILD=$(curl -s $URL_PREFIX/LATEST) +read -p "Username [${LOGNAME}]: " GSDCURL_USERNAME +export GSDCURL_USERNAME +read -s -p "Password: " GSDCURL_PASSWORD +export GSDCURL_PASSWORD + +LATEST_BUILD=$(bin/cros_gsdcurl.py -s $URL_PREFIX/LATEST) LATEST_IMAGE_DIR="$IMAGES_DIR/$LATEST_BUILD" if [ ! -e $LATEST_IMAGE_DIR/chromiumos_base_image.bin ]; then mkdir -p $LATEST_IMAGE_DIR - curl $URL_PREFIX/$LATEST_BUILD/image.zip -o $LATEST_IMAGE_DIR/image.zip \ + bin/cros_gsdcurl.py $URL_PREFIX/$LATEST_BUILD/image.zip -o \ + $LATEST_IMAGE_DIR/image.zip \ || die "Could not download image.zip" ( cd $LATEST_IMAGE_DIR && unzip -qo image.zip ) \ || die "Could not unzip image.zip"