<commit_before>
<#
// install chef-client with /i switch
// Actions: (do what windows bootstrap template)
//    - install chef-client

#>

function Chef-GetScriptDirectory
{
  $Invocation = (Get-Variable MyInvocation -Scope 1).Value
  Split-Path $Invocation.MyCommand.Path
}

$scriptDir = Chef-GetScriptDirectory

function Install-AzureChefExtensionGem($chefExtensionRoot) {
  # Install the custom gem
  Write-Host("[$(Get-Date)] Installing Azure-Chef-Extension gem")
  gem install "$chefExtensionRoot\\gems\\*.gem" --no-ri --no-rdoc
  Write-Host("[$(Get-Date)] Installed Azure-Chef-Extension gem successfully")
}

function Chef-GetExtensionRoot {
  $chefExtensionRoot = [System.IO.Path]::GetFullPath("$scriptDir\\..")
  $chefExtensionRoot
}

function Get-ChefPackage {
  Get-WmiObject -Class Win32_Product | Where-Object { $_.Name.contains("Chef Client") }
}

function Get-PublicSettings-From-Config-Json($key) {
  Try
  {
    $azure_config_file = Get-Azure-Config-Path
    $json_contents = Get-Content $azure_config_file
    $normalized_json = normalize_json($json_contents)
    $value = ($normalized_json | ConvertFrom-Json | Select -expand runtimeSettings | Select -expand handlerSettings | Select -expand publicSettings).$key
    $value
  }
  Catch
  {
    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName
    echo "Failed to read file: $FailedItem. The error message was $ErrorMessage"
    throw "Error in Get-PublicSettings-From-Config-Json. Couldn't parse $azure_config_file"
  }
}

function normalize_json($json) {
  $json -Join " "
}

function Get-Azure-Config-Path {
  $chefExtensionRoot = Chef-GetExtensionRoot

  Try
  {
    # Reading chef_extension_root/HandlerEnvironment.json file
    $handler_file = "$chefExtensionRoot\\HandlerEnvironment.json"
    $config_folder = (((Get-Content $handler_file) | ConvertFrom-Json)[0] | Select -expand handlerEnvironment).configFolder

    # Get the last .settings file
    $config_file = (get-childitem $config_folder -recurse | where {$_.extension -eq ".settings"})[-1].Name

    "$config_folder\$config_file"
  }
  Catch
  {
    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName
    echo "Failed to read file: $FailedItem. The error message was $ErrorMessage"
    throw "Error in Get-Azure-Config-Path. Couldn't parse the HandlerEnvironment.json file"
  }
}

function Install-ChefClient {
  # Source the shared PS
  . $(Get-SharedHelper)
  $powershellVersion = Get-PowershellVersion

  $retries = 3
  $retrycount = 0
  $completed = $false

  while (-not $completed) {
    echo "Downloading Chef Client ..."
    Try {
      ## Get chef_pkg by matching "chef client" string with $_.Name
      $chef_pkg = Get-ChefPackage
      if (-Not $chef_pkg) {
        if ( $powershellVersion -ge 3 ) {
          $chef_package_version = Get-PublicSettings-From-Config-Json("bootstrap_version")
          $daemon = Get-PublicSettings-From-Config-Json("daemon")
        } else {
          echo "Powershell version is less than 3. Hence skipping reading the azure config file. Downloading the latest version of chef-client."
        }<commit_msg>Accepting daemon=none instead of auto<commit_after>
<#
// install chef-client with /i switch
// Actions: (do what windows bootstrap template)
//    - install chef-client

#>

function Chef-GetScriptDirectory
{
  $Invocation = (Get-Variable MyInvocation -Scope 1).Value
  Split-Path $Invocation.MyCommand.Path
}

$scriptDir = Chef-GetScriptDirectory

function Install-AzureChefExtensionGem($chefExtensionRoot) {
  # Install the custom gem
  Write-Host("[$(Get-Date)] Installing Azure-Chef-Extension gem")
  gem install "$chefExtensionRoot\\gems\\*.gem" --no-ri --no-rdoc
  Write-Host("[$(Get-Date)] Installed Azure-Chef-Extension gem successfully")
}

function Chef-GetExtensionRoot {
  $chefExtensionRoot = [System.IO.Path]::GetFullPath("$scriptDir\\..")
  $chefExtensionRoot
}

function Get-ChefPackage {
  Get-WmiObject -Class Win32_Product | Where-Object { $_.Name.contains("Chef Client") }
}

function Get-PublicSettings-From-Config-Json($key) {
  Try
  {
    $azure_config_file = Get-Azure-Config-Path
    $json_contents = Get-Content $azure_config_file
    $normalized_json = normalize_json($json_contents)
    $value = ($normalized_json | ConvertFrom-Json | Select -expand runtimeSettings | Select -expand handlerSettings | Select -expand publicSettings).$key
    $value
  }
  Catch
  {
    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName
    echo "Failed to read file: $FailedItem. The error message was $ErrorMessage"
    throw "Error in Get-PublicSettings-From-Config-Json. Couldn't parse $azure_config_file"
  }
}

function normalize_json($json) {
  $json -Join " "
}

function Get-Azure-Config-Path {
  $chefExtensionRoot = Chef-GetExtensionRoot

  Try
  {
    # Reading chef_extension_root/HandlerEnvironment.json file
    $handler_file = "$chefExtensionRoot\\HandlerEnvironment.json"
    $config_folder = (((Get-Content $handler_file) | ConvertFrom-Json)[0] | Select -expand handlerEnvironment).configFolder

    # Get the last .settings file
    $config_file = (get-childitem $config_folder -recurse | where {$_.extension -eq ".settings"})[-1].Name

    "$config_folder\$config_file"
  }
  Catch
  {
    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName
    echo "Failed to read file: $FailedItem. The error message was $ErrorMessage"
    throw "Error in Get-Azure-Config-Path. Couldn't parse the HandlerEnvironment.json file"
  }
}

function Install-ChefClient {
  # Source the shared PS
  . $(Get-SharedHelper)
  $powershellVersion = Get-PowershellVersion

  $retries = 3
  $retrycount = 0
  $completed = $false

  while (-not $completed) {
    echo "Downloading Chef Client ..."
    Try {
      ## Get chef_pkg by matching "chef client" string with $_.Name
      $chef_pkg = Get-ChefPackage
      if (-Not $chef_pkg) {
        if ( $powershellVersion -ge 3 ) {
          $chef_package_version = Get-PublicSettings-From-Config-Json("bootstrap_version")
          $daemon = Get-PublicSettings-From-Config-Json("daemon")

          if ( $daemon -eq "none" ) {
            $daemon = "auto"
          }
        } else {
          echo "Powershell version is less than 3. Hence skipping reading the azure config file. Downloading the latest version of chef-client."
        }
{'fraction_non_alphanumeric': 0.11704794735192729, 'fraction_numerical': 0.002820432466311501, 'mean_word_length': 3.572349570200573, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5096103', 'n_tokens_mistral': 2012, 'n_tokens_neox': 1943, 'n_words': 470}