~ibmcharmers/charms/trusty/ibm-im/trunk

« back to all changes in this revision

Viewing changes to reactive/ibm-im.sh

  • Committer: salmavar at ibm
  • Date: 2016-07-04 06:50:04 UTC
  • Revision ID: salmavar@in.ibm.com-20160704065004-r8meknbuqkzyf17u
Including Resources and Terms

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/bash
2
 
set -ex
 
2
set -e
3
3
 
4
4
source charms.reactive.sh
5
 
ARCHIVE_DIR=files/archives
6
5
ARCHITECTURE=`uname -m`
7
6
 
8
7
# Installation Manager install path
9
8
IM_INSTALL_PATH="/opt/IBM/InstallationManager"
10
9
 
11
 
 
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
18
 
      
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"
26
 
          else
27
 
                status-set blocked "IBM IM: Platform not supported"
28
 
          fi
29
 
             cfg_im_pkg_name=${DEFAULT_INSTALLER_FILE_IM}
30
 
      else
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"
35
 
                else
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"
38
 
                        exit 0
39
 
                fi
40
 
          else
41
 
                if echo "$cfg_im_pkg_name" | grep -q "ppcle"; then
42
 
                        juju-log "IBM IM: Package name is matching for the platform"
43
 
                else
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"
46
 
                        exit 0
47
 
                fi
48
 
          fi
49
 
      fi
50
 
 
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"
 
16
            exit 1
 
17
      fi
 
18
 
 
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`
 
23
 
 
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"
 
28
        exit 0
 
29
      fi
 
30
 
 
31
      juju-log "IBM IM: using $cfg_im_pkg_name as the ibm_im_installer resource"
 
32
      ARCHIVE_DIR=`dirname $cfg_im_pkg_name`
 
33
 
 
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"
56
40
           else
57
 
                 cd $CHARM_DIR/$ARCHIVE_DIR
58
 
 
59
 
                 if ! unzip  $cfg_im_pkg_name -d $CHARM_DIR/$ARCHIVE_DIR
60
 
                 then
61
 
                      juju-log "IBM IM: Unable to extract the IM package content. Verify whether the package is corrupt."
 
41
                 cd $ARCHIVE_DIR
 
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"
 
46
                      rm -rf $ARCHIVE_DIR
65
47
                      exit 0
66
48
                 else
67
 
                      juju-log "IBM IM: Installation Manager extracted successfully."
 
49
                      juju-log "IBM IM: ibm_im_installer resource extracted successfully"
68
50
                 fi
69
51
           fi
70
 
    fi
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 ];
75
 
    then
 
52
      fi
76
53
 
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
81
 
      then
82
 
          set_state 'ibm-im.installed'
83
 
                  
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"
 
63
        else
 
64
            juju-log "IBM IM: error while installing"
 
65
            exit 1
 
66
        fi
85
67
      else
86
 
        juju-log "IBM IM: Error while installing  IM"
 
68
        juju-log "IBM IM: installer was not found."
 
69
        status-set blocked "installation failed"
87
70
        exit 1
88
71
      fi
89
 
 
90
 
    else
91
 
      juju-log "IBM IM: IM Packages missing. Please check README file"
92
 
      status-set maintenance "IBM IM install failed"
93
 
      exit 1
94
 
    fi
95
 
  }
96
 
 
97
 
  
98
 
@when 'ibm-im.installed' 'config.set.ibm_im_fp_package'
 
72
}
 
73
 
 
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`
102
 
 
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."
107
 
         else
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
111
 
                  then
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`
 
81
 
 
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"
 
86
      exit 0
 
87
    fi
 
88
 
 
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
 
93
    # fixpack resource.
 
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"
 
98
      exit 0
 
99
    fi
 
100
 
 
101
    juju-log "IBM IM: using $ibm_im_fp_package as the ibm_im_fixpack resource"
 
102
    ARCHIVE_DIR=`dirname $ibm_im_fp_package`
 
103
 
 
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"
 
110
        else
 
111
              cd $ARCHIVE_DIR
 
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"
 
116
                      rm  -rf $ARCHIVE_DIR
116
117
                      exit 0
117
 
                  else
118
 
                      juju-log "IBM IM: Installation Manager Fix pack extracted successfully."
119
 
                  fi
120
 
         fi
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 ];
125
 
         then
126
 
 
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
131
 
             then
132
 
                 set_state 'ibm-im.updated'
133
 
                  
134
 
                 status-set active "IBM IM: IM Is updated successfully"
135
 
             else
136
 
                 juju-log "IBM IM: Error while updating  IM"
137
 
                 exit 1
138
 
             fi
139
 
         fi
140
 
 
141
 
   else
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"
 
118
              else
 
119
                      juju-log "IBM IM: ibm_im_fixpack resource extracted successfully"
 
120
              fi
 
121
        fi
 
122
    fi
 
123
 
 
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"
 
133
        else
 
134
             juju-log "IBM IM: error while installing the fixpack."
 
135
             exit 1
 
136
        fi
 
137
    else
 
138
        juju-log "IBM_IM: Fix pack installer was not found."
 
139
        status-set blocked "fixpack installation failed"
144
140
        exit 1
145
141
   fi
146
 
 
147
 
}
148
 
 
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'
153
 
     
154
 
}
155
 
 
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"
164
 
}
 
142
}
 
143
 
 
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
 
148
    # fixpack.
 
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."
 
153
        exit 0
 
154
    else
 
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"
 
162
 
 
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"
 
170
            else
 
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)"
 
176
                    rm -rf $ARCHIVE_DIR
 
177
                    remove_state 'ibm-im.updated'
 
178
                else
 
179
                    juju-log "IBM IM: no new fixpack to install"
 
180
                fi
 
181
            fi
 
182
        fi
 
183
    fi
 
184
}
 
185
 
165
186
 
166
187
reactive_handler_main