|
| 1 | +#!/bin/bash |
| 2 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | +# |
| 6 | +# This Source Code Form is "Incompatible With Secondary Licenses", as |
| 7 | +# defined by the Mozilla Public License, v. 2.0. |
| 8 | + |
| 9 | +################################################## |
| 10 | +# Common checks and functions for docker scripts # |
| 11 | +################################################## |
| 12 | + |
| 13 | +# Function to print text in red if terminal supports it |
| 14 | +echo_red() { |
| 15 | + if [ -t 1 ] && command -v tput >/dev/null 2>&1 && [ $(tput colors 2>/dev/null || echo 0) -ge 8 ]; then |
| 16 | + echo -e "\033[31m$1\033[0m" |
| 17 | + else |
| 18 | + echo "$1" |
| 19 | + fi |
| 20 | +} |
| 21 | + |
| 22 | +# Function to print text in green if terminal supports it |
| 23 | +echo_green() { |
| 24 | + if [ -t 1 ] && command -v tput >/dev/null 2>&1 && [ $(tput colors 2>/dev/null || echo 0) -ge 8 ]; then |
| 25 | + echo -e "\033[32m$1\033[0m" |
| 26 | + else |
| 27 | + echo "$1" |
| 28 | + fi |
| 29 | +} |
| 30 | + |
| 31 | +# Check that we're in the root of the Bugzilla source tree |
| 32 | +if [ ! -e 'Makefile.PL' ]; then |
| 33 | + echo |
| 34 | + echo_red "Please run this from the root of the Bugzilla source tree." |
| 35 | + echo |
| 36 | + exit -1 |
| 37 | +fi |
| 38 | + |
| 39 | +# Find and validate the Docker executable |
| 40 | +if [ -z "$DOCKER" ]; then |
| 41 | + DOCKER=`which docker` |
| 42 | +fi |
| 43 | +if [ -n "$DOCKER" ] && [ ! -x "$DOCKER" ]; then |
| 44 | + echo |
| 45 | + echo_red "You specified a custom Docker executable via the DOCKER" |
| 46 | + echo_red "environment variable at $DOCKER" |
| 47 | + echo_red "which either does not exist or is not executable." |
| 48 | + echo "Please fix it to point at a working Docker or remove the" |
| 49 | + echo "DOCKER environment variable to use the one in your PATH" |
| 50 | + echo "if it exists." |
| 51 | + echo |
| 52 | + exit -1 |
| 53 | +fi |
| 54 | +if [ -z "$DOCKER" ]; then |
| 55 | + echo |
| 56 | + echo_red "You do not appear to have docker installed or I can't find it." |
| 57 | + echo "Windows and Mac versions can be downloaded from" |
| 58 | + echo "https://www.docker.com/products/docker-desktop" |
| 59 | + echo "Linux users can install using your package manager." |
| 60 | + echo |
| 61 | + echo "Please install docker or specify the location of the docker" |
| 62 | + echo "executable in the DOCKER environment variable and try again." |
| 63 | + echo |
| 64 | + exit -1 |
| 65 | +fi |
| 66 | + |
| 67 | +# Check that Docker daemon is running |
| 68 | +$DOCKER info 1>/dev/null 2>/dev/null |
| 69 | +if [ $? != 0 ]; then |
| 70 | + echo |
| 71 | + echo_red "The docker daemon is not running or I can't connect to it." |
| 72 | + echo "Please make sure it's running and try again." |
| 73 | + echo |
| 74 | + exit -1 |
| 75 | +fi |
| 76 | + |
| 77 | +# Disable Docker CLI hints |
| 78 | +export DOCKER_CLI_HINTS=false |
0 commit comments