Created
March 9, 2017 16:09
-
-
Save mafredri/26f19ee658b28d14693efee26b527251 to your computer and use it in GitHub Desktop.
Script to build (and update) headless Chromium on Ubuntu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
# This script checks out the latest chromium and builds the headless | |
# version of it. When the chromium source is already present, the | |
# repository is updated. | |
# | |
# A .tar.gz is created in $DIR containing the headless_shell binary, | |
# this binary runs chromium. The resulting binary should be quite | |
# portable given that the (few) dependencies are installed on the target | |
# machine. | |
# | |
# This script has been tested on: | |
# - Ubuntu 14.04 (Trusty) | |
# | |
# WARNING! Building Chromium requires root privileges and installs many | |
# packages via apt, avoid doing this on production systems. A throw-away | |
# VM or docker container is probably for the best. | |
# | |
# README (doesn't contain much): | |
# https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md | |
BUILD_CONFIG=' | |
import("//build/args/headless.gn") | |
is_debug=false | |
symbol_level=0 | |
enable_nacl=false | |
remove_webcore_debug_symbols=true | |
' | |
DIR=~/chromium | |
[[ -d $DIR ]] || mkdir $DIR | |
[[ -d $DIR/depot_tools ]] || { | |
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $DIR/depot_tools | |
} | |
(cd $DIR/depot_tools; git pull) | |
PATH=$PATH:$DIR/depot_tools | |
(cd $DIR; | |
# Fetch the chromium repository without history. | |
[[ -d src ]] || { | |
fetched=1 | |
fetch --no-history --nohooks chromium # Run hooks later. | |
} | |
cd src | |
[[ $fetched = 1 ]] || { | |
# Update repository if already fetched. | |
git rebase-update | |
gclient sync | |
} | |
./build/install-build-deps.sh --no-prompt # Must run before runhooks. | |
gclient runhooks | |
# Configure the build. | |
[[ -d out/Headless ]] && rm -r out/Headless | |
mkdir -p out/Headless | |
print $BUILD_CONFIG > out/Headless/args.gn | |
gn gen out/Headless | |
# Start the build. | |
ninja -j 8 -C out/Headless headless_shell | |
[[ -f $DIR/ChromiumHeadless.tar.gz ]] && rm $DIR/ChromiumHeadless.tar.gz | |
tar -cvzf $DIR/ChromiumHeadless.tar.gz out/Headless | |
) | |
print "Created $DIR/ChromiumHeadless.tar.gz" | |
print " tar -xvzf $DIR/ChromiumHeadless.tar.gz" | |
print " ./out/Headless/headless_shell --headless --disable-gpu --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222" | |
print "Remember to: apt install libexpat1 libfontconfig1 libfreetype6 libnspr4 libnss3 libpng12-0" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment