<commit_before>#!/bin/bash
# @description This file is for common helper functions that
# get called in other provisioners

export DEFAULT_TEXT="\033[39m"
export BOLD="\033[1m"
export UNBOLD="\033[21m"
export DIM="\033[2m"
export UNDIM="\033[21m"
export UNDERLINE="\033[4m"
export NOUNDERLINNE="\033[24m"
export YELLOW="\033[0;38;5;3m"
export YELLOW_UNDERLINE="\033[4;38;5;3m"
export GREEN="\033[0;38;5;2m"
export RED="\033[0;38;5;9m"
export BLUE="\033[0;38;5;4m" # 33m"
export PURPLE="\033[0;38;5;5m" # 129m"
export CRESET="\033[0m"


VVV_CONFIG=/vagrant/vvv-custom.yml
if [[ -f /vagrant/config.yml ]]; then
	VVV_CONFIG=/vagrant/config.yml
fi

export VVV_CONFIG
export VVV_CURRENT_LOG_FILE=""

# @description Does a bash array contain a value?
#
# @arg $1 string The value to search for
# @arg $2 string The list/array to search in
#
# @exitcode 0 If the list contains the element
# @exitcode 1 If the list does not containn the element
function containsElement () {
  declare -a array=(${2})
  local i
  for i in "${array[@]}"
  do
      if [ "${i}" == "${1}" ] ; then
          return 0
      fi
  done
  return 1
}
export -f containsElement

# @description Test that we have network connectivity with a URL.
# Deprecated, use check_network_connection_to_host instead
#
# @arg $1 string The address to test
# @see check_network_connection_to_host
function network_detection() {
  local url=${1:-"https://ppa.launchpad.net"}
  check_network_connection_to_host "${url}"
}
export -f network_detection

# @description Test that we have network connectivity with a URL.
#
# @arg $1 string The address to test, defaults to `https://ppa.launchpad.net`
#
# @exitcode 0 If the address is reachable
# @exitcode 1 If network issues are found
function check_network_connection_to_host() {
  local url=${1:-"https://ppa.launchpad.net"}
  vvv_info " * Testing network connection to <url>${url}</url>"

  # Network Detection
  #
  # If 3 attempts with a timeout of 5 seconds are not successful,
  # then we'll skip a few things further in provisioning rather
  # than create a bunch of errors.
  if [[ "$(wget --tries=3 --timeout=10 "${url}" -O /dev/null 2>&1 | grep 'connected')" ]]; then
    vvv_success " * Successful Network connection to <url>${url}</url><success> detected"
    return 0
  fi
  vvv_error " ! Network connection issues found. Unable to reach <url>${url}</url>"
  return 1
}
export -f check_network_connection_to_host

# @description Tests network connectivity with several hosts needed for provisioning
# @noargs
# @see check_network_connection_to_host
function network_check() {
  # Make an HTTP request to ppa.launchpad.net to determine if
  # outside access is available to us. Also check the mariadb
  declare -a hosts_to_test=(
    "https://ppa.launchpad.net"
    "https://wordpress.org"
    "https://github.com"
    "https://raw.githubusercontent.com"
    "https://getcomposer.org"
    "http://ams2.mirrors.digitalocean.com"
  )
  declare -a failed_hosts=()<commit_msg>only private ppas get https so switch back to http for launchpad<commit_after>#!/bin/bash
# @description This file is for common helper functions that
# get called in other provisioners

export DEFAULT_TEXT="\033[39m"
export BOLD="\033[1m"
export UNBOLD="\033[21m"
export DIM="\033[2m"
export UNDIM="\033[21m"
export UNDERLINE="\033[4m"
export NOUNDERLINNE="\033[24m"
export YELLOW="\033[0;38;5;3m"
export YELLOW_UNDERLINE="\033[4;38;5;3m"
export GREEN="\033[0;38;5;2m"
export RED="\033[0;38;5;9m"
export BLUE="\033[0;38;5;4m" # 33m"
export PURPLE="\033[0;38;5;5m" # 129m"
export CRESET="\033[0m"


VVV_CONFIG=/vagrant/vvv-custom.yml
if [[ -f /vagrant/config.yml ]]; then
	VVV_CONFIG=/vagrant/config.yml
fi

export VVV_CONFIG
export VVV_CURRENT_LOG_FILE=""

# @description Does a bash array contain a value?
#
# @arg $1 string The value to search for
# @arg $2 string The list/array to search in
#
# @exitcode 0 If the list contains the element
# @exitcode 1 If the list does not containn the element
function containsElement () {
  declare -a array=(${2})
  local i
  for i in "${array[@]}"
  do
      if [ "${i}" == "${1}" ] ; then
          return 0
      fi
  done
  return 1
}
export -f containsElement

# @description Test that we have network connectivity with a URL.
# Deprecated, use check_network_connection_to_host instead
#
# @arg $1 string The address to test
# @see check_network_connection_to_host
function network_detection() {
  local url=${1:-"https://ppa.launchpad.net"}
  check_network_connection_to_host "${url}"
}
export -f network_detection

# @description Test that we have network connectivity with a URL.
#
# @arg $1 string The address to test, defaults to `https://ppa.launchpad.net`
#
# @exitcode 0 If the address is reachable
# @exitcode 1 If network issues are found
function check_network_connection_to_host() {
  local url=${1:-"https://ppa.launchpad.net"}
  vvv_info " * Testing network connection to <url>${url}</url>"

  # Network Detection
  #
  # If 3 attempts with a timeout of 5 seconds are not successful,
  # then we'll skip a few things further in provisioning rather
  # than create a bunch of errors.
  if [[ "$(wget --tries=3 --timeout=10 "${url}" -O /dev/null 2>&1 | grep 'connected')" ]]; then
    vvv_success " * Successful Network connection to <url>${url}</url><success> detected"
    return 0
  fi
  vvv_error " ! Network connection issues found. Unable to reach <url>${url}</url>"
  return 1
}
export -f check_network_connection_to_host

# @description Tests network connectivity with several hosts needed for provisioning
# @noargs
# @see check_network_connection_to_host
function network_check() {
  # Make an HTTP request to ppa.launchpad.net to determine if
  # outside access is available to us. Also check the mariadb
  declare -a hosts_to_test=(
    "http://ppa.launchpad.net"
    "https://wordpress.org"
    "https://github.com"
    "https://raw.githubusercontent.com"
    "https://getcomposer.org"
    "http://ams2.mirrors.digitalocean.com"
  )
  declare -a failed_hosts=()
{'fraction_non_alphanumeric': 0.12662013958125623, 'fraction_numerical': 0.03755400465270854, 'mean_word_length': 4.279824561403509, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 15, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '902324', 'n_tokens_mistral': 2206, 'n_tokens_neox': 1975, 'n_words': 630}