|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Invoke with `source "$BUILDPACK_DIR/bin/install-chrome-dependencies"` from inside `bin/compile`. |
| 3 | +# This script is mostly copied from: |
| 4 | +# https://github.com/heroku/heroku-buildpack-google-chrome/blob/master/bin/compile |
| 5 | + |
| 6 | +# Uses variables & methods from compile script: |
| 7 | +# BUILD_DIR |
| 8 | +# CACHE_DIR |
| 9 | +# ENV_DIR |
| 10 | +# BUILDPACK_DIR |
| 11 | +# topic() |
| 12 | +# indent() |
| 13 | + |
| 14 | +topic "Installing Chrome dependencies" |
| 15 | + |
| 16 | +# Install correct dependencies according to $STACK |
| 17 | +case "${STACK}" in |
| 18 | + "heroku-18" | "heroku-20" | "heroku-22") |
| 19 | + # the package list is found by using ci:debug then running ldd $GOOGLE_CHROME_BIN | grep not |
| 20 | + # also look here for more packages/notes https://developers.google.com/web/tools/puppeteer/troubleshooting |
| 21 | + PACKAGES=" |
| 22 | + gconf-service |
| 23 | + libappindicator1 |
| 24 | + libasound2 |
| 25 | + libatk1.0-0 |
| 26 | + libatk-bridge2.0-0 |
| 27 | + libcairo-gobject2 |
| 28 | + libdrm2 |
| 29 | + libgbm1 |
| 30 | + libgconf-2-4 |
| 31 | + libgtk-3-0 |
| 32 | + libnspr4 |
| 33 | + libnss3 |
| 34 | + libx11-xcb1 |
| 35 | + libxcb-dri3-0 |
| 36 | + libxcomposite1 |
| 37 | + libxcursor1 |
| 38 | + libxdamage1 |
| 39 | + libxfixes3 |
| 40 | + libxi6 |
| 41 | + libxinerama1 |
| 42 | + libxrandr2 |
| 43 | + libxshmfence1 |
| 44 | + libxss1 |
| 45 | + libxtst6 |
| 46 | + fonts-liberation |
| 47 | + " |
| 48 | + ;; |
| 49 | + *) |
| 50 | + error "STACK must be 'heroku-18', 'heroku-20' or 'heroku-22', not '${STACK}'." |
| 51 | +esac |
| 52 | + |
| 53 | +if [ ! -f $CACHE_DIR/PURGED_CACHE_V1 ]; then |
| 54 | + echo "Purging cache" | indent |
| 55 | + rm -rf $CACHE_DIR/apt |
| 56 | + rm -rf $CACHE_DIR/archives |
| 57 | + rm -rf $CACHE_DIR/lists |
| 58 | + touch $CACHE_DIR/PURGED_CACHE_V1 |
| 59 | +fi |
| 60 | + |
| 61 | +# This is where the original buildpack installed Chrome itself, |
| 62 | +# but Chrome for Testing is installed from direct downloads. |
| 63 | +# |
| 64 | +# echo "Installing Google Chrome from the $channel channel." | indent |
| 65 | +# PACKAGES="$PACKAGES https://dl.google.com/linux/direct/google-chrome-${channel}_current_amd64.deb" |
| 66 | + |
| 67 | +APT_CACHE_DIR="$CACHE_DIR/apt/cache" |
| 68 | +APT_STATE_DIR="$CACHE_DIR/apt/state" |
| 69 | + |
| 70 | +mkdir -p "$APT_CACHE_DIR/archives/partial" |
| 71 | +mkdir -p "$APT_STATE_DIR/lists/partial" |
| 72 | + |
| 73 | +APT_OPTIONS="-o debug::nolocking=true -o dir::cache=$APT_CACHE_DIR -o dir::state=$APT_STATE_DIR" |
| 74 | + |
| 75 | +echo "Updating apt caches" | indent |
| 76 | +apt-get $APT_OPTIONS update | indent |
| 77 | + |
| 78 | +for PACKAGE in $PACKAGES; do |
| 79 | + if [[ $PACKAGE == *deb ]]; then |
| 80 | + PACKAGE_NAME=$(basename $PACKAGE .deb) |
| 81 | + PACKAGE_FILE=$APT_CACHE_DIR/archives/$PACKAGE_NAME.deb |
| 82 | + |
| 83 | + echo "Fetching $PACKAGE" | indent |
| 84 | + curl -s -L -z $PACKAGE_FILE -o $PACKAGE_FILE $PACKAGE 2>&1 | indent |
| 85 | + else |
| 86 | + echo "Fetching .debs for $PACKAGE" | indent |
| 87 | + apt-get $APT_OPTIONS -y --force-yes -d install --reinstall $PACKAGE | indent |
| 88 | + fi |
| 89 | +done |
| 90 | + |
| 91 | +mkdir -p $BUILD_DIR/.apt |
| 92 | + |
| 93 | +for DEB in $(ls -1 $APT_CACHE_DIR/archives/*.deb); do |
| 94 | + echo "Installing $(basename $DEB)" | indent |
| 95 | + dpkg -x $DEB $BUILD_DIR/.apt/ |
| 96 | +done |
| 97 | + |
| 98 | +echo "Writing profile script" | indent |
| 99 | +mkdir -p $BUILD_DIR/.profile.d |
| 100 | +cat <<EOF >$BUILD_DIR/.profile.d/000_apt.sh |
| 101 | +export PATH="\$HOME/.apt/usr/bin:\$PATH" |
| 102 | +export LD_LIBRARY_PATH="\$HOME/.apt/usr/lib/x86_64-linux-gnu:\$HOME/.apt/usr/lib/i386-linux-gnu:\$HOME/.apt/usr/lib:\$LD_LIBRARY_PATH" |
| 103 | +export LIBRARY_PATH="\$HOME/.apt/usr/lib/x86_64-linux-gnu:\$HOME/.apt/usr/lib/i386-linux-gnu:\$HOME/.apt/usr/lib:\$LIBRARY_PATH" |
| 104 | +export INCLUDE_PATH="\$HOME/.apt/usr/include:\$HOME/.apt/usr/include/x86_64-linux-gnu:\$INCLUDE_PATH" |
| 105 | +export CPATH="\$INCLUDE_PATH" |
| 106 | +export CPPPATH="\$INCLUDE_PATH" |
| 107 | +export PKG_CONFIG_PATH="\$HOME/.apt/usr/lib/x86_64-linux-gnu/pkgconfig:\$HOME/.apt/usr/lib/i386-linux-gnu/pkgconfig:\$HOME/.apt/usr/lib/pkgconfig:\$PKG_CONFIG_PATH" |
| 108 | +EOF |
| 109 | + |
| 110 | +export PATH="$BUILD_DIR/.apt/usr/bin:$PATH" |
| 111 | +export LD_LIBRARY_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu:$BUILD_DIR/.apt/usr/lib:$LD_LIBRARY_PATH" |
| 112 | +export LIBRARY_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu:$BUILD_DIR/.apt/usr/lib:$LIBRARY_PATH" |
| 113 | +export INCLUDE_PATH="$BUILD_DIR/.apt/usr/include:$BUILD_DIR/.apt/usr/include/x86_64-linux-gnu:$INCLUDE_PATH" |
| 114 | +export CPATH="$INCLUDE_PATH" |
| 115 | +export CPPPATH="$INCLUDE_PATH" |
| 116 | +export PKG_CONFIG_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu/pkgconfig:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu/pkgconfig:$BUILD_DIR/.apt/usr/lib/pkgconfig:$PKG_CONFIG_PATH" |
| 117 | + |
| 118 | +#give environment to later buildpacks |
| 119 | +export | grep -E -e ' (PATH|LD_LIBRARY_PATH|LIBRARY_PATH|INCLUDE_PATH|CPATH|CPPPATH|PKG_CONFIG_PATH)=' > "$BUILDPACK_DIR/export" |
| 120 | + |
| 121 | +echo "Installed Chrome dependencies for $STACK" | indent |
0 commit comments