           if [ "#{options.version}" == "latest" ]; then
             version=`hdp-select versions | tail -1`
           elif [ "#{options.version}" == "current" ]; then
-            version=`hdp-select status #{options.version_name} | sed 's/.* \\(\\d*\\)/\\1/'`
+            version=`hdp-select status #{options.version_name} | sed 's/.* \\(.*\\)/\\1/'`
           else
             version='#{options.version}'
           fi
-          # If it doesn't exist, then we switch to the latest version
           if [ ! -d "/usr/hdp/$version" ]; then
-            version=`hdp-select versions | tail -1`
-            if [ ! -d "/usr/hdp/$version" ]; then
-              echo 'Failed to detect the latest HDP version'
-              exit 1
-            fi
+            echo 'Failed to detect the latest HDP version'
+            exit 1
           fi
           echo $version
           hdp-select set #{options.version_name} $version


module.exports = (ctx) ->
  # Options include
  # startup: [true] or false
  # link: [true]
  # write: array
  # version_name
  ctx.hdp_service = (options, callback) ->
    options = name: options if typeof options is 'string'
    wrap null, arguments, (options, callback) ->
      # options = name: options if typeof options is 'string'
      # options = [options] unless Array.isArray options
      changed = false
      # each options
      # .run (options, next) ->
      options.startup ?= false
      # options.link ?= true
      options.version_name ?= options.name
      return callback Error "Missing Option 'name'" unless options.name
      version=''

          for filename in #{Object.keys(options.etc_default).join(' ')}; do
            source="/etc/default/$filename"
            target="/usr/hdp/$version/etc/default/$filename"
            if [ ! -f $target ]; then
              if [ $source == "/etc/default/#{options.name}" ]; then continue; else exit 1; fi
            fi
