1
1
#! /bin/bash
2
2
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
+ }
4
12
5
13
# Error exit function
6
14
function error_exit () {
7
15
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 "
10
18
exit 1
11
19
}
12
20
@@ -17,50 +25,48 @@ function download_run (){
17
25
tmpfile=$( mktemp)
18
26
trap " /bin/rm -f $tmpfile " RETURN
19
27
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
21
29
else
22
30
wget -qO- ${url} > $tmpfile || return 1
23
31
fi
24
32
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: $? "
26
34
}
27
35
28
36
function 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 [@]} "
33
41
else
34
- download_run ${preinstall }
42
+ download_run ${cfn_preinstall }
35
43
fi
36
44
fi || error_exit " Failed to run preinstall"
37
45
}
38
46
39
47
function run_postinstall () {
40
48
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 [@]} "
45
53
else
46
- download_run ${postinstall }
54
+ download_run ${cfn_postinstall }
47
55
fi
48
56
fi || error_exit " Failed to run postinstall"
49
57
}
50
58
51
- ACTION= ${1 # ?}
59
+ check_params
52
60
53
- case $ACTION in
61
+ ACTION=${1# ?}
62
+ case ${ACTION} in
54
63
preinstall)
55
64
run_preinstall
56
65
;;
57
-
58
66
postinstall)
59
67
run_postinstall
60
68
;;
61
-
62
69
* )
63
70
echo " Unknown action. Exit gracefully"
64
71
exit 0
65
-
66
72
esac
0 commit comments