Skip to content

Commit

Permalink
Merge pull request #300 from MsysTechnologiesllc/ashwini/Add_feature_…
Browse files Browse the repository at this point in the history
…package_url

Added feature for chef_package_url for linux and windows system
  • Loading branch information
Vasundhara Jagdale authored Jul 2, 2020
2 parents 350c7b4 + 8cfb9d7 commit 7b8a41d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
14 changes: 12 additions & 2 deletions ChefExtensionHandler/bin/chef-install.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function Install-ChefClient {
$completed = $false

while (-not $completed) {
echo "Downloading Chef Client ..."
echo "Checking Chef Client ..."
Try {
## Get chef_pkg by matching "chef client" string with $_.Name
$chef_pkg = Get-ChefPackage
Expand All @@ -63,6 +63,8 @@ function Install-ChefClient {
Chef-SetCustomEnvVariables $chef_licence_env $powershellVersion
Write-Host "Set CHEF_LICENSE Environment variable as" $env:CHEF_LICENSE
}
## Get msi url from config file.
$chef_package_url = Get-PublicSettings-From-Config-Json "chef_package_url" $powershellVersion
## Get locally downloaded msi path string from config file.
$chef_downloaded_package = Get-PublicSettings-From-Config-Json "chef_package_path" $powershellVersion
$daemon = Get-PublicSettings-From-Config-Json "daemon" $powershellVersion
Expand All @@ -72,7 +74,8 @@ function Install-ChefClient {
if (-Not $daemon) {
$daemon = "service"
}
if (-Not $chef_pkg -and -Not $chef_downloaded_package ) {
if (-Not $chef_pkg -and -Not $chef_downloaded_package -and -Not $chef_package_url) {
echo "Downloading Chef Client ..."
$chef_package_version = Get-PublicSettings-From-Config-Json "bootstrap_version" $powershellVersion
$chef_package_channel = Get-PublicSettings-From-Config-Json "bootstrap_channel" $powershellVersion

Expand All @@ -86,6 +89,13 @@ function Install-ChefClient {
iex (new-object net.webclient).downloadstring('https://omnitruck.chef.io/install.ps1');install -daemon $daemon -version $chef_package_version -channel $chef_package_channel
} elseif ( -Not $chef_pkg -and $chef_downloaded_package ) {
Install-ChefMsi $chef_downloaded_package $daemon
} elseif ( -Not $chef_pkg -and $chef_package_url ) {
# Saving .msi in TEMP folder with pattern accepted by `Invoke-WebRequest`
$chef_downloaded_package = "$env:TEMP\chef-client.msi"
echo "Downloading chef client package from $chef_package_url"
Invoke-WebRequest -Uri $chef_package_url -OutFile $chef_downloaded_package
echo "Installing chef client from path $chef_downloaded_package"
Install-ChefMsi $chef_downloaded_package $daemon
}
$completed = $true
}
Expand Down
18 changes: 17 additions & 1 deletion ChefExtensionHandler/bin/chef-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ chef_install_from_script(){
chef_channel=$(get_value_from_setting_file $config_file_name "bootstrap_channel" &)
echo "Reading downloaded chef-client path from settings file"
chef_downloaded_package=$(get_value_from_setting_file $config_file_name "chef_package_path" &)
echo "Reading chef package url from settings file"
chef_package_url=$(get_value_from_setting_file $config_file_name "chef_package_url" &)
echo "Call for Checking linux distributor"
platform=$(get_linux_distributor)
#check if chef-client is already installed
Expand All @@ -62,7 +64,7 @@ chef_install_from_script(){
elif [ "$platform" = "centos" -o "$platform" = "rhel" -o "$platform" = "linuxoracle" ]; then
yum list installed | grep -w "chef"
fi
if [ $? -ne 0 ] && [ -z "$chef_downloaded_package" ]; then
if [ $? -ne 0 ] && [ -z "$chef_downloaded_package" ] && [ -z "$chef_package_url" ]; then
curl_check $platform
curl -L -o /tmp/$platform-install.sh https://omnitruck.chef.io/install.sh
echo "Install.sh script downloaded at /tmp/$platform-install.sh"
Expand All @@ -86,6 +88,20 @@ chef_install_from_script(){
filename=`echo $chef_downloaded_package | sed -e 's/^.*\///'`
filetype=`echo $filename | sed -e 's/^.*\.//'`
install_file $filetype "$chef_downloaded_package"
elif [ $? -ne 0 ] && [ ! -z "$chef_package_url" ]; then
echo "Checking url $chef_package_url"
url_check="$(curl -Is $chef_package_url | head -1 | grep 404)"
if [ -z $(echo $url_check | xargs) ]; then
echo "Downloading chef client package from $chef_package_url"
filetype=`echo $chef_package_url | sed -e 's/^.*\.//'`
chef_downloaded_package="/tmp/chef-client.$filetype"
curl_check $platform
curl -L -o $chef_downloaded_package $chef_package_url
echo "Installing chef client from path $chef_downloaded_package"
install_file $filetype "$chef_downloaded_package"
else
echo "ERROR: 404 'Url $chef_package_url not found'"
fi
else
echo "Chef-client is already installed"
fi
Expand Down

0 comments on commit 7b8a41d

Please sign in to comment.