11#! /bin/bash
22
3- . /etc/parallelcluster/cfnconfig
3+ cfnconfig_file=" /etc/parallelcluster/cfnconfig"
4+ . ${cfnconfig_file}
5+
6+ # Check expected variables from cfnconfig file
7+ function check_params () {
8+ if [ -z " ${cfn_region} " ] || [ -z " ${cfn_preinstall} " ] || [ -z " ${cfn_preinstall_args} " ] || [ -z " ${cfn_postinstall} " ] || [ -z " ${cfn_postinstall_args} " ]; then
9+ error_exit " One or more required variables from ${cfnconfig_file} file are undefined"
10+ fi
11+ }
412
513# Error exit function
614function error_exit () {
715 script=` basename $0 `
8- echo " parallelcluster: $script - $1 "
9- logger -t parallelcluster " $script - $1 "
16+ echo " parallelcluster: ${ script} - $1 "
17+ logger -t parallelcluster " ${ script} - $1 "
1018 exit 1
1119}
1220
@@ -17,50 +25,48 @@ function download_run (){
1725 tmpfile=$( mktemp)
1826 trap " /bin/rm -f $tmpfile " RETURN
1927 if [ " ${scheme} " == " s3" ]; then
20- < %= node[' cluster' ][' cookbook_virtualenv_path' ] %> /bin/aws --region ${region } s3 cp ${url} - > $tmpfile || return 1
28+ < %= node[' cluster' ][' cookbook_virtualenv_path' ] %> /bin/aws --region ${cfn_region } s3 cp ${url} - > $tmpfile || return 1
2129 else
2230 wget -qO- ${url} > $tmpfile || return 1
2331 fi
2432 chmod +x $tmpfile || return 1
25- $tmpfile " $@ " || error_exit " Failed to run $ACTION , $file failed with non 0 return code: $? "
33+ $tmpfile " $@ " || error_exit " Failed to run ${ ACTION} , ${ file} failed with non 0 return code: $? "
2634}
2735
2836function run_preinstall () {
29- if [ " ${preinstall } " != " NONE" ]; then
30- file=" ${preinstall } "
31- if [ " ${preinstall_args } " != " NONE" ]; then
32- download_run ${preinstall } " ${preinstall_args [@]} "
37+ if [ " ${cfn_preinstall } " != " NONE" ]; then
38+ file=" ${cfn_preinstall } "
39+ if [ " ${cfn_preinstall_args } " != " NONE" ]; then
40+ download_run ${cfn_preinstall } " ${cfn_preinstall_args [@]} "
3341 else
34- download_run ${preinstall }
42+ download_run ${cfn_preinstall }
3543 fi
3644 fi || error_exit " Failed to run preinstall"
3745}
3846
3947function run_postinstall () {
4048 RC=0
41- if [ " ${postinstall } " != " NONE" ]; then
42- file=" ${postinstall } "
43- if [ " ${postinstall_args } " != " NONE" ]; then
44- download_run ${postinstall } " ${postinstall_args [@]} "
49+ if [ " ${cfn_postinstall } " != " NONE" ]; then
50+ file=" ${cfn_postinstall } "
51+ if [ " ${cfn_postinstall_args } " != " NONE" ]; then
52+ download_run ${cfn_postinstall } " ${cfn_postinstall_args [@]} "
4553 else
46- download_run ${postinstall }
54+ download_run ${cfn_postinstall }
4755 fi
4856 fi || error_exit " Failed to run postinstall"
4957}
5058
51- ACTION= ${1 # ?}
59+ check_params
5260
53- case $ACTION in
61+ ACTION=${1# ?}
62+ case ${ACTION} in
5463 preinstall)
5564 run_preinstall
5665 ;;
57-
5866 postinstall)
5967 run_postinstall
6068 ;;
61-
6269 * )
6370 echo " Unknown action. Exit gracefully"
6471 exit 0
65-
6672esac
0 commit comments