4
4
source charms.reactive.sh
5
ARCHIVE_DIR=files/archives
6
5
ARCHITECTURE=`uname -m`
8
7
# Installation Manager install path
9
8
IM_INSTALL_PATH="/opt/IBM/InstallationManager"
12
@when 'ibm-base.license.accepted' 'ibm-base.curl.resource.fetched'
13
10
@when_not 'ibm-im.installed'
14
function install-ibm-im(){
15
# Get the package name to check whether the user wants to install a different package
16
im_file_name="$(layer_option ibm-im ibm_im_package)"
17
cfg_im_pkg_name=$im_file_name
19
#Check whether user has selected right package name from the package name string. If he selects wrong package name , install would fail.
20
# Set package name to a predefined value if user have not set the layer option
21
if [ "$cfg_im_pkg_name" == "" ]; then
22
if [ "$ARCHITECTURE" = "x86_64" ]; then
23
DEFAULT_INSTALLER_FILE_IM="agent.installer.linux.gtk.x86_64_1.8.3000.20150606_0047.zip"
24
elif [ "$ARCHITECTURE" = "ppc64le" ]; then
25
DEFAULT_INSTALLER_FILE_IM="agent.installer.linux.gtk.ppc64le_1.8.1000.20141126_2002.zip"
27
status-set blocked "IBM IM: Platform not supported"
29
cfg_im_pkg_name=${DEFAULT_INSTALLER_FILE_IM}
31
if [ "$ARCHITECTURE" = "x86_64" ]; then
32
juju-log "Checking the package name"
33
if echo "$cfg_im_pkg_name" | grep -q "x86"; then
34
juju-log "IBM IM: Package name is matching for the platform"
36
juju-log "IBM IM: Probably Not the right package. IM install will fail if its not the right package"
37
status-set blocked "Probably Not the right package. Please configure the correct package name"
41
if echo "$cfg_im_pkg_name" | grep -q "ppcle"; then
42
juju-log "IBM IM: Package name is matching for the platform"
44
juju-log "IBM IM: Probably Not the right package. IM install will fail if its not the right package"
45
status-set blocked "Probably Not the right package. Please configure the correct package name"
51
# Do the actual IBM IM install
52
if [ -f $CHARM_DIR/$ARCHIVE_DIR/$cfg_im_pkg_name ]; then
53
juju-log "IBM IM: downloading and extracting IM packages"
54
if [ -f $CHARM_DIR/$ARCHIVE_DIR/userinstc ]; then
55
juju-log "IBM IM: IBM IM package contents extracted already."
11
function install_ibm_im(){
12
# Fail fast if we're on an unsupported arch
13
if [ "$ARCHITECTURE" != "x86_64" -a "$ARCHITECTURE" != "ppc64le" ]; then
14
juju-log "IBM IM: only supported on x86_64 or ppc64le platforms"
15
status-set blocked "unsupported architecture"
19
# Get the installable resource
20
juju-log "IBM IM: fetching the ibm_im_installer resource"
21
status-set maintenance "fetching the ibm_im_installer resource"
22
cfg_im_pkg_name=`resource-get 'ibm_im_installer' || echo unavailable`
24
# If we don't have a package, report blocked status; we can't proceed.
25
if [ "$cfg_im_pkg_name" = "unavailable" ]; then
26
juju-log "IBM IM: missing required ibm_im_installer resource"
27
status-set blocked "missing required ibm_im_installer resource"
31
juju-log "IBM IM: using $cfg_im_pkg_name as the ibm_im_installer resource"
32
ARCHIVE_DIR=`dirname $cfg_im_pkg_name`
34
# Extract the installer contents
35
if [ -f $cfg_im_pkg_name ]; then
36
juju-log "IBM IM: extracting the ibm_im_installer resource"
37
status-set maintenance "extracting the ibm_im_installer resource"
38
if [ -f $ARCHIVE_DIR/userinstc ]; then
39
juju-log "IBM IM: ibm_im_installer resource already extracted"
57
cd $CHARM_DIR/$ARCHIVE_DIR
59
if ! unzip $cfg_im_pkg_name -d $CHARM_DIR/$ARCHIVE_DIR
61
juju-log "IBM IM: Unable to extract the IM package content. Verify whether the package is corrupt."
42
if ! unzip $cfg_im_pkg_name; then
43
juju-log "IBM IM: Unable to extract the ibm_im_installer resource"
62
44
# Remove corrupt archive file
63
status-set blocked "IBM Installation Manager package is corrupt"
64
rm -f $CHARM_DIR/$ARCHIVE_DIR/$im_pkg_name
45
status-set blocked "ibm_im_installer resource is corrupt"
67
juju-log "IBM IM: Installation Manager extracted successfully."
49
juju-log "IBM IM: ibm_im_installer resource extracted successfully"
71
juju-log "IBM IM: IM installation start"
72
# Check IM package availability
73
juju-log $CHARM_DIR/$ARCHIVE_DIR
74
if [ -f $CHARM_DIR/$ARCHIVE_DIR/userinstc ];
77
juju-log "IBM IM: IM Packages available for installation."
78
cp $CHARM_DIR/$ARCHIVE_DIR/install.xml $CHARM_DIR/$ARCHIVE_DIR/silent_install.xml
79
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>" $CHARM_DIR/$ARCHIVE_DIR/silent_install.xml
80
if $CHARM_DIR/$ARCHIVE_DIR/userinstc -input $CHARM_DIR/$ARCHIVE_DIR/silent_install.xml -acceptlicense
82
set_state 'ibm-im.installed'
84
status-set active "IBM IM: IM Is installed successfully"
54
# Do the actual IBM IM install
55
if [ -f $ARCHIVE_DIR/userinstc ]; then
56
juju-log "IBM IM: starting installation."
57
status-set maintenance "installing ibm-im"
58
cp $ARCHIVE_DIR/install.xml $ARCHIVE_DIR/silent_install.xml
59
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
60
if $ARCHIVE_DIR/userinstc -input $ARCHIVE_DIR/silent_install.xml -acceptlicense; then
61
set_state 'ibm-im.installed'
62
status-set active "ready"
64
juju-log "IBM IM: error while installing"
86
juju-log "IBM IM: Error while installing IM"
68
juju-log "IBM IM: installer was not found."
69
status-set blocked "installation failed"
91
juju-log "IBM IM: IM Packages missing. Please check README file"
92
status-set maintenance "IBM IM install failed"
98
@when 'ibm-im.installed' 'config.set.ibm_im_fp_package'
74
@when 'ibm-im.installed'
99
75
@when_not 'ibm-im.updated'
100
function install-ibm-im-fixpack(){
101
ibm_im_fp_package=`config-get ibm_im_fp_package`
103
if [ -f $CHARM_DIR/$ARCHIVE_DIR/$ibm_im_fp_package ]; then
104
juju-log "IBM-IM: ibm_im_fp_package is available"
105
if [ -f $CHARM_DIR/$ARCHIVE_DIR/FP/userinstc ]; then
106
juju-log "IBM IM: IBM IM package contents extracted already."
108
mkdir $CHARM_DIR/$ARCHIVE_DIR/FP
109
cd $CHARM_DIR/$ARCHIVE_DIR
110
if ! unzip $ibm_im_fp_package -d $CHARM_DIR/$ARCHIVE_DIR/FP
112
juju-log "IBM IM: Unable to extract the IM FP package content. Verify whether the package is corrupt."
76
function install_ibm_im_fixpack(){
77
# Get the fixpack resource
78
juju-log "IBM IM: fetching the ibm_im_fixpack resource"
79
status-set maintenance "fetching the ibm_im_fixpack resource"
80
ibm_im_fp_package=`resource-get 'ibm_im_fixpack' || echo unavailable`
82
# If we don't have a fixpack, just exit successfully; there's nothing to do.
83
if [ "$ibm_im_fp_package" = "unavailable" ]; then
84
juju-log "IBM IM: no ibm_im_fixpack to install"
85
status-set active "ready"
89
# Currently, there is no way to make a resource optional, so something
90
# must be uploaded to the charm store, even if it's a dummy archive.
91
# If we detect the fixpack is just a placeholder (because we created an
92
# empty placeholder in the store), exit just like we do with a missing
94
ibm_im_fp_empty=`file $ibm_im_fp_package | { grep -q empty && echo "True"; } || echo "False"`
95
if [ "$ibm_im_fp_empty" = "True" ]; then
96
juju-log "IBM IM: no ibm_im_fixpack to install"
97
status-set active "ready"
101
juju-log "IBM IM: using $ibm_im_fp_package as the ibm_im_fixpack resource"
102
ARCHIVE_DIR=`dirname $ibm_im_fp_package`
104
# Extract the fixpack contents
105
if [ -f $ibm_im_fp_package ]; then
106
juju-log "IBM IM: extracting the ibm_im_fixpack resource"
107
status-set maintenance "extracting the ibm_im_fixpack resource"
108
if [ -f $ARCHIVE_DIR/userinstc ]; then
109
juju-log "IBM IM: ibm_im_fixpack resource already extracted"
112
if ! unzip $ibm_im_fp_package; then
113
juju-log "IBM IM: Unable to extract the ibm_im_fixpack resource"
113
114
# Remove corrupt archive file
114
status-set blocked "IBM Installation Manager fixpack package is corrupt"
115
rm -f $CHARM_DIR/$ARCHIVE_DIR/$ibm_im_fp_package
115
status-set blocked "ibm_im_fixpack resource is corrupt"
118
juju-log "IBM IM: Installation Manager Fix pack extracted successfully."
121
juju-log "IBM IM: IM upgrading start"
122
# Check IM package availability
123
juju-log $CHARM_DIR/$ARCHIVE_DIR
124
if [ -f $CHARM_DIR/$ARCHIVE_DIR/FP/userinstc ];
127
juju-log "IBM IM: IM FP Packages available for installation."
128
cp $CHARM_DIR/$ARCHIVE_DIR/FP/install.xml $CHARM_DIR/$ARCHIVE_DIR/FP/silent_install.xml
129
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>" $CHARM_DIR/$ARCHIVE_DIR/FP/silent_install.xml
130
if $CHARM_DIR/$ARCHIVE_DIR/FP/userinstc -input $CHARM_DIR/$ARCHIVE_DIR/FP/silent_install.xml -acceptlicense
132
set_state 'ibm-im.updated'
134
status-set active "IBM IM: IM Is updated successfully"
136
juju-log "IBM IM: Error while updating IM"
142
juju-log "IBM_IM: Fix pack is not available to install, please provide the correct package"
143
status-set maintenance "IBM IM updating failed"
119
juju-log "IBM IM: ibm_im_fixpack resource extracted successfully"
124
# Do the actual IBM IM fixpack install
125
if [ -f $ARCHIVE_DIR/userinstc ]; then
126
juju-log "IBM IM: starting fixpack installation."
127
status-set maintenance "installing fixpack"
128
cp $ARCHIVE_DIR/install.xml $ARCHIVE_DIR/silent_install.xml
129
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
130
if $ARCHIVE_DIR/userinstc -input $ARCHIVE_DIR/silent_install.xml -acceptlicense; then
131
set_state 'ibm-im.updated'
132
status-set active "ready"
134
juju-log "IBM IM: error while installing the fixpack."
138
juju-log "IBM_IM: Fix pack installer was not found."
139
status-set blocked "fixpack installation failed"
149
@when 'config.changed.ibm_im_fp_package'
150
function config-changed-ibm-im-fp(){
151
rm -rf $CHARM_DIR/$ARCHIVE_DIR/FP
152
remove_state 'ibm-im.updated'
156
@when 'ibm-im.installed'
157
@when_not 'ibm-base.license.accepted'
158
function uninstall() {
159
juju-log "IBM IM: Removing IBM IM software."
160
/root/var/ibm/InstallationManager/uninstall/uninstallc
161
juju-log "IBM IM: Removed IBM IM software"
162
remove_state "ibm-im.installed"
163
status-set blocked "IBM IM uninstalled"
144
@hook 'upgrade-charm'
145
function check_fixpack(){
146
# The upgrade-charm hook will fire when a new resource is pushed for this
147
# charm. This is a good time to determine if we need to deal with a new
149
if ! charms.reactive is_state 'ibm-im.updated'; then
150
# If there is no prior fixpack installed (because ibm-im.updated is not
151
# set), do nothing since install-ibm-im-fixpack will handle that case.
152
juju-log "IBM IM: no fixpack has been installed; nothing to upgrade."
155
# If we have a fixpack already (because ibm-im.updated is set),
156
# we should fetch the latest fixpack and determine if it is new.
157
# - If it is new, set our states so install-ibm-im-fixpack is called again
158
# - If it is not new, do nothing
159
juju-log "IBM IM: scanning for new fixpacks to install"
160
ARCHIVE_DIR="$CHARM_DIR/../resources/ibm_im_fixpack"
161
CUR_FIXPACK="$ARCHIVE_DIR/ibm_im_fixpack.zip"
163
# Sum any existing fixpack to determine if we have a new one
164
if [ -f $CUR_FIXPACK ]; then
165
CUR_MD5=`md5sum "$CUR_FIXPACK" | awk '{print $1}'`
166
# Calling resource-get here will fetch the fixpack resource.
167
NEW_FIXPACK=`resource-get 'ibm_im_fixpack' || echo unavailable`
168
if [ "$NEW_FIXPACK" = "unavailable" ]; then
169
juju-log "IBM IM: no fixpack to install"
171
NEW_MD5=`md5sum "$NEW_FIXPACK" | awk '{print $1}'`
172
# If sums don't match, we have a new fp. Configure states so
173
# we re-run install-ibm-im-fixpack().
174
if [ "$CUR_MD5" != "$NEW_MD5" ]; then
175
juju-log "IBM IM: new fixpack detected ($CUR_FIXPACK with $CUR_MD5 versus $NEW_FIXPACK with $NEW_MD5)"
177
remove_state 'ibm-im.updated'
179
juju-log "IBM IM: no new fixpack to install"
166
187
reactive_handler_main