From ac5281a65c40c522277418895b3843f4bf603a5a Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 27 Jan 2021 13:16:08 -0700 Subject: [PATCH] add chromedriver --- chromedriver/README.md | 52 ++++++++++++++++++++++++ chromedriver/install.ps1 | 60 +++++++++++++++++++++++++++ chromedriver/install.sh | 39 ++++++++++++++++++ chromedriver/releases.js | 88 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 239 insertions(+) create mode 100644 chromedriver/README.md create mode 100644 chromedriver/install.ps1 create mode 100644 chromedriver/install.sh create mode 100644 chromedriver/releases.js diff --git a/chromedriver/README.md b/chromedriver/README.md new file mode 100644 index 0000000..e51f168 --- /dev/null +++ b/chromedriver/README.md @@ -0,0 +1,52 @@ +--- +title: ChromeDriver +homepage: https://chromedriver.chromium.org +tagline: | + ChromeDriver: WebDriver for Chrome +--- + +To update or switch versions, run `webi chromedriver@stable` (or `@v2`, `@beta`, +etc). + +## Cheat Sheet + +> WebDriver is an open source tool for automated testing of webapps across many +> browsers. ChromeDriver is a WebDriver created by the Chromium (Google Chrome) +> team - for Selenium and such. + +You probably won't run `chromedriver` manually, but it must be installed for +some testing frameworks. + +Also, **Chrome must be installed first** in order for ChromeDriver to work. + +### How to Install Chrome on Linux + +On Debian (and Ubuntu) Linux you should be able to install Chrome with `dpkg` +and `apt`: + +```bash +wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb +sudo dpkg -i google-chrome-stable_current_amd64.deb +sudo apt install -y google-chrome-stable +sudo apt --fix-broken install -y +``` + +You may get an error like this: + +```txt +chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory +``` + +If so, try installing `chromium-browser`: + +```bash +sudo apt install -y chromium-browser +sudo apt --fix-broken install -y +``` + +### Other Notes + +On Windows `chromedriver.exe` _should_ Just Work™. + +On macOS you may need to install XCode Command Line Tools with +`xcode-select --install`. diff --git a/chromedriver/install.ps1 b/chromedriver/install.ps1 new file mode 100644 index 0000000..459df0a --- /dev/null +++ b/chromedriver/install.ps1 @@ -0,0 +1,60 @@ +#!/usr/bin/env pwsh + +################## +# Install chromedriver # +################## + +# Every package should define these variables +$pkg_cmd_name = "chromedriver" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\chromedriver.exe" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\chromedriver-v$Env:WEBI_VERSION\bin\chromedriver.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\chromedriver-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\chromedriver-v$Env:WEBI_VERSION" +$pkg_src = "$pkg_src_cmd" + +$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" + +# Fetch archive +IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE")) +{ + # TODO: arch detection + echo "Downloading chromedriver from $Env:WEBI_PKG_URL to $pkg_download" + & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part" + & move "$pkg_download.part" "$pkg_download" +} + +IF (!(Test-Path -Path "$pkg_src_cmd")) +{ + echo "Installing chromedriver" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path ".\chromedriver.exe" -Recurse -ErrorAction Ignore + + # NOTE: DELETE THIS COMMENT IF NOT USED + # Move single binary into root of temporary folder + #& move "$pkg_download" "chromedriver.exe" + + # Unpack archive file into this temporary directory + # Windows BSD-tar handles zip. Imagine that. + echo "Unpacking $pkg_download" + & tar xf "$pkg_download" + + # Settle unpacked archive into place + echo "Install Location: $pkg_src_cmd" + New-Item "$pkg_src_bin" -ItemType Directory -Force + Move-Item -Path ".\chromedriver-*\chromedriver.exe" -Destination "$pkg_src_bin" + + # Exit tmp + popd +} + +echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'" +Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore +Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse diff --git a/chromedriver/install.sh b/chromedriver/install.sh new file mode 100644 index 0000000..d57d8b5 --- /dev/null +++ b/chromedriver/install.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +{ + set -e + set -u + + ######################## + # Install chromedriver # + ######################## + + # Every package should define these 6 variables + pkg_cmd_name="chromedriver" + + pkg_dst_cmd="$HOME/.local/bin/chromedriver" + pkg_dst="$pkg_dst_cmd" + + pkg_src_cmd="$HOME/.local/opt/chromedriver-v$WEBI_VERSION/bin/chromedriver" + pkg_src_dir="$HOME/.local/opt/chromedriver-v$WEBI_VERSION" + pkg_src="$pkg_src_cmd" + + # pkg_install must be defined by every package + pkg_install() { + # ~/.local/opt/chromedriver-v88.0.4324.96/bin + mkdir -p "$(dirname $pkg_src_cmd)" + + # mv ./chromedriver-*/chromedriver ~/.local/opt/chromedriver-v88.0.4324.96/bin/chromedriver + mv ./chromedriver* "$pkg_src_cmd" + } + + # pkg_get_current_version is recommended, but (soon) not required + pkg_get_current_version() { + # 'chromedriver --version' has output in this format: + # ChromeDriver 88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324@{#1784}) + # This trims it down to just the version number: + # 88.0.4324.96 + echo $(chromedriver --version 2>/dev/null | head -n 1 | cut -d ' ' -f 2) + } + +} diff --git a/chromedriver/releases.js b/chromedriver/releases.js new file mode 100644 index 0000000..05eb382 --- /dev/null +++ b/chromedriver/releases.js @@ -0,0 +1,88 @@ +'use strict'; + +var matchers = { + key: /.*Key>(.*)<\/Key.*/, + generation: /.*Generation>(.*)<\/Generation.*/, + metaGeneration: /.*MetaGeneration>(.*)<\/MetaGeneration.*/, + lastModified: /.*LastModified>(.*)<\/LastModified.*/, + etag: /.*ETag>(.*)<\/ETag.*/, + size: /.*Size>(.*)<\/Size.*/ +}; +var baseUrl = 'https://chromedriver.storage.googleapis.com'; + +module.exports = function (request) { + var all = { + download: '', + releases: [] + }; + + // XML + return request({ + url: 'https://chromedriver.storage.googleapis.com/', + json: false + }) + .then(function (resp) { + var body = resp.body; + var groups = body.split(/<\/?Contents>/g); + // get rid of leading and trailing junk + groups.shift(); + groups.pop(); + var metas = groups.map(function (group) { + return { + key: group.replace(matchers.key, '$1'), + //generation: group.replace(matchers.generation, '$1'), + //metaGeneration: group.replace(matchers.metaGeneration, '$1'), + lastModified: group.replace(matchers.lastModified, '$1') + //etag: group.replace(matchers.etag, '$1'), + //size: group.replace(matchers.size, '$1') + }; + }); + all.download = baseUrl + '/{{ download }}'; + metas.forEach(function (asset) { + if (!asset.key.includes('chromedriver')) { + // skip the indexes, images, etc + return null; + } + + var osname = asset.key.replace(/.*(win|mac|linux)/, '$1'); + var arch; + if (asset.key.includes('linux')) { + osname = 'linux'; + } else if (asset.key.includes('mac64')) { + osname = 'macos'; + if (asset.key.includes('_m1.')) { + arch = 'arm64'; + } + } else if (asset.key.includes('win')) { + osname = 'windows'; + arch = 'amd64'; + } + all.releases.push({ + // 87.0.4280.88/chromedriver_win32.zip => 87.0.4280.88 + version: asset.key.replace(/(.*)\/.*/, '$1'), + lts: false, + channel: 'stable', + date: asset.lastModified.replace(/T.*/, '$1'), + os: osname, + arch: arch, + hash: '-', // not sure about including etag as hash yet + download: asset.key + }); + }); + }) + .then(function () { + all.releases.sort(function (a, b) { + return new Date(b.date).valueOf() - new Date(a.date).valueOf(); + }); + return all; + }); +}; + +if (module === require.main) { + module.exports(require('@root/request')).then(function (all) { + all = require('../_webi/normalize.js')(all); + // just select the latest 5 for demonstration + all.releases = all.releases.slice(-20); + console.info(JSON.stringify(all, null, 2)); + }); +} -- 2.25.1