1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#!/bin/bash
set -e
source charms.reactive.sh
ARCHITECTURE=`uname -m`
# Installation Manager install path
IM_INSTALL_PATH="/opt/IBM/InstallationManager"
@when_not 'ibm-im.installed'
function install_ibm_im(){
# Fail fast if we're on an unsupported arch
if [ "$ARCHITECTURE" != "x86_64" -a "$ARCHITECTURE" != "ppc64le" ]; then
juju-log "IBM IM: only supported on x86_64 or ppc64le platforms"
status-set blocked "unsupported architecture"
exit 1
fi
# Get the installable resource
juju-log "IBM IM: fetching the ibm_im_installer resource"
status-set maintenance "fetching the ibm_im_installer resource"
cfg_im_pkg_name=`resource-get 'ibm_im_installer' || echo unavailable`
# If we don't have a package, report blocked status; we can't proceed.
if [ "$cfg_im_pkg_name" = "unavailable" ]; then
juju-log "IBM IM: missing required ibm_im_installer resource"
status-set blocked "missing required ibm_im_installer resource"
exit 0
fi
juju-log "IBM IM: using $cfg_im_pkg_name as the ibm_im_installer resource"
ARCHIVE_DIR=`dirname $cfg_im_pkg_name`
# Extract the installer contents
if [ -f $cfg_im_pkg_name ]; then
juju-log "IBM IM: extracting the ibm_im_installer resource"
status-set maintenance "extracting the ibm_im_installer resource"
if [ -f $ARCHIVE_DIR/userinstc ]; then
juju-log "IBM IM: ibm_im_installer resource already extracted"
else
cd $ARCHIVE_DIR
if ! unzip $cfg_im_pkg_name; then
juju-log "IBM IM: Unable to extract the ibm_im_installer resource"
# Remove corrupt archive file
status-set blocked "ibm_im_installer resource is corrupt"
rm -rf $ARCHIVE_DIR
exit 0
else
juju-log "IBM IM: ibm_im_installer resource extracted successfully"
fi
fi
fi
# Do the actual IBM IM install
if [ -f $ARCHIVE_DIR/userinstc ]; then
juju-log "IBM IM: starting installation."
status-set maintenance "installing ibm-im"
cp $ARCHIVE_DIR/install.xml $ARCHIVE_DIR/silent_install.xml
sed -i "2 a \<profile kind='self' installLocation='$IM_INSTALL_PATH' id='IBM Installation Manager'>\n <data key='eclipseLocation' value='$IM_INSTALL_PATH' />\n</profile>" $ARCHIVE_DIR/silent_install.xml
if $ARCHIVE_DIR/userinstc -input $ARCHIVE_DIR/silent_install.xml -acceptlicense; then
set_state 'ibm-im.installed'
status-set active "ready"
else
juju-log "IBM IM: error while installing"
exit 1
fi
else
juju-log "IBM IM: installer was not found."
status-set blocked "installation failed"
exit 1
fi
}
@when 'ibm-im.installed'
@when_not 'ibm-im.updated'
function install_ibm_im_fixpack(){
# Get the fixpack resource
juju-log "IBM IM: fetching the ibm_im_fixpack resource"
status-set maintenance "fetching the ibm_im_fixpack resource"
ibm_im_fp_package=`resource-get 'ibm_im_fixpack' || echo unavailable`
# If we don't have a fixpack, just exit successfully; there's nothing to do.
if [ "$ibm_im_fp_package" = "unavailable" ]; then
juju-log "IBM IM: no ibm_im_fixpack to install"
status-set active "ready"
exit 0
fi
# Currently, there is no way to make a resource optional, so something
# must be uploaded to the charm store, even if it's a dummy archive.
# If we detect the fixpack is just a placeholder (because we created an
# empty placeholder in the store), exit just like we do with a missing
# fixpack resource.
ibm_im_fp_empty=`file $ibm_im_fp_package | { grep -q empty && echo "True"; } || echo "False"`
if [ "$ibm_im_fp_empty" = "True" ]; then
juju-log "IBM IM: no ibm_im_fixpack to install"
status-set active "ready"
exit 0
fi
juju-log "IBM IM: using $ibm_im_fp_package as the ibm_im_fixpack resource"
ARCHIVE_DIR=`dirname $ibm_im_fp_package`
# Extract the fixpack contents
if [ -f $ibm_im_fp_package ]; then
juju-log "IBM IM: extracting the ibm_im_fixpack resource"
status-set maintenance "extracting the ibm_im_fixpack resource"
if [ -f $ARCHIVE_DIR/userinstc ]; then
juju-log "IBM IM: ibm_im_fixpack resource already extracted"
else
cd $ARCHIVE_DIR
if ! unzip $ibm_im_fp_package; then
juju-log "IBM IM: Unable to extract the ibm_im_fixpack resource"
# Remove corrupt archive file
status-set blocked "ibm_im_fixpack resource is corrupt"
rm -rf $ARCHIVE_DIR
exit 0
else
juju-log "IBM IM: ibm_im_fixpack resource extracted successfully"
fi
fi
fi
# Do the actual IBM IM fixpack install
if [ -f $ARCHIVE_DIR/userinstc ]; then
juju-log "IBM IM: starting fixpack installation."
status-set maintenance "installing fixpack"
cp $ARCHIVE_DIR/install.xml $ARCHIVE_DIR/silent_install.xml
sed -i "2 a \<profile kind='self' installLocation='$IM_INSTALL_PATH' id='IBM Installation Manager'>\n <data key='eclipseLocation' value='$IM_INSTALL_PATH' />\n</profile>" $ARCHIVE_DIR/silent_install.xml
if $ARCHIVE_DIR/userinstc -input $ARCHIVE_DIR/silent_install.xml -acceptlicense; then
set_state 'ibm-im.updated'
status-set active "ready"
else
juju-log "IBM IM: error while installing the fixpack."
exit 1
fi
else
juju-log "IBM_IM: Fix pack installer was not found."
status-set blocked "fixpack installation failed"
exit 1
fi
}
@hook 'upgrade-charm'
function check_fixpack(){
# The upgrade-charm hook will fire when a new resource is pushed for this
# charm. This is a good time to determine if we need to deal with a new
# fixpack.
if ! charms.reactive is_state 'ibm-im.updated'; then
# If there is no prior fixpack installed (because ibm-im.updated is not
# set), do nothing since install-ibm-im-fixpack will handle that case.
juju-log "IBM IM: no fixpack has been installed; nothing to upgrade."
exit 0
else
# If we have a fixpack already (because ibm-im.updated is set),
# we should fetch the latest fixpack and determine if it is new.
# - If it is new, set our states so install-ibm-im-fixpack is called again
# - If it is not new, do nothing
juju-log "IBM IM: scanning for new fixpacks to install"
ARCHIVE_DIR="$CHARM_DIR/../resources/ibm_im_fixpack"
CUR_FIXPACK="$ARCHIVE_DIR/ibm_im_fixpack.zip"
# Sum any existing fixpack to determine if we have a new one
if [ -f $CUR_FIXPACK ]; then
CUR_MD5=`md5sum "$CUR_FIXPACK" | awk '{print $1}'`
# Calling resource-get here will fetch the fixpack resource.
NEW_FIXPACK=`resource-get 'ibm_im_fixpack' || echo unavailable`
if [ "$NEW_FIXPACK" = "unavailable" ]; then
juju-log "IBM IM: no fixpack to install"
else
NEW_MD5=`md5sum "$NEW_FIXPACK" | awk '{print $1}'`
# If sums don't match, we have a new fp. Configure states so
# we re-run install-ibm-im-fixpack().
if [ "$CUR_MD5" != "$NEW_MD5" ]; then
juju-log "IBM IM: new fixpack detected ($CUR_FIXPACK with $CUR_MD5 versus $NEW_FIXPACK with $NEW_MD5)"
rm -rf $ARCHIVE_DIR
remove_state 'ibm-im.updated'
else
juju-log "IBM IM: no new fixpack to install"
fi
fi
fi
fi
}
reactive_handler_main
|