SPECS/open-vm-tools/gosc-post-custom.patch
f2ed558a
 diff -Naur gosc-scripts/imc-shell/imgcust-scripts/CustomizationUtils.sh gosc-scripts-modify/imc-shell/imgcust-scripts/CustomizationUtils.sh
 --- gosc-scripts/imc-shell/imgcust-scripts/CustomizationUtils.sh	2016-04-30 04:11:27.000000000 +0530
 +++ gosc-scripts-modify/imc-shell/imgcust-scripts/CustomizationUtils.sh	2018-07-04 20:13:30.443320383 +0530
 @@ -633,6 +633,55 @@
    Info "RunCustomScript has completed"
  }
  
 +# Runs post-customization script.
 +#
 +# Args:
 +#   scriptPath: string: relative path to the script
 +# Results:
 +#   None
 +# Throws:
 +#   Dies in case execution returns non-zero exit code.
 +RunPostCustomScript()
 +{
 +  local scriptPath=$1
 +  
 +  Info "RunPostCustomScript invoked"
 +  
 +  if [[ -e $scriptPath ]]; then
 +    # Strip any CR characters from the decoded script
 +    Exec "${CAT} $scriptPath | ${TR} -d '\r' > $scriptPath.tmp" '' ''
 +    Exec "${CHMOD} u+x $scriptPath.tmp" '' ''
 +    
 +    Info "Executing post-customization script..."
 +    
 +    ${SH} -c "$scriptPath.tmp postcustomization"
 +    local exitCode=$?
 +    if [[ $exitCode -ne 0 ]]; then
 +      Die "Execution of post-customization failed!"
 +    fi
 +  else
 +   Warn "Customization script '$scriptPath' does not exist"
 +  fi
 +  
 +  Info "RunPostCustomScript has completed" 
 +}
 +
 +# Sets Guest Customization status
 +#
 +# Args:
 +#   Status: String: Started / Successful / Failed
 +# Results:
 +#   None
 +# Throws:
 +#   None
 +PostGCStatus()
 +{
 +  local STATUS=$1
 +  local OUTPUT="$(ps -C vmtoolsd -o cmd=)"
 +  local CMD="$OUTPUT --cmd \"info-set guestinfo.gc.status $STATUS\""
 +  eval $CMD
 +}
 +
  # Installs post-customization script.
  #
  # Args:
 diff -Naur gosc-scripts/imc-shell/imgcust-scripts/PhotonCustomization.sh gosc-scripts-modify/imc-shell/imgcust-scripts/PhotonCustomization.sh
 --- gosc-scripts/imc-shell/imgcust-scripts/PhotonCustomization.sh	2016-04-30 02:40:39.000000000 +0530
 +++ gosc-scripts-modify/imc-shell/imgcust-scripts/PhotonCustomization.sh	2018-07-04 23:25:43.503012031 +0530
 @@ -20,7 +20,6 @@
      scriptName=`${DIRNAME} $configPath`"/$scriptName"
      Info "Handling customization script [$scriptName]"
      RunCustomScript $scriptName
 -    InstallCustomScript $scriptName
    else
      Info "No customization script to run"
    fi
 @@ -88,7 +87,27 @@
  
    Info "Photon customization started"
  
 +  #Set Guest Customization status as Started
 +  PostGCStatus "Started"
 +
    RunCloudConfig $configFilePath
  
    Info "Photon customization finished"
 +
 +  # Run Post customization script
 +
 +  local scriptName=$(ConfigFile_GetCustomScriptName)
 +
 +  if [[ -n "$scriptName" ]]; then
 +    scriptName=`${DIRNAME} $configFilePath`"/$scriptName"
 +    Info "Handling Post Customization script [$scriptName]"
 +    RunPostCustomScript $scriptName
 +  else
 +    Info "No post customization script to run"
 +  fi
 +  
 +  #Set Guest customization status as successful
 +  PostGCStatus "Successful"
 +
 +  Info "Photon Customization Successful. GC Status is updated"
  }
 diff -Naur gosc-scripts/imc-shell/imgcust-scripts/Utils.sh gosc-scripts-modify/imc-shell/imgcust-scripts/Utils.sh
 --- gosc-scripts/imc-shell/imgcust-scripts/Utils.sh	2016-04-30 02:40:39.000000000 +0530
 +++ gosc-scripts-modify/imc-shell/imgcust-scripts/Utils.sh	2018-07-04 19:32:43.255385812 +0530
 @@ -105,6 +105,8 @@
  {
    Error "$@"
    echo "DIE: $@" 1>&2
 +  # Set Guest customization status as failure
 +  PostGCStatus "Failed"
    exit 1
  }