<commit_before>#!/bin/sh

# returns script dir
get_script_dir(){
  SCRIPT=$(readlink -f "$0")
  script_dir=`dirname $SCRIPT`
  echo "${script_dir}"
}

chef_extension_root=$(get_script_dir)/../

# install azure chef extension gem
install_chef_extension_gem(){
 echo "[$(date)] Installing Azure Chef Extension gem"
 gem install "$1" --no-ri --no-rdoc

  if test $? -ne 0; then
    echo "[$(date)] Azure Chef Extension gem installation failed"
    exit 1
  else
    echo "[$(date)] Azure Chef Extension gem installation succeeded"
  fi
}

get_hostname (){
  echo "Getting the hostname of this machine..."

  host=`hostname -f 2>/dev/null`
  if [ "$host" = "" ]; then
    host=`hostname 2>/dev/null`
    if [ "$host" = "" ]; then
      host=$HOSTNAME
    fi
  fi

  if [ "$host" = "" ]; then
    echo "Unable to determine the hostname of your system!"
    echo
    echo "Please consult the documentation for your system. The files you need "
    echo "to modify to do this vary between Linux distribution and version."
    echo
    exit 1
  fi

  echo "Found hostname: ${host}"
}

curl_check(){
  echo "Checking for curl..."
  if command -v curl > /dev/null; then
    echo "Detected curl..."
  else
    echo "Installing curl..."
    if [ "$1" = "centos" ]; then
      yum install -d0 -e0 -y curl
    else
      apt-get install -q -y curl
    fi
  fi
}

curl_status(){
  if [ "$1" = "22" ]; then
    echo
    echo -n "Unable to download repo config from: "
    echo "${2}"
    echo
    echo "Please contact <EMAIL> and report this."
    [ -e $3 ] && rm $3
    exit 1
  elif [ "$1" = "35" ]; then
    echo
    echo "curl is unable to connect to packagecloud.io over TLS when running: "
    echo "curl ${2}"
    echo
    echo "This is usually due to one of two things:"
    echo
    echo " 1.) Missing CA root certificates (make sure the ca-certificates package is installed)"
    echo " 2.) An old version of libssl. Try upgrading libssl on your system to a more recent version"
    echo
    echo "Contact <EMAIL> with information about your system for help."
    [ -e $3 ] && rm $3
    exit 1
  elif [ "$1" -gt "0" ]; then
    echo
    echo "Unable to run: "
    echo "curl ${2}"
    echo
    echo "Double check your curl installation and try again."
    [ -e $3 ] && rm $3
    exit 1
  else
    echo "done."
  fi
}

get_config_settings_file() {
  config_files_path="$chef_extension_root/config/*.settings"
  config_file_name=`ls $config_files_path 2>/dev/null | sort -V | tail -1`

  echo $config_file_name
}

get_chef_version() {
  config_file_name=$(get_config_settings_file)
  if [ -z "$config_file_name" ]; then
    echo "No config file found !!"
  else
    if cat $config_file_name 2>/dev/null | grep -q "bootstrap_version"; then
      chef_version=`sed 's/.*bootstrap_version" *: *"\(.*\)/\1/' $config_file_name 2>/dev/null | awk -F\" '{ print $1 }'`
      echo $chef_version
    else
      echo ""
    fi
  fi
}

get_chef_package_from_omnitruck() {
  echo "Call for Checking linux distributor"
  platform=$(get_linux_distributor)

  #check if chef-client is already installed
  if [ "$platform" = "ubuntu" -o "$platform" = "debian" ]; then
    dpkg-query -s chef<commit_msg>Modified parsing code which reads bootstrap_version and handled various cases like parsing the contents having new lines.<commit_after>#!/bin/sh

# returns script dir
get_script_dir(){
  SCRIPT=$(readlink -f "$0")
  script_dir=`dirname $SCRIPT`
  echo "${script_dir}"
}

chef_extension_root=$(get_script_dir)/../

# install azure chef extension gem
install_chef_extension_gem(){
 echo "[$(date)] Installing Azure Chef Extension gem"
 gem install "$1" --no-ri --no-rdoc

  if test $? -ne 0; then
    echo "[$(date)] Azure Chef Extension gem installation failed"
    exit 1
  else
    echo "[$(date)] Azure Chef Extension gem installation succeeded"
  fi
}

get_hostname (){
  echo "Getting the hostname of this machine..."

  host=`hostname -f 2>/dev/null`
  if [ "$host" = "" ]; then
    host=`hostname 2>/dev/null`
    if [ "$host" = "" ]; then
      host=$HOSTNAME
    fi
  fi

  if [ "$host" = "" ]; then
    echo "Unable to determine the hostname of your system!"
    echo
    echo "Please consult the documentation for your system. The files you need "
    echo "to modify to do this vary between Linux distribution and version."
    echo
    exit 1
  fi

  echo "Found hostname: ${host}"
}

curl_check(){
  echo "Checking for curl..."
  if command -v curl > /dev/null; then
    echo "Detected curl..."
  else
    echo "Installing curl..."
    if [ "$1" = "centos" ]; then
      yum install -d0 -e0 -y curl
    else
      apt-get install -q -y curl
    fi
  fi
}

curl_status(){
  if [ "$1" = "22" ]; then
    echo
    echo -n "Unable to download repo config from: "
    echo "${2}"
    echo
    echo "Please contact <EMAIL> and report this."
    [ -e $3 ] && rm $3
    exit 1
  elif [ "$1" = "35" ]; then
    echo
    echo "curl is unable to connect to packagecloud.io over TLS when running: "
    echo "curl ${2}"
    echo
    echo "This is usually due to one of two things:"
    echo
    echo " 1.) Missing CA root certificates (make sure the ca-certificates package is installed)"
    echo " 2.) An old version of libssl. Try upgrading libssl on your system to a more recent version"
    echo
    echo "Contact <EMAIL> with information about your system for help."
    [ -e $3 ] && rm $3
    exit 1
  elif [ "$1" -gt "0" ]; then
    echo
    echo "Unable to run: "
    echo "curl ${2}"
    echo
    echo "Double check your curl installation and try again."
    [ -e $3 ] && rm $3
    exit 1
  else
    echo "done."
  fi
}

get_config_settings_file() {
  config_files_path="$chef_extension_root/config/*.settings"
  config_file_name=`ls $config_files_path 2>/dev/null | sort -V | tail -1`

  echo $config_file_name
}

get_chef_version() {
  config_file_name=$(get_config_settings_file)
  if [ -z "$config_file_name" ]; then
    echo "No config file found !!"
  else
    if cat $config_file_name 2>/dev/null | grep -q "bootstrap_version"; then
      chef_version=`sed ':a;N;$!ba;s/\n//g' $config_file_name | sed 's/.*bootstrap_version" *: *" *\(.*\)/\1/' 2>/dev/null | awk -F\" '{ print $1 }' | sed 's/[ \t]*$//'`
      echo $chef_version
    else
      echo ""
    fi
  fi
}

get_chef_package_from_omnitruck() {
  echo "Call for Checking linux distributor"
  platform=$(get_linux_distributor)

  #check if chef-client is already installed
  if [ "$platform" = "ubuntu" -o "$platform" = "debian" ]; then
    dpkg-query -s chef
{'fraction_non_alphanumeric': 0.12964669738863288, 'fraction_numerical': 0.011674347158218126, 'mean_word_length': 2.8120608899297426, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2479518', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2125, 'n_words': 764}