Skip to content

Commit

Permalink
Examine all scripts in scripts/drevops for any binaries that are used…
Browse files Browse the repository at this point in the history
… and exit if they are not found.
  • Loading branch information
tannguyen04 committed Apr 17, 2024
1 parent 3a97f9f commit 404e9ba
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 10 deletions.
2 changes: 2 additions & 0 deletions scripts/drevops/deploy-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v docker >/dev/null || (fail "docker command is not available." && exit 1)

info "Started DOCKER deployment."

# Only deploy if the map was provided, but do not fail if it has not as this
Expand Down
1 change: 1 addition & 0 deletions scripts/drevops/deploy-lagoon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ if ! command -v lagoon >/dev/null || [ -n "${DREVOPS_LAGOONCLI_FORCE_INSTALL}" ]
chmod +x "${DREVOPS_LAGOONCLI_PATH}/lagoon"
export PATH="${PATH}:${DREVOPS_LAGOONCLI_PATH}"
fi
command -v lagoon >/dev/null || (fail "Command lagoon is not available." && exit 1)

note "Configuring Lagoon instance."
#shellcheck disable=SC2218
Expand Down
2 changes: 2 additions & 0 deletions scripts/drevops/deploy-webhook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v curl >/dev/null || (fail "Command curl is not available." && exit 1)

info "Started WEBHOOK deployment."

# Check all required values.
Expand Down
4 changes: 4 additions & 0 deletions scripts/drevops/doctor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
warn() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[33m[WARN] %s\033[0m\n" "${1}" || printf "[WARN] %s\n" "${1}"; }
# @formatter:on

for cmd in docker "docker compose" pygmy ahoy; do
command -v ${cmd} >/dev/null || { fail "Command ${cmd} is not available"; exit 1; };
done

#
# Main entry point.
#
Expand Down
4 changes: 4 additions & 0 deletions scripts/drevops/download-db-acquia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

for cmd in php curl gunzip; do
command -v ${cmd} >/dev/null || { fail "Command ${cmd} is not available"; exit 1; };
done

info "Started database dump download from Acquia."

#
Expand Down
2 changes: 2 additions & 0 deletions scripts/drevops/download-db-curl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v curl >/dev/null || (fail "Command curl is not available." && exit 1)

info "Started database dump download from CURL."

# Check all required values.
Expand Down
2 changes: 2 additions & 0 deletions scripts/drevops/download-db-docker-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v docker >/dev/null || (fail "Command docker is not available." && exit 1)

info "Started Docker data image download."

[ -z "${DOCKER_USER}" ] && fail "Missing required value for DOCKER_USER." && exit 1
Expand Down
2 changes: 2 additions & 0 deletions scripts/drevops/download-db-ftp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v curl >/dev/null || (fail "Command curl is not available." && exit 1)

# Check all required values.
[ -z "${DREVOPS_DB_DOWNLOAD_FTP_USER}" ] && fail "Missing required value for DREVOPS_DB_DOWNLOAD_FTP_USER." && exit 1
[ -z "${DREVOPS_DB_DOWNLOAD_FTP_PASS}" ] && fail "Missing required value for DREVOPS_DB_DOWNLOAD_FTP_PASS." && exit 1
Expand Down
4 changes: 4 additions & 0 deletions scripts/drevops/download-db-lagoon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

for cmd in ssh rsync; do
command -v ${cmd} >/dev/null || { fail "Command ${cmd} is not available"; exit 1; };
done

info "Started database dump download from Lagoon."

mkdir -p "${DREVOPS_DB_DIR}"
Expand Down
2 changes: 2 additions & 0 deletions scripts/drevops/download-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v find >/dev/null || (fail "Command find is not available." && exit 1)

info "Started database download."

[ "${DREVOPS_DB_DOWNLOAD_PROCEED}" != "1" ] && pass "Skipping database download as DB_DOWNLOAD_PROCEED is not set to 1." && exit 0
Expand Down
2 changes: 2 additions & 0 deletions scripts/drevops/export-db-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v "docker compose" >/dev/null || (fail "Command 'docker compose' is not available." && exit 1)

info "Started Docker database image export."

[ -z "${DREVOPS_DB_EXPORT_DOCKER_IMAGE}" ] && fail "Destination image name is not specified. Please provide docker image as a variable DREVOPS_DB_EXPORT_DOCKER_IMAGE in a format <org>/<repository>." && exit 1
Expand Down
2 changes: 2 additions & 0 deletions scripts/drevops/export-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v "docker compose" >/dev/null || (fail "Command 'docker compose' is not available." && exit 1)

info "Started database export."

if [ -z "${DREVOPS_DB_DOCKER_IMAGE}" ]; then
Expand Down
4 changes: 4 additions & 0 deletions scripts/drevops/github-labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

for cmd in curl sed awk; do
command -v ${cmd} >/dev/null || { fail "Command ${cmd} is not available"; exit 1; };
done

# Array of labels to create. If DELETE_EXISTING_LABELS=1, the labels list will
# be exactly as below, otherwise labels below will be added to existing ones.
labels=(
Expand Down
2 changes: 2 additions & 0 deletions scripts/drevops/login-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v docker >/dev/null || (fail "Command docker is not available." && exit 1)

# Check all required values.
[ -z "${DOCKER_REGISTRY}" ] && echo "Missing required value for DOCKER_REGISTRY." && exit 1

Expand Down
4 changes: 4 additions & 0 deletions scripts/drevops/mirror-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

for cmd in git rsync pushd popd; do
command -v ${cmd} >/dev/null || { fail "Command ${cmd} is not available"; exit 1; };
done

info "Started code mirroring."

# Check all required values.
Expand Down
5 changes: 4 additions & 1 deletion scripts/drevops/notify-github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v curl >/dev/null || (fail "curl command is not available." && exit 1)
for cmd in curl php; do
command -v ${cmd} >/dev/null || { fail "Command ${cmd} is not available"; exit 1; };
done

[ -z "${DREVOPS_NOTIFY_GITHUB_TOKEN}" ] && fail "Missing required value for DREVOPS_NOTIFY_GITHUB_TOKEN" && exit 1
[ -z "${DREVOPS_NOTIFY_REPOSITORY}" ] && fail "Missing required value for DREVOPS_NOTIFY_REPOSITORY" && exit 1
[ -z "${DREVOPS_NOTIFY_REF}" ] && fail "Missing required value for DREVOPS_NOTIFY_REF" && exit 1
Expand Down
5 changes: 4 additions & 1 deletion scripts/drevops/notify-jira.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v curl >/dev/null || (fail "curl command is not available." && exit 1)
for cmd in curl php; do
command -v ${cmd} >/dev/null || { fail "Command ${cmd} is not available"; exit 1; };
done

[ -z "${DREVOPS_NOTIFY_JIRA_USER}" ] && fail "Missing required value for DREVOPS_NOTIFY_JIRA_USER" && exit 1
[ -z "${DREVOPS_NOTIFY_JIRA_TOKEN}" ] && fail "Missing required value for DREVOPS_NOTIFY_JIRA_TOKEN" && exit 1
[ -z "${DREVOPS_NOTIFY_BRANCH}" ] && fail "Missing required value for DREVOPS_NOTIFY_BRANCH" && exit 1
Expand Down
2 changes: 1 addition & 1 deletion scripts/drevops/notify-newrelic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v curl >/dev/null || (fail "curl command is not available." && exit 1)
command -v curl >/dev/null || (fail "Command curl is not available." && exit 1)
[ -z "${DREVOPS_NOTIFY_NEWRELIC_PROJECT}" ] && fail "Missing required value for DREVOPS_NOTIFY_NEWRELIC_PROJECT" && exit 1
[ -z "${DREVOPS_NOTIFY_NEWRELIC_APIKEY}" ] && fail "Missing required value for DREVOPS_NOTIFY_NEWRELIC_APIKEY" && exit 1
[ -z "${DREVOPS_NOTIFY_NEWRELIC_REF}" ] && fail "Missing required value for DREVOPS_NOTIFY_NEWRELIC_REF" && exit 1
Expand Down
2 changes: 2 additions & 0 deletions scripts/drevops/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

command -v git >/dev/null || (fail "Command git is not available." && exit 1)

is_hard_reset="$([ "${1:-}" == "hard" ] && echo "1" || echo "0")"

info "Started reset."
Expand Down
4 changes: 4 additions & 0 deletions scripts/drevops/setup-ssh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

for cmd in ssh-keygen ssh-add; do
command -v ${cmd} >/dev/null || { fail "Command ${cmd} is not available"; exit 1; };
done

info "Started SSH setup."

fingerprint_var="DREVOPS_${DREVOPS_SSH_PREFIX}_SSH_FINGERPRINT"
Expand Down
2 changes: 1 addition & 1 deletion scripts/drevops/task-copy-db-acquia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extract_json_value() {
}

# Pre-flight checks.
command -v curl >/dev/null || (fail "curl command is not available." && exit 1)
command -v curl >/dev/null || (fail "Command curl is not available." && exit 1)

# Check that all required variables are present.
[ -z "${DREVOPS_ACQUIA_KEY}" ] && fail "Missing value for DREVOPS_ACQUIA_KEY." && exit 1
Expand Down
8 changes: 5 additions & 3 deletions scripts/drevops/task-copy-files-acquia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

# Pre-flight checks.
for cmd in php curl; do
command -v ${cmd} >/dev/null || { fail "Command ${cmd} is not available"; exit 1; };
done

info "Started database copying between environments in Acquia."

#
Expand All @@ -67,9 +72,6 @@ extract_json_value() {
php -r "\$data=json_decode(file_get_contents('php://stdin'), TRUE); isset(\$data[\"${key}\"]) ? print trim(json_encode(\$data[\"${key}\"], JSON_UNESCAPED_SLASHES), '\"') : exit(1);"
}

# Pre-flight checks.
command -v curl >/dev/null || (fail "curl command is not available." && exit 1)

# Check that all required variables are present.
[ -z "${DREVOPS_ACQUIA_KEY}" ] && fail "Missing value for DREVOPS_ACQUIA_KEY." && exit 1
[ -z "${DREVOPS_ACQUIA_SECRET}" ] && fail "Missing value for DREVOPS_ACQUIA_SECRET." && exit 1
Expand Down
1 change: 1 addition & 0 deletions scripts/drevops/task-custom-lagoon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ if ! command -v lagoon >/dev/null || [ -n "${DREVOPS_LAGOONCLI_FORCE_INSTALL}" ]
chmod +x "${DREVOPS_LAGOONCLI_PATH}/lagoon"
export PATH="${PATH}:${DREVOPS_LAGOONCLI_PATH}"
fi
command -v lagoon >/dev/null || (fail "Command lagoon is not available." && exit 1)

note "Configuring Lagoon instance."
#shellcheck disable=SC2218
Expand Down
8 changes: 5 additions & 3 deletions scripts/drevops/task-purge-cache-acquia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

# Pre-flight checks.
for cmd in php curl; do
command -v ${cmd} >/dev/null || { fail "Command ${cmd} is not available"; exit 1; };
done

info "Started cache purging in Acquia."

#
Expand All @@ -67,9 +72,6 @@ extract_json_value() {
php -r "\$data=json_decode(file_get_contents('php://stdin'), TRUE); isset(\$data[\"${key}\"]) ? print trim(json_encode(\$data[\"${key}\"], JSON_UNESCAPED_SLASHES), '\"') : exit(1);"
}

# Pre-flight checks.
command -v curl >/dev/null || (fail "curl command is not available." && exit 1)

# Check that all required variables are present.
[ -z "${DREVOPS_ACQUIA_KEY}" ] && fail "Missing value for DREVOPS_ACQUIA_KEY." && exit 1
[ -z "${DREVOPS_ACQUIA_SECRET}" ] && fail "Missing value for DREVOPS_ACQUIA_SECRET." && exit 1
Expand Down
4 changes: 4 additions & 0 deletions scripts/drevops/update-scaffold.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ DREVOPS_INSTALLER_URL="${DREVOPS_INSTALLER_URL:-https://install.drevops.com}"
export DREVOPS_INSTALLER_URL
export DREVOPS_INSTALL_COMMIT

for cmd in php curl; do
command -v ${cmd} >/dev/null || { fail "Command ${cmd} is not available"; exit 1; };
done

curl -L "${DREVOPS_INSTALLER_URL}"?"$(date +%s)" >/tmp/install
php /tmp/install --quiet
rm /tmp/install >/dev/null

1 comment on commit 404e9ba

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.