diff -ru gosc-scripts/imc-shell/imgcust-scripts/ConfigFile.sh gosc-scripts-from-RPM/imc-shell/imgcust-scripts/ConfigFile.sh --- gosc-scripts/imc-shell/imgcust-scripts/ConfigFile.sh 2015-06-17 23:21:44.000000000 +0000 +++ gosc-scripts-from-RPM/imc-shell/imgcust-scripts/ConfigFile.sh 2015-08-13 22:56:47.000000000 +0000 @@ -103,6 +103,8 @@ local lineLength= local key= local val= +# local bulkcontent=0 + cloud_config_blob="content: |" ConfigFile_Clear @@ -146,8 +148,11 @@ # key value pair (non-eager '=' for base64) elif [[ $line =~ ([^=]+)=(.*) ]]; then key="${BASH_REMATCH[1]}" - val="${BASH_REMATCH[2]}" + val="${BASH_REMATCH[2]}" + echo "$category" + echo "$key" + # cleaning up on all "input" paths key=$(Trim "$key") val=$(Trim "$val") @@ -169,6 +174,44 @@ done <<<"$content" } +# Parses extra config file to parse the bulk blob content. +# Args: +# content: string:Name of file containing blob data +# Results: +# String: Content of Blob content config file +# Throws: +# None +ConfigFile_GetBlobContent() +{ + local content="$1" + local line= + local cloud_config_blob="content: |" + + while read line + do + # remove end char \n (chomp) + line="${line%\\n}" + + # spaces at the end are not allowed, things like passwords must be at least base64-encoded + line=$(Trim "$line") + + if [[ -z "$line" ]]; then + # Debug "Empty line. Ignored." + continue + fi + + if [[ $line == '#'* ]]; then + #Debug "Comment found. Line ignored." + continue + fi + + cloud_config_blob="$cloud_config_blob + $line" + + done <<<"$content" + echo "$cloud_config_blob" +} + # Parses properties from a .cfg file. # # Any previously available properties will be removed. @@ -184,14 +227,28 @@ ConfigFile_LoadConfigFile() { local filename=$1 - - Info "Opening file name $filename." - + Info "Opening file name $filename" local content=$(<$filename) + ConfigFile_LoadConfigContent "$content" +} - ConfigFile_LoadConfigContent "$content" +# Open and parses content from Blob file content. +# +# Args: +# filename: string: full path to a .cfg file +# Results: +# Bulk Config File Content. +# Throws: +# None +ConfigFile_WriteFileContent() +{ + local filename=$1 + local content=$(<$filename) + local result=$(ConfigFile_GetBlobContent "$content") + echo "$result" } + # Determines whether a property with a given key exists. # # Args: @@ -493,6 +550,200 @@ echo "$val" } +# Retrieves Lightwave DNS1 IP. +# +# Args: +# None +# Results: +# string: DNS1 IP or empty string in case it's missing or empty +# Throws: +# None +ConfigFile_GetLWDNS1() +{ + echo "$(ConfigFile_GetOptionalString 'LIGHTWAVE|DNS1')" +} + +# Retrieves Lightwave DNS2 IP. +# +# Args: +# None +# Results: +# string: DNS2 IP or empty string in case it's missing or empty +# Throws: +# None +ConfigFile_GetLWDNS2() +{ + echo "$(ConfigFile_GetOptionalString 'LIGHTWAVE|DNS2')" +} + +# Retrieves Lightwave DNS3 IP. +# +# Args: +# None +# Results: +# string: DNS3 IP or empty string in case it's missing or empty +# Throws: +# None +ConfigFile_GetLWDNS3() +{ + echo "$(ConfigFile_GetOptionalString 'LIGHTWAVE|DNS3')" +} + +# Retrieves Lightwave Domain. +# +# Args: +# None +# Results: +# string: Lightwave Domain or empty string in case it's missing or empty +# Throws: +# None +ConfigFile_GetLWDomain() +{ + echo "$(ConfigFile_GetOptionalString 'LIGHTWAVE|DOMAIN')" +} + +# Retrieves Lightwave SITE. +# +# Args: +# None +# Results: +# string: SITE or empty string in case it's missing or empty +# Throws: +# None +ConfigFile_GetLWSite() +{ + echo "$(ConfigFile_GetOptionalString 'LIGHTWAVE|SITE')" +} + +# Retrieves Lightwave OP. +# +# Args: +# None +# Results: +# string: OP or empty string in case it's missing or empty +# Throws: +# None +ConfigFile_GetLWOP() +{ + echo "$(ConfigFile_GetOptionalString 'LIGHTWAVE|OP')" +} + +# Retrieves Lightware domain password. +# +# Args: +# None +# Results: +# string: Lightwave domain password or empty if its missing or empty +# Throws: +# None +ConfigFile_GetLWDomainPwd() +{ + echo "$(ConfigFile_GetOptionalString 'LIGHTWAVE|-PASS')" +} + +# Retrieves Lightware domain username. +# +# Args: +# None +# Results: +# string: Lightwave domain username or empty if its missing or empty +# Throws: +# None +ConfigFile_GetLWDomainUserName() +{ + echo "$(ConfigFile_GetOptionalString 'LIGHTWAVE|USERNAME')" +} + +# Retrieves Service-N file Name. +# +# Args: +# SERVICE-N File Name +# Results: +# string: Number of commands to be run for this particular service +# Throws: +# None +ConfigFile_GetServiceFileCommandCount() +{ + local service_file=$1 + local query="${service_file}|COMMANDCNT" + echo "$(ConfigFile_GetOptionalString $query)" +} + +# Retrieves Service-N - command N to be executed +# +# Args: +# SERVICE-N File Name +# Command number +# Results: +# string: Command to be run. +# Throws: +# None +ConfigFile_GetServiceFileCommand() +{ + local service_file=$1 + local cmdNo=$2 + local query="${service_file}|${cmdNo}" + echo "$(ConfigFile_GetOptionalString $query)" +} + +# Retrieves Service-N file path +# +# Args: +# SERVICE-N File Name +# +# Results: +# string: Service file path +# Throws: +# None +ConfigFile_GetServiceFilePath() +{ + local service_file=$1 + local query="${service_file}|PATH" + echo "$(ConfigFile_GetOptionalString $query)" +} + + +# Retrieves Number of custom service. +# +# Args: +# None +# Results: +# integer: count +# Throws: +# Dies in case setting is not present. +ConfigFile_GetServiceCount() +{ + local val='' # has to be declared before assigned +# Info "Seee Count" + val=$(ConfigFile_GetOptionalNonEmptyString "CLOUD-INIT-BLOB|SERVICES") || exit 1 + + local myresult=0 + + if [[ -n "$val" ]]; then + local spl=(${val//,/ }) + myresult="${#spl[@]}" + fi +# Info "service Count " + echo "$myresult" +} + +# Retrieves Service File Name. +# +# Args: +# None +# Results: +# string: service file name +# Throws: +# Dies in case setting is not present. +ConfigFile_GetServiceFileName() +{ + local service_file=$1 + # echo "$service_file" + local query="${service_file}|NAME" + echo "$(ConfigFile_GetOptionalString $query)" + +} + # Retrieves whether to set time to UTC or Local. # # Args: @@ -1035,3 +1286,4 @@ echo "$primary" } + diff -ru gosc-scripts/imc-shell/imgcust-scripts/CustomizationUtils.sh gosc-scripts-from-RPM/imc-shell/imgcust-scripts/CustomizationUtils.sh --- gosc-scripts/imc-shell/imgcust-scripts/CustomizationUtils.sh 2015-06-17 23:21:58.000000000 +0000 +++ gosc-scripts-from-RPM/imc-shell/imgcust-scripts/CustomizationUtils.sh 2015-08-14 02:19:13.099688800 +0000 @@ -385,7 +385,7 @@ local oldFQDN=$(GetResolverFqdn) local res='' Info "CHF" - echo $pldHostname + echo $oldHostname echo $oldFQDN CustomizeHostsFileContent "" "$oldHostname" "$oldFQDN" "res" @@ -670,6 +670,113 @@ Info "InstallCustomScript has completed" } + +# Execute Photon vm to join lightwave configuration if provided credential in input. +# +# Args: +# None +# Results: +# None +# Throws: +# None +LightWaveDomainJoin() +{ + + local result="DNS=" + local lw_dns1=$(ConfigFile_GetLWDNS1) + local lw_dns2=$(ConfigFile_GetLWDNS2) + local lw_dns3=$(ConfigFile_GetLWDNS3) + local query_string='' + + Debug "DNS1 $lw_dns1" + Debug "DNS2 $lw_dns2" + Debug "DNS3 $lw_dns3" + query_string="$lw_dns1 $lw_dns2 $lw_dns3" + Debug "DNS to be set : $query_string" + + if [[ -n "$query_string" ]]; then + result=$result$query_string + sed -i "s/#DNS/DNS/g" /etc/systemd/resolved.conf + sed -i "1,/DNS=/s/DNS=/$result/" /etc/systemd/resolved.conf + fi + + local domain_name=$(ConfigFile_GetLWDomain) + local user_name=$(ConfigFile_GetLWDomainUserName) + local password=$(ConfigFile_GetLWDomainPwd) + + # default username is administrator, we will overwrite it if other username is specified + + if [[ -z "$user_name" ]]; then + user_name='administrator' + fi + + # optional params + local op=$(ConfigFile_GetLWOP) + if [[ -n "$op" ]]; then + op="--op $op" + fi + + local site=$(ConfigFile_GetLWSite) + if [[ -n "$site" ]]; then + site="--site $site" + fi + Debug "LIGHTWAVE domain_name $domain_name username : $user_name pwd $password" + local optional="$op $site" + + local execute="/opt/vmware/bin/domainjoin join $domain_name --username $user_name --password $password" + + if [[ -n "$domain_name" ]] && [[ -n "$password" ]]; then + if [[ -n "$optional" ]]; then + execute="$execute $optional" + fi + Debug "Going to execute $execute" + $execute + Debug "Light wave domain join procedure completed" + else + Debug "ERROR :: Either Domain Name or Password Missing: Cannot Join Lighwave domain" + fi + +} + + +# Execute all blob service file commands if present in the configuration file. +# +# Args: +# None +# Results: +# None +# Throws: +# Nothing +# +ExecuteAllBlobServiceFileCommands() +{ + local val='' + val=$(ConfigFile_GetOptionalNonEmptyString "CLOUD-INIT-BLOB|SERVICES") + + if [ -z "$val" ]; then + Info "No Blob Service file present:: Nothing to do" + else + Info "Service file found. executing Commands......." + local ser_cnt=$(ConfigFile_GetServiceCount) + for i in $(seq 1 $ser_cnt); do + local service_tag="SERVICE" + local command_tag="COMMAND" + local ser_query=$service_tag$i + local cmd_cnt=$(ConfigFile_GetServiceFileCommandCount $ser_query) + if [ "$cmd_cnt" -gt 0 ]; then + for j in $(seq 1 $ser_cnt); do + + local cmd_query=$command_tag$j + local commd=$(ConfigFile_GetServiceFileCommand $ser_query $cmd_query) + Exec '$commd' + done + fi + done + fi +} + + + # Generates cloud-init configuration files which represents customization. # # Args: @@ -697,30 +804,6 @@ EOF ) - local scriptName=$(ConfigFile_GetCustomScriptName) - - if [[ -n "$scriptName" ]]; then - export formatResult=$formatResult$(${CAT} < /etc/shadow fi + # Execute all commands present in blob service file + ExecuteAllBlobServiceFileCommands + + # Call lightwave domain join + LightWaveDomainJoin + machineId=$(GetBiosUuid "") }