Skip to content

Instantly share code, notes, and snippets.

@sj-dan
Last active December 10, 2023 12:22
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sj-dan/e103425b4b3c3125b393831c3b4c0748 to your computer and use it in GitHub Desktop.
Save sj-dan/e103425b4b3c3125b393831c3b4c0748 to your computer and use it in GitHub Desktop.
Script to fetch and download the latest version of the Chrome OS Flex image
#!/bin/bash
URLs=$(curl "https://dl.google.com/dl/edgedl/chromeos/recovery/cloudready_recovery2.json" \
-s --output - | \
grep "^.*\"url\".*$" | \
sed "s/.*\"url\": \"\(.*\)\".*$/\1/g")
printf "\nPick which channel to download your image from. Channel name is near the end of the URL.\n\n"
select URL in $URLs;
do
if [[ $URL != "" ]]; then
printf "\nDownloading now...\n\n"
curl -L -C - -O $URL && break
else
printf "\nInvalid selection, please pick one of the above displayed numbers.\n\n"
fi
done
printf "\nFinished downloading!\n"
@madmax2
Copy link

madmax2 commented Jul 21, 2022

downloaded the chromeOS file but the script gave this message at the end

curl: (23) Failed writing body (4824 != 15791)
Finished downloading!

@sj-dan
Copy link
Author

sj-dan commented Jul 21, 2022

@madmax2

So, google actually updated the way their JSON works on this, so I'll have to update the script.

@porteusconf
Copy link

porteusconf commented Dec 3, 2022

There is an alternative script that seems to download *bin.zip files ok for me. I used the chromiumos recovery.sh script at https://chromium.googlesource.com/chromiumos/user-recovery-tools/+/master/linux/recovery.sh And it can download the current newest DEV and/or STABLE chromeos-flex *bin.zip files with command-line argument --config URL where URL is https://dl.google.com/dl/edgedl/chromeos/recovery/cloudready_recovery2.conf as shown below. That is:

 cd  ~/Downloads  # (or cd /Users/Shared  or  cd /tmp  or  cd /full-path-to-folder-where-script-is)
 ./recovery.sh --config "https://dl.google.com/dl/edgedl/chromeos/recovery/cloudready_recovery2.conf"

NOTE: To allow resuming partial downloads, it uses /tmp/tmp.crosrec by default as $WORKDIR. As a bonus, after the download it then optionally offers to write to a USB drive of your choice. I did not test the writing of usb yet, only the ability to download.
It is quite a nice little /bin/sh script: simple, but thorough and careful. It is designed to run on mac or linux. It does lots of sanity tests and error checking including checks of zipfilesize, unzipped filesize, checksum of zip file, and if there is enough room on usb flash drive to write the image. It uses dd to write the image to usb flash drive as fast as it can, with bs=4194304 (=1024*4096). Comments suggest in most cases sudo is not needed if you already have permissions for external drives.

# Many BSD variants provide both normal /dev/FOO and raw /dev/rFOO devices,
# with the raw path being much faster. If that device exists, we'll use it.
if [ -e /dev/r${user_choice} ]; then
  user_choice="r${user_choice}"
fi
dd bs=4194304 of=/dev/${user_choice} if="$image_file" conv=sync ||
  ufatal "Unable to write the image."
sync
...
Done. Remove the USB drive and insert it in your Chrome notebook.

Example transcript...

$  cd /tmp
$ curl "https://chromium.googlesource.com/chromiumos/user-recovery-tools/+/master/linux/recovery.sh?format=TEXT" \
-s --output - |  base64 --decode > recovery.sh
$ chmod a+x recovery.sh

$  ./recovery.sh --config "https://dl.google.com/dl/edgedl/chromeos/recovery/cloudready_recovery2.conf"
Working in /tmp/tmp.crosrec/
Downloading config file from https://dl.google.com/dl/edgedl/chromeos/recovery/cloudready_recovery2.conf

If you know the Model string displayed at the recovery screen,
type some or all of it; otherwise just press Enter: 

This may take a few minutes to print the full list...

There are 2 recovery images to choose from:

0 - <quit>
1 - ChromeOS Flex
      channel:  DEV
2 - ChromeOS Flex
      channel:  STABLE

Please select a recovery image to download: 2
Downloading image zipfile from https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_15117.112.0_reven_recovery_stable-channel_mp-v2.bin.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  
                                                       
 96 1151M   96 1110M    0     0   709k      0  0:27:42  0:26:44  0:00:58  594k
100 1151M  100 1151M    0     0   707k      0  0:27:46  0:27:46 --:--:--  715k
Unpacking the zipfile
Archive:  chromeos_15117.112.0_reven_recovery_stable-channel_mp-v2.bin.zip
  inflating: chromeos_15117.112.0_reven_recovery_stable-channel_mp-v2.bin  
I can't seem to find a valid USB drive.  We need one with at least 6619MB capacity.

0 - <quit>

$. ls -lrt /tmp/tmp.crosrec/*.zip
 1206930016 Dec  2 20:25 chromeos_15117.112.0_reven_recovery_stable-channel_mp-v2.bin.zip

$ ls /tmp/tmp.crosrec
chromeos_15117.112.0_reven_recovery_stable-channel_mp-v2.bin
chromeos_15117.112.0_reven_recovery_stable-channel_mp-v2.bin.zip
config.txt
debug.log
tmp.txt
version.txt

Note that tho I have very slow (2MBs/down) DSL internet, maybe google throttles downloads to even slower speeds??? More likely just my horrible speed of my declining century-link (aka brightspeed) ISP...
Here's the contents of short 2-entry cloudready_recovery2.conf file...

$  % curl -LGO https://dl.google.com/dl/edgedl/chromeos/recovery/cloudready_recovery2.conf
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   874  100   874    0     0    922      0 --:--:-- --:--:-- --:--:--   938
$ cat cloudready_recovery2.conf 
recovery_tool_version=0.9.2
recovery_tool_linux_version=0.9.2
recovery_tool_update=


name=ChromeOS Flex
version=14794.0.0
desc=
channel=DEV
hwidmatch=^REVEN($|-.*)
hwid=
md5=442e88dec2cf2201c82c60cc6ee9a8f6
sha1=93ebd1cf8c3463e668cc507f1b165ced6791831e
zipfilesize=1174071023
file=chromeos_14794.0.0_reven_recovery_dev-channel_mp-v2.bin
filesize=6939566592
url=https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_14794.0.0_reven_recovery_dev-channel_mp-v2.bin.zip


name=ChromeOS Flex
version=15117.112.0
desc=
channel=STABLE
hwidmatch=^REVEN($|-.*)
hwid=
md5=23cc0c6a0c0976e626e15f08b03a8691
sha1=99dd29cbc92df4a72f5c65348764a0b83a0f2bd5
zipfilesize=1206930016
file=chromeos_15117.112.0_reven_recovery_stable-channel_mp-v2.bin
filesize=6939566592
url=https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_15117.112.0_reven_recovery_stable-channel_mp-v2.bin.zip%                                          
$ 

Note the zipfilesize=1206930016 matches the actual size of downloaded zip file. The recovery.sh script does warn if any of these are wrong: zipfilesize, filesize after unzip, checksum (md5 or sha1) of the zip file.

Running ./recovery.sh with no command-line arguments presents a menu of over 400 chromebook *bin.zip files to download...

$  cd /tmp
$ curl "https://chromium.googlesource.com/chromiumos/user-recovery-tools/+/master/linux/recovery.sh?format=TEXT" \
-s --output - |  base64 --decode > recovery.sh
$ chmod a+x recovery.sh
Working in /tmp/tmp.crosrec/
Downloading config file from https://dl.google.com/dl/edgedl/chromeos/recovery/recovery.conf
If you know the Model string displayed at the recovery screen,
type some or all of it; otherwise just press Enter: 
This may take a few minutes to print the full list...
There are 442 recovery images to choose from:
...

0 - <quit>
1 - Dell Chromebook 13 (3380)
      channel:  STABLE
2 - ASUS Chromebook Flip CM3200FM1A
      channel:  STABLE
...
441 - Lenovo ThinkPad C13 Yoga Chromebook / Lenovo ThinkPad C13 Yoga Chromebook Enterprise
      channel:  STABLE
442 - NEC Chromebook Y1 Gen3A
      channel:  STABLE

Please select a recovery image to download: 244

Downloading image zipfile from https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_15117.111.0_octopus_recovery_stable-channel_mp-v31.bin.zip

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  Dload  Upload   Total   Spent    Left  Speed
100 1727M  100 1727M    0     0   220k      0  2:13:25  2:13:25 --:--:-- 85118
Unpacking the zipfile
Archive:  chromeos_15117.111.0_octopus_recovery_stable-channel_mp-v31.bin.zip
  inflating: chromeos_15117.111.0_octopus_recovery_stable-channel_mp-v31.bin  

I can't seem to find a valid USB drive.  We need one with at least 4773MB capacity.
0 - <quit>

Tell me what to do (or just press Enter to scan again): 0
$  ls -lrt *.zip
-rw-r--r--  1 student  wheel  293654528 Dec  2 19:24 chromeos_14794.0.0_reven_recovery_dev-channel_mp-v2.bin.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment