Starbeamrainbowlabs

Stardust
Blog

Chromium nightly script

I don't really like chrome (I could write an entire blog post about this), but sometimes circumstances demand I have to use a blink-based (Chromium's rendering engine) browser for some rare and limited but equally essential tasks.

Unfortunately, the default chromium package in Ubuntu is now a snap, which complicates matters as snaps generally cause issues I'd rather not deal with on my system. This left me out of options, until I did some digging and found that chromium nightly was available to download as a zip. Fast-forward an hour and I now have a quick little script that automates the process of downloading and running chromium nightly, so I thought I'd share it here.

I've talked about shell scripts being lego before (exhibits A, B, C, and D), and the same applies here - so I'll break it down and explain each part. Let's set out first what we want to do:

  1. If chromium has already been downloaded, skip to step 4
  2. Download .zip from https://download-chromium.appspot.com/dl/Linux_x64?type=snapshots
  3. Extract to somewhere in /tmp
  4. Run the chromium binary

Now, let's put this together into a shell script. First, let's define some variables:

#!/usr/bin/env bash

set -e;
download_url="https://download-chromium.appspot.com/dl/Linux_x64?type=snapshots";
temp_dir="/tmp/chromium-nightly";

#!/usr/bin/env bash tells Linux to run the script with Bash - this must be the first line of the file. set -e tells Bash to exit immediately if any errors are encountered instead of trying to continue - this is a shell flag, so you could get the same effect by executing a script like bash -e path/to/script.sh instead of doing it here, but in this case we always want the option to be set, hence the use of set here instead.

Now, let's create that temporary directory:

if [[ ! -d "${temp_dir}" ]]; then mkdir "${temp_dir}"; fi

Next on the list is to to check if we've already downloaded chromium nightly already. The laziest way I can think of to do this is to check if the chrome binary exists or not and whether it's executable. This can be done like so:

if [[ ! -x "${temp_dir}/chrome-linux/chrome" ]]; then
    echo "download chromium nightly here";
fi

If statements are a bit weird in Bash. -x checks to see if the file at the following path is executable or not, and ! inverts it.

Next, we need to download the archive. Let's do that inside the if statement:

    echo ">>> Downloading chromium" >&2;
    curl -SL --progress-bar "${download_url}" -o "${temp_dir}/chromium.zip";

>&2 sends the output to the standard error instead of the standard output. curl is a command for downloading things from the internet. We provide the URL to download (it supports almost every protocol imaginable, but here we're just using https) and the place to download it to (-o), and it does the rest.

Next up is extracting it:

    echo ">>> Extracting zip" >&2;
    unzip "${temp_dir}/chromium.zip" -d "${temp_dir}";

    echo ">>> Cleaning up" >&2;
    rm "${temp_dir}/chromium.zip";

unzip is the command to unzip .zip archives, and -d tells it the directory to extract everything to. Here I manually downloaded the file at the download URL and inspected it with the file command (file path/to/unknown_file) to see what format I was dealing with - then once I knew it was a .zip archive I chose chromium.zip as the filename to download it to.

In cases where I have a file with the correct file extension that I want to extract as a one-off, I also have an all-in-one script that can automatically determine the right extractor for it. Here though we use the direct command to simplify the script.

Finally, we delete the .zip after we're done extracting it, as it's no longer needed.

Now that chromium nightly is downloaded, we can start it like so:

echo ">>> Starting chromium" >&2;
exec "${temp_dir}/chrome-linux/chrome";

...and we're done! exec here is a builtin that replaces the current process with another, which reduces the number of running processes. Here's the full script:

(Can't see the above? Try a direct link)

Shell scripts - like this one - can be really useful for automating repetitive tasks. Whether you use Linux, macOS, Windows, or something else I can absolutely recommend learning your system's default shell scripting language - it will save you a lot of time.

Let me know if you have any questions about this or shell scripting in the comments below, and I'll do my best to help.

Tag Cloud

3d 3d printing account algorithms android announcement architecture archives arduino artificial intelligence artix assembly async audio automation backups bash batch blender blog bookmarklet booting bug hunting c sharp c++ challenge chrome os cluster code codepen coding conundrums coding conundrums evolved command line compilers compiling compression conference conferences containerisation css dailyprogrammer data analysis debugging defining ai demystification distributed computing dns docker documentation downtime electronics email embedded systems encryption es6 features ethics event experiment external first impressions freeside future game github github gist gitlab graphics guide hardware hardware meetup holiday holidays html html5 html5 canvas infrastructure interfaces internet interoperability io.js jabber jam javascript js bin labs latex learning library linux lora low level lua maintenance manjaro minetest network networking nibriboard node.js open source operating systems optimisation outreach own your code pepperminty wiki performance phd photos php pixelbot portable privacy problem solving programming problems project projects prolog protocol protocols pseudo 3d python reddit redis reference release releases rendering research resource review rust searching secrets security series list server software sorting source code control statistics storage svg systemquery talks technical terminal textures thoughts three thing game three.js tool tutorial twitter ubuntu university update updates upgrade version control virtual reality virtualisation visual web website windows windows 10 worldeditadditions xmpp xslt

Archive

Art by Mythdael