Commit d404a106 authored by Pascal Déchamboux's avatar Pascal Déchamboux
Browse files

Correct bash scripting pb #2

parent baec3519
Loading
Loading
Loading
Loading
+23 −25
Original line number Diff line number Diff line
@@ -671,7 +671,7 @@ stages:

    # delete app
    tobesearched="/^${appname}\$/p"
    sfound=`cf apps | sed -e 1,3d | cut -d " " -f 1 | sed -ne ${tobesearched}`
    sfound=$(cf apps | sed -e 1,3d | cut -d " " -f 1 | sed -ne "${tobesearched}")
    if [[ -z "$sfound" ]]; then
      log_info "--- nothing to delete"
    else
@@ -759,7 +759,7 @@ stages:
  function get_desc_field() {
    local field_value
    local notnull
    field_value=$(cat "$1" | jq ."${2}")
    field_value=$(jq ".${2}" <"${1}")
    notnull=$3
    export desc_field
    export desc_field_error
@@ -767,7 +767,7 @@ stages:
    if [[ "${field_value}" == "null" ]]; then
      if [[ "${notnull}" == "true" ]]; then
   	    desc_field_error="${2} should not be null: creation aborted"
      if [[ ! -z "$desc_field_error" ]]; then
        if [[ -n "$desc_field_error" ]]; then
          log_info "${smsg}${COLOR_RED}KO - skipped${COLOR_NONE} (${COLOR_BLUE}${desc_field_error}${COLOR_NONE})"
          manage_services_errors=$((manage_services_errors+1))
          return
@@ -816,38 +816,36 @@ stages:
    smsg="Create service instance ${COLOR_YELLOW}${service_desc}${COLOR_NONE}: "
    for fi in "${!fields[@]}"
    do
      get_desc_field $service_desc "${fields[$fi]}" "${mandatory[$fi]}"
      fvalues[$fi]=$(echo ${desc_field} | tr -d '\r' | envsubst)
      get_desc_field "${service_desc}" "${fields[$fi]}" "${mandatory[$fi]}"
      fvalues[$fi]=$(echo "${desc_field}" | tr -d '\r' | envsubst)
      log_info "--- ${fields[$fi]}: ${COLOR_YELLOW}${fvalues[$fi]}${COLOR_NONE}"
    done
    log_info "${smsg}service definition OK - proceed"
    tobesearched="/^${fvalues[0]}\$/p"
    sfound=`cf services | sed -e 1,3d | cut -d " " -f 1 | sed -ne ${tobesearched}`
    sfound=$(cf services | sed -e 1,3d | cut -d " " -f 1 | sed -ne "${tobesearched}")
    if [[ -z "${sfound}" ]]; then
      is_cups "${fvalues[1]}" "${fvalues[2]}"
      argfile=`mktemp`
      argfile=$(mktemp)
      if [[ "$res_is_cups" = "CUPS" ]]; then
        narg="-p"
      else
        narg="-c"
      fi
      if [[ -z "${fvalues[4]}" ]]; then
        params=""
        narg=
      else
        echo "${fvalues[4]}" >"${argfile}"
        params="${narg}${argfile}"
      fi
      if [[ "$res_is_cups" = "CUPS" ]]; then
        cf cups ${fvalues[0]} ${params} >/dev/null
        cf cups "${fvalues[0]}" "${narg}" "${argfile}" >/dev/null
      else
        if [[ -z "${fvalues[3]}" ]]; then
          broker=""
          cf create-service "${fvalues[1]}" "${fvalues[2]}" "${fvalues[0]}" "${narg}" "${argfile}" -w >/dev/null
        else
          broker="-b ${fvalues[3]}"
          cf create-service "${fvalues[1]}" "${fvalues[2]}" "${fvalues[0]}" "-b ${fvalues[3]}" "${narg}" "${argfile}" -w >/dev/null
        fi
        cf create-service ${fvalues[1]} ${fvalues[2]} ${fvalues[0]} ${broker} ${params} -w >/dev/null
      fi
      rm -f ${argfile}
      rm -f "${argfile}"
      log_info "${COLOR_GREEN}... created${COLOR_NONE}"
    else
      log_info "${COLOR_BLUE}... service instance \"${fvalues[0]}\" already exist - skipped${COLOR_NONE}"
@@ -862,21 +860,21 @@ stages:
      ;;
    *)
      smsg="Delete service instance ${COLOR_YELLOW}${service_desc}${COLOR_NONE}: "
      get_desc_field $service_desc "cfServiceName" "true"
      if [[ ! -z "${desc_field_error}" ]]; then
      get_desc_field "${service_desc}" "cfServiceName" "true"
      if [[ -n "${desc_field_error}" ]]; then
        log_info "${smsg}${COLOR_RED}KO - skipped${COLOR_NONE} (${COLOR_BLUE}${desc_field_error}${COLOR_NONE})"
        manage_services_errors=$((manage_services_errors+1))
        return
      fi
      name=$(echo ${desc_field} | tr -d '\r')
      name=$(echo "${desc_field}" | tr -d '\r')
      log_info "${smsg}service definition OK - proceed"
      log_info "--- cfServiceName: ${COLOR_YELLOW}${name}${COLOR_NONE}"
      tobesearched="/^${name}\$/p"
      sfound=`cf services | sed -e 1,3d | cut -d " " -f 1 | sed -ne ${tobesearched}`
      sfound=$(cf services | sed -e 1,3d | cut -d " " -f 1 | sed -ne "${tobesearched}")
      if [[ -z "${sfound}" ]]; then
        log_info "${COLOR_BLUE}.... service instance \"${name}\" does not exist - skipped${COLOR_NONE}"
      else
        cf delete-service ${name} -f >/dev/null
        cf delete-service "${name}" -f >/dev/null
        log_info "${COLOR_GREEN}.... deleted${COLOR_NONE}"
      fi
      ;;