From 838c520f557de7f133c56306b1ff6f9d2d3d9feb Mon Sep 17 00:00:00 2001 From: Ruben Esteve Date: Wed, 8 Jul 2020 00:50:22 +0200 Subject: [PATCH 1/2] Use jq to parse JSON --- selenium/build.sh | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/selenium/build.sh b/selenium/build.sh index c6e837eb7..afc91dc9e 100755 --- a/selenium/build.sh +++ b/selenium/build.sh @@ -32,13 +32,14 @@ download_selenium() { } download_geckodriver() { - geckodriver_driver_url="" + local tag="" if [ "$1" == "latest" ]; then - geckodriver_driver_url=$(wget -qO- "https://api.github.com/repos/mozilla/geckodriver/releases/latest" | awk -F '"' '/browser_download_url.*?linux64.tar.gz/{print $4}') + tag="$1" else - geckodriver_driver_url=$(wget -qO- "https://api.github.com/repos/mozilla/geckodriver/releases/tags/v$1" | awk -F '"' '/browser_download_url.*?linux64.tar.gz/{print $4}') + tag="tags/v$1" fi - wget -O geckodriver.tar.gz $geckodriver_driver_url + local download_url=$(wget -qO- "https://api.github.com/repos/mozilla/geckodriver/releases/$tag" | jq -r '.assets[].browser_download_url | select(contains("linux64"))') + wget -O geckodriver.tar.gz "$download_url" tar xvzf geckodriver.tar.gz rm -Rf geckodriver.tar.gz } @@ -50,13 +51,14 @@ download_chromedriver() { } download_operadriver() { - operadriver_driver_url="" + local tag="" if [ "$1" == "latest" ]; then - operadriver_driver_url=$(wget -qO- "https://api.github.com/repos/operasoftware/operachromiumdriver/releases/latest" | awk -F '"' '/browser_download_url.*?linux64.zip/{print $4}') + tag="$1" else - operadriver_driver_url=$(wget -qO- "https://api.github.com/repos/operasoftware/operachromiumdriver/releases/tags/v.$1" | awk -F '"' '/browser_download_url.*?linux64.zip/{print $4}') + tag="tags/v.$1" fi - wget -O operadriver.zip $operadriver_driver_url + local download_url=$(wget -qO- "https://api.github.com/repos/operasoftware/operachromiumdriver/releases/$tag" | jq -r '.assets[].browser_download_url | select(contains("linux64"))') + wget -O operadriver.zip "$download_url" unzip operadriver.zip if [ -d operadriver_linux64 ]; then cp operadriver_linux64/operadriver ./operadriver @@ -66,30 +68,31 @@ download_operadriver() { } download_yandexdriver() { - yandex_driver_url="" + local download_url="" if [ "$1" == "latest" ]; then - yandex_driver_url=$(wget -qO- "https://api.github.com/repos/yandex/YandexDriver/releases" | awk -F '"' '/browser_download_url.*?linux.zip/{print $4;exit}') + download_url=$(wget -qO- "https://api.github.com/repos/yandex/YandexDriver/releases" | jq -r 'first(.[].assets[].browser_download_url | select(contains("linux")))') else - yandex_driver_url=$(wget -qO- "https://api.github.com/repos/yandex/YandexDriver/releases/tags/v$1-stable" | awk -F '"' '/browser_download_url.*?linux.zip/{print $4}') - if [ -z "$yandex_driver_url" ]; then + download_url=$(wget -qO- "https://api.github.com/repos/yandex/YandexDriver/releases/tags/v$1-stable" | jq -r '.assets[].browser_download_url | select(contains("linux"))') + if [ -z "$download_url" ]; then echo "Unsupported Yandexdriver version: $1" exit 1 fi fi - wget -O yandexdriver.zip $yandex_driver_url + wget -O yandexdriver.zip "$download_url" unzip yandexdriver.zip chmod +x yandexdriver rm yandexdriver.zip } download_selenoid() { - selenoid_url="" + local tag="" if [ "$1" == "latest" ]; then - selenoid_url=$(wget -qO- "https://api.github.com/repos/aerokube/selenoid/releases/latest" | awk -F '"' '/browser_download_url.*?linux_amd64/{print $4}') + tag="$1" else - selenoid_url=$(wget -qO- "https://api.github.com/repos/aerokube/selenoid/releases/tags/$1" | awk -F '"' '/browser_download_url.*?linux_amd64/{print $4}') + tag="tags/$1" fi - wget -O selenoid $selenoid_url + local download_url=$(wget -qO- "https://api.github.com/repos/aerokube/selenoid/releases/$tag" | jq -r '.assets[].browser_download_url | select(contains("linux_amd64"))') + wget -O selenoid "$download_url" chmod +x selenoid } From 6e5cbab986d5b986b82d7506f16cdbcfa1617493 Mon Sep 17 00:00:00 2001 From: Ruben Esteve Date: Thu, 9 Jul 2020 19:48:19 +0200 Subject: [PATCH 2/2] Check required commands --- selenium/automate_chrome.sh | 20 ++++++++++++++++++++ selenium/automate_firefox.sh | 20 ++++++++++++++++++++ selenium/automate_opera.sh | 20 ++++++++++++++++++++ selenium/automate_yandex.sh | 20 ++++++++++++++++++++ 4 files changed, 80 insertions(+) diff --git a/selenium/automate_chrome.sh b/selenium/automate_chrome.sh index d540b61d9..ce4078221 100755 --- a/selenium/automate_chrome.sh +++ b/selenium/automate_chrome.sh @@ -1,5 +1,25 @@ #!/bin/bash + set -e + +require_command(){ + cmd_name=$1 + if [ -z $(command -v $1) ]; then + echo "$1 command required for this script to run" + exit 1 + fi +} + +require_command "awk" +require_command "cut" +require_command "docker" +require_command "ifconfig" +require_command "sed" +require_command "true" +require_command "unzip" +require_command "uuidgen" +require_command "wget" + input=$1 driver_version=$2 tag=$3 diff --git a/selenium/automate_firefox.sh b/selenium/automate_firefox.sh index a32b9a4cd..81e386016 100755 --- a/selenium/automate_firefox.sh +++ b/selenium/automate_firefox.sh @@ -1,5 +1,25 @@ #!/bin/bash set -e + +require_command(){ + cmd_name=$1 + if [ -z $(command -v $1) ]; then + echo "$1 command required for this script to run" + exit 1 + fi +} + +require_command "awk" +require_command "cut" +require_command "docker" +require_command "ifconfig" +require_command "jq" +require_command "sed" +require_command "tar" +require_command "true" +require_command "uuidgen" +require_command "wget" + input=$1 server_version=$2 tag=$3 diff --git a/selenium/automate_opera.sh b/selenium/automate_opera.sh index 1acfc579f..00a906ebc 100755 --- a/selenium/automate_opera.sh +++ b/selenium/automate_opera.sh @@ -1,5 +1,25 @@ #!/bin/bash set -e + +require_command(){ + cmd_name=$1 + if [ -z $(command -v $1) ]; then + echo "$1 command required for this script to run" + exit 1 + fi +} + +require_command "awk" +require_command "cut" +require_command "docker" +require_command "ifconfig" +require_command "jq" +require_command "sed" +require_command "true" +require_command "unzip" +require_command "uuidgen" +require_command "wget" + input=$1 driver_version=$2 tag=$3 diff --git a/selenium/automate_yandex.sh b/selenium/automate_yandex.sh index a1510436d..a8389c02d 100755 --- a/selenium/automate_yandex.sh +++ b/selenium/automate_yandex.sh @@ -1,5 +1,25 @@ #!/bin/bash set -e + +require_command(){ + cmd_name=$1 + if [ -z $(command -v $1) ]; then + echo "$1 command required for this script to run" + exit 1 + fi +} + +require_command "awk" +require_command "cut" +require_command "docker" +require_command "ifconfig" +require_command "jq" +require_command "sed" +require_command "true" +require_command "unzip" +require_command "uuidgen" +require_command "wget" + input=$1 driver_version=$2 tag=$3