mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-23 06:31:18 +02:00
Update cros_download_latest_image to work again.
cros_download_latest_image was using cros_gsdcurl, which has stopped working, even when you use application-specific passwords. I've updated it to use gsutil instead, which is more supported. BUG=chromium-os:17512 TEST=Try downloading the latest x86-generic image. Change-Id: Ia7b0704a8c7ff6897508c44e882f87bc44ccbe28 Reviewed-on: http://gerrit.chromium.org/gerrit/5031 Reviewed-by: Rahul Chaturvedi <rkc@chromium.org> Tested-by: David James <davidjames@chromium.org>
This commit is contained in:
parent
bb783007ce
commit
65d88bf903
@ -1,69 +0,0 @@
|
|||||||
#!/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():
|
|
||||||
default_username = getpass.getuser()
|
|
||||||
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 = getpass.getpass(prompt='')
|
|
||||||
cmd = [
|
|
||||||
'curl', '--silent', 'https://www.google.com/accounts/ClientLogin',
|
|
||||||
'-d', 'Email=' + username,
|
|
||||||
'-d', 'Passwd=' + urllib.quote_plus(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))
|
|
@ -32,42 +32,36 @@ get_default_board
|
|||||||
|
|
||||||
DEFINE_string board "$DEFAULT_BOARD" \
|
DEFINE_string board "$DEFAULT_BOARD" \
|
||||||
"The name of the board to check for images."
|
"The name of the board to check for images."
|
||||||
DEFINE_boolean incremental "${FLAGS_FALSE}" "Download incremental build"
|
DEFINE_boolean incremental "$FLAGS_FALSE" "Download incremental build"
|
||||||
|
|
||||||
# Parse command line flags.
|
# Parse command line flags.
|
||||||
FLAGS "$@" || exit 1
|
FLAGS "$@" || exit 1
|
||||||
eval set -- "${FLAGS_ARGV}"
|
eval set -- "$FLAGS_ARGV"
|
||||||
|
|
||||||
# Check on the board that they are trying to set up.
|
# Check on the board that they are trying to set up.
|
||||||
if [ -z "$FLAGS_board" ] ; then
|
if [ -z "$FLAGS_board" ] ; then
|
||||||
die "Error: --board required."
|
die "Error: --board required."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
|
BUCKET="chromeos-image-archive"
|
||||||
|
|
||||||
if [ $FLAGS_board = x86-generic ]; then
|
if [ $FLAGS_board = x86-generic ]; then
|
||||||
if [ "$FLAGS_incremental" -eq "$FLAGS_TRUE" ]; then
|
if [ "$FLAGS_incremental" -eq "$FLAGS_TRUE" ]; then
|
||||||
URL_PREFIX="https://sandbox.google.com/storage/chromeos-archive/x86-generic-bin"
|
PATH_PREFIX="x86-generic-pre-flight-queue"
|
||||||
else
|
else
|
||||||
URL_PREFIX="https://sandbox.google.com/storage/chromeos-archive/x86-generic-rel"
|
PATH_PREFIX="x86-generic-full"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
die "Unrecognized board: $FLAGS_board"
|
die "Unrecognized board: $FLAGS_board"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -p "Username [${LOGNAME}]: " GSDCURL_USERNAME
|
URL_PREFIX="gs://$BUCKET/$PATH_PREFIX"
|
||||||
export GSDCURL_USERNAME
|
LATEST_BUILD=$(gsutil cat $URL_PREFIX/LATEST)
|
||||||
read -s -p "Password: " GSDCURL_PASSWORD
|
IMAGES_DIR="$DEFAULT_BUILD_ROOT/images/$FLAGS_board"
|
||||||
echo >&2 # ... because read -s didn't print a newline
|
|
||||||
export GSDCURL_PASSWORD
|
|
||||||
|
|
||||||
LATEST_BUILD=$(bin/cros_gsdcurl.py -s $URL_PREFIX/LATEST)
|
|
||||||
LATEST_IMAGE_DIR="$IMAGES_DIR/$LATEST_BUILD"
|
LATEST_IMAGE_DIR="$IMAGES_DIR/$LATEST_BUILD"
|
||||||
if [ ! -e $LATEST_IMAGE_DIR/chromiumos_base_image.bin ]; then
|
if [ ! -e $LATEST_IMAGE_DIR/chromiumos_base_image.bin ]; then
|
||||||
mkdir -p $LATEST_IMAGE_DIR
|
mkdir -p $LATEST_IMAGE_DIR
|
||||||
bin/cros_gsdcurl.py $URL_PREFIX/$LATEST_BUILD/image.zip -o \
|
gsutil cp "$URL_PREFIX/$LATEST_BUILD/image.zip" \
|
||||||
$LATEST_IMAGE_DIR/image.zip \
|
"$LATEST_IMAGE_DIR/image.zip" || die "Could not download image.zip"
|
||||||
|| die "Could not download image.zip"
|
|
||||||
( cd $LATEST_IMAGE_DIR && unzip -qo image.zip ) \
|
( cd $LATEST_IMAGE_DIR && unzip -qo image.zip ) \
|
||||||
|| die "Could not unzip image.zip"
|
|| die "Could not unzip image.zip"
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user