diff --git a/CHANGELOG.md b/CHANGELOG.md index a7785ac88..d39529da8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + +- Setting the host in a batch_connect batch script can now be directly + manipulated through the `set_host` initialization parameter. + [#42](https://github.com/OSC/ood_core/issues/42) + ## [0.0.5] - 2017-07-05 ### Added diff --git a/lib/ood_core/batch_connect/template.rb b/lib/ood_core/batch_connect/template.rb index a96109f22..f3fc60b7e 100644 --- a/lib/ood_core/batch_connect/template.rb +++ b/lib/ood_core/batch_connect/template.rb @@ -29,6 +29,9 @@ class Template # @option context [#to_s] :script_wrapper ("%s") Bash code that wraps # around the body of the template script (use `%s` to interpolate the # body) + # @option context [#to_s] :set_host ("host=$(hostname)") Bash code used + # to set the `host` environment variable used for connection + # information # @option context [#to_s] :before_script ("...") Bash code run before the # main script is forked off # @option context [#to_s] :before_file ("before.sh") Path to script that @@ -78,6 +81,11 @@ def conn_params (conn_params + [:host, :port, :password]).uniq end + # Bash script used to define the `host` environment variable + def set_host + context.fetch(:set_host, "host=$(hostname)").to_s + end + # Helper methods used in the bash scripts def bash_helpers context.fetch(:bash_helpers) do @@ -126,7 +134,7 @@ def before_script context.fetch(:before_script) do before_file = context.fetch(:before_file, "before.sh").to_s - "host=$(hostname)\n[[ -e \"#{before_file}\" ]] && source \"#{before_file}\"" + "[[ -e \"#{before_file}\" ]] && source \"#{before_file}\"" end.to_s end @@ -184,6 +192,9 @@ def base_script #{bash_helpers} + # Set host of current machine + #{set_host} + #{before_script} echo "Script starting..."