~charmers/charms/trusty/ibm-xlc/trunk

« back to all changes in this revision

Viewing changes to hooks/config-changed

  • Committer: Shilpa Kaul
  • Date: 2016-01-07 05:53:40 UTC
  • mfrom: (12.1.6 ibm-xlc)
  • Revision ID: shilkaul@in.ibm.com-20160107055340-u99myu5bcin241hb
Merged code with Kevin's branch for ibm-xlc

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
set -e
5
5
ARCHIVE_DIR=$CHARM_DIR/files/archives
6
6
IBM_XLC_INSTALL_PATH=/opt/ibm/xlC
7
 
IBM_XLC_PARENT_FOLDER=/opt/ibm
8
7
 
9
8
# Check whether XL C/C++ is installed
10
9
is_xlc_installed()
11
10
{
12
 
     if [ -d $IBM_XLC_INSTALL_PATH ] ; then
13
 
             echo "True"
14
 
             juju-log " IBM XL C/C++ : IBM XL C/C++ is installed"
15
 
     else
16
 
                 
17
 
             echo "False"
18
 
             juju-log " IBM XL C/C++ : IBM XL C/C++ is not installed"
19
 
     fi
20
 
           
21
 
     
 
11
  if [ -d $IBM_XLC_INSTALL_PATH ]; then
 
12
    echo "True"
 
13
    juju-log " IBM XL C/C++ : IBM XL C/C++ is installed"
 
14
  else
 
15
    echo "False"
 
16
    juju-log " IBM XL C/C++ : IBM XL C/C++ is not installed"
 
17
  fi
22
18
}
23
19
 
24
 
 
25
 
# enabling manpages and error messages 
26
 
 
 
20
 
 
21
# enabling manpages and error messages
27
22
enable_man_error()
28
 
 {
29
 
 
 
23
{
30
24
  cd $IBM_XLC_INSTALL_PATH
31
25
  xlc_conf_path=`find . -name xlc_configure`
32
26
  xlc_version=`echo $xlc_conf_path | awk -F'/' '{print $2}'`
33
 
  cd /etc
34
 
 
35
 
  if grep export profile | grep "/opt/ibm/msg/%L/%N" profile 
36
 
  then
37
 
          juju-log "IBM XL C/C++ : export NLSPATH already added in profile file"
38
 
  else
39
 
          sudo sed -i -e '$a\export NLSPATH=$NLSPATH:/opt/ibm/msg/%L/%N ' /etc/profile
40
 
          if [ $? = 0 ];then
41
 
                juju-log "IBM XL C/C++ : Enabling of error messages done successfully"
42
 
          else
43
 
                juju-log "IBM XL C/C++ : Enabling of error messages is not done correctly , please review /etc/profile file"
44
 
          fi
45
 
 
46
 
  fi
47
 
 
48
 
  if grep export profile | grep $xlc_version/man/en_US
49
 
  then
50
 
          juju-log "IBM XL C/C++ : export MANPATH for version $xlc_version already added in profile file"
51
 
  else
52
 
 
53
 
          echo export MANPATH=$IBM_XLC_INSTALL_PATH/$xlc_version/man/en_US:"$"MANPATH >> /etc/profile
54
 
          if [ $? = 0 ];then
55
 
                juju-log "IBM XL C/C++ : Enabling of manual pages done successfully"
56
 
          else
57
 
                juju-log "IBM XL C/C++ : Enabling of manual pages is not done correctly , please review /etc/profile file"
58
 
          fi
59
 
  fi
60
 
 
 
27
 
 
28
  if grep "NLSPATH:/opt/ibm/msg/%L/%N" /etc/profile
 
29
  then
 
30
    juju-log "IBM XL C/C++ : export NLSPATH already added in /etc/profile"
 
31
  else
 
32
    echo "export NLSPATH=/opt/ibm/msg/%L/%N:\$NLSPATH" >> /etc/profile
 
33
    if [ $? -eq 0 ]; then
 
34
      juju-log "IBM XL C/C++ : Enabling of error messages done successfully"
 
35
    else
 
36
      juju-log "IBM XL C/C++ : Enabling of error messages is not done correctly, please review /etc/profile"
 
37
    fi
 
38
  fi
 
39
 
 
40
  if grep "$xlc_version/man/en_US" /etc/profile
 
41
  then
 
42
    juju-log "IBM XL C/C++ : export MANPATH for version $xlc_version already added in /etc/profile"
 
43
  else
 
44
    echo "export MANPATH=$IBM_XLC_INSTALL_PATH/$xlc_version/man/en_US:\$MANPATH" >> /etc/profile
 
45
    if [ $? -eq 0 ]; then
 
46
      juju-log "IBM XL C/C++ : Enabling of manual pages done successfully"
 
47
    else
 
48
      juju-log "IBM XL C/C++ : Enabling of manual pages is not done correctly, please review /etc/profile"
 
49
    fi
 
50
  fi
61
51
}
62
52
 
63
53
 
64
54
# Creating sample C/C++ programs for testing the compiler installation
65
 
 create_prog_compiler()
66
 
 {
67
 
 
68
 
 
69
 
  cd $CHARM_DIR/files/archives/
70
 
  if  [ -f $CHARM_DIR/files/archives/hello.c ]; then
71
 
           juju-log "IBM XL C/C++ : Sample C file hello.c already exists in files/archives folder , you can run it for your verification"
72
 
 
73
 
  else
74
 
           touch hello.c
75
 
           echo "#include <stdio.h>" >> hello.c
76
 
           echo "int main(void)" >> hello.c
77
 
           echo "{" >> hello.c
78
 
           echo "printf(\""Hello World C\!\\n\"");" >> hello.c
79
 
           echo "return 0;" >> hello.c
80
 
           echo "}" >> hello.c
81
 
           juju-log "IBM XL C/C++ : Created sample C program <hello.c> in files/archives to test the product installation and the critical search paths."
82
 
 
83
 
  fi
84
 
 
85
 
 
86
 
  if   [ -f $CHARM_DIR/files/archives/hello1.cpp ]; then
87
 
            juju-log "IBM XL C/C++ : Sample C++ file hello1.cpp already exists in files/archives folder, you can run it for your verification"
88
 
 
89
 
  else
90
 
            touch hello1.cpp
91
 
            echo "#include <iostream>" >> hello1.cpp
92
 
            echo "using namespace std;" >> hello1.cpp
93
 
            echo "int main()" >> hello1.cpp
94
 
            echo "{" >> hello1.cpp
95
 
            echo "cout << \""Hello World C++\!\\n\"";" >> hello1.cpp
96
 
            echo "return 0;" >> hello1.cpp
97
 
            echo "}" >> hello1.cpp
98
 
            juju-log "IBM XL C/C++ : Created sample C++ program <hello1.cpp> in files/archives to test the product installation and the critical search paths."
99
 
 
100
 
         
101
 
  fi
102
 
 
 
55
create_prog_compiler()
 
56
{
 
57
  cd $ARCHIVE_DIR
 
58
  if  [ -f $ARCHIVE_DIR/hello.c ]; then
 
59
    juju-log "IBM XL C/C++ : Sample C file hello.c already exists in files/archives folder, you can run it for your verification"
 
60
  else
 
61
    touch hello.c
 
62
    echo "#include <stdio.h>" >> hello.c
 
63
    echo "int main(void)" >> hello.c
 
64
    echo "{" >> hello.c
 
65
    echo "printf(\""Hello World C\!\\n\"");" >> hello.c
 
66
    echo "return 0;" >> hello.c
 
67
    echo "}" >> hello.c
 
68
    juju-log "IBM XL C/C++ : Created sample C program <hello.c> in files/archives to test the product installation and the critical search paths."
 
69
  fi
 
70
 
 
71
  if  [ -f $ARCHIVE_DIR/hello1.cpp ]; then
 
72
    juju-log "IBM XL C/C++ : Sample C++ file hello1.cpp already exists in files/archives folder, you can run it for your verification"
 
73
  else
 
74
    touch hello1.cpp
 
75
    echo "#include <iostream>" >> hello1.cpp
 
76
    echo "using namespace std;" >> hello1.cpp
 
77
    echo "int main()" >> hello1.cpp
 
78
    echo "{" >> hello1.cpp
 
79
    echo "cout << \""Hello World C++\!\\n\"";" >> hello1.cpp
 
80
    echo "return 0;" >> hello1.cpp
 
81
    echo "}" >> hello1.cpp
 
82
    juju-log "IBM XL C/C++ : Created sample C++ program <hello1.cpp> in files/archives to test the product installation and the critical search paths."
 
83
  fi
103
84
}
104
85
 
105
86
 
106
 
 
107
87
juju-log "IBM XL C/C++ : Begin config-changed hook"
108
88
 
109
89
# Check for architecture
110
90
ARCHITECTURE=`uname -m`
111
91
if [ "$ARCHITECTURE" != "ppc64le" ]; then
112
 
        juju-log "IBM XL C/C++: Unsupported platform. IBM XL C/C++ installed with this Charm supports only POWER LE (ppc64le) platforms."
113
 
        status-set blocked "Unsupported platform ,deploy on Power LE platform"
114
 
        exit 0
 
92
  juju-log "IBM XL C/C++: Unsupported platform. IBM XL C/C++ installed with this Charm supports only POWER LE (ppc64le) platforms."
 
93
  status-set blocked "Unsupported platform ,deploy on Power LE platform"
 
94
  exit 0
115
95
fi
116
96
 
117
97
 
118
 
 
119
 
cd $ARCHIVE_DIR
120
 
# Extract IBM XLC packages and install it
121
 
 
122
98
xlc_installed=`is_xlc_installed`
123
99
if  [ $xlc_installed == False ]; then
124
 
       if [ -f  $ARCHIVE_DIR/IBM_XL_C_CPP*.tar.gz ]; then
125
 
 
126
 
             # extract XLC package if it is present at /files/archives folder
127
 
             juju-log " IBM XL C/C++ : Extracting the packages"           
128
 
             tar -xzvf *.tar.gz 
129
 
             if [ $? != 0 ]; then
130
 
                   juju-log "IBM XL C/C++: Unable to extract the XL C/C++ package content. Verify whether the package is corrupt."
131
 
                   # Remove corrupt archive file
132
 
                   rm $ARCHIVE_DIR/*.tar.gz
133
 
                   status-set blocked "Package is corrupt, failed to extract"
134
 
                   exit 0
135
 
             else 
136
 
                   juju-log "IBM XL C/C++ packages extracted successfully"
137
 
 
138
 
                   # lib and required packages before installing xlc
139
 
                   apt-get install gcc g++ libc6-dev perl -y
140
 
      
141
 
                   # Running install command
142
 
                   juju-log "IBM XL C/C++ : Running install command for installing IBM XL C/C++"
143
 
                   echo 1 | $ARCHIVE_DIR/install
144
 
                   if [ $? != 0 ]; then
145
 
                         juju-log "IBM XL C/C++ : Error while installing Compiler packages into the default location, /opt/ibm/."
146
 
                         exit 1
147
 
                   else
148
 
                         juju-log "IBM XL C/C++ : Compiler packages are successfully installed and configured into default location ,opt/ibm/."
149
 
                         # For enabling the manual pages and xlc error codes
150
 
                         enable_man_error
151
 
                         # For creating sample C/C++ programs
152
 
                         create_prog_compiler
153
 
                         status-set active "IBM XL C/C++ Installed successfully"
154
 
                   fi
155
 
     
156
 
                              
157
 
                        
158
 
             fi
159
 
       else
160
 
             juju-log "IBM XL C/C++ : XL C/C++ packages are missing. Please place correct packages at files/archives folder." 
161
 
             status-set blocked "XL C/C++ packages are missing, place correct packages at files/archives folder"
162
 
             exit 0
163
 
             
164
 
       fi
 
100
  juju-log "IBM XL C/C++ : Installing packages"
 
101
  status-set maintenance "Installing IBM XL C/C++ packages"
 
102
  # Note: package list comes from: http://public.dhe.ibm.com/software/server/POWER/Linux/xl-compiler/eval/ppc64le/
 
103
  apt-get install -qy xlc.13.1.3 xlc-license-eval.13.1.3 libxlc libxlc-devel.13.1.3 libxlsmp libxlsmp-devel.4.1.3 libxlmass-devel.8.1.3
 
104
  if [ $? -ne 0 ]; then
 
105
    juju-log "IBM XL C/C++: Failed to install packages"
 
106
    status-set blocked "Failed to install IBM XL C/C++ packages"
 
107
    exit 1
 
108
  else
 
109
    juju-log "IBM XL C/C++ : Running xlc_configure"
 
110
 
 
111
    echo 1 | /opt/ibm/xlC/13.1.3/bin/xlc_configure
 
112
    if [ $? -ne 0 ]; then
 
113
      juju-log "IBM XL C/C++ : Error running xlc_configure"
 
114
      status-set blocked "Failed to run xlc_configure"
 
115
      exit 1
 
116
    else
 
117
      # For enabling the manual pages and xlc error codes
 
118
      enable_man_error
 
119
      # For creating sample C/C++ programs
 
120
      create_prog_compiler
 
121
      juju-log "IBM XL C/C++ : Compiler packages are successfully installed and configured"
 
122
      status-set active "IBM XL C/C++ Ready"
 
123
    fi
 
124
  fi
165
125
else
166
 
       juju-log "IBM XL C/C++ : XL C/C++ is already installed at /opt/ibm/xlC location"
167
 
       status-set blocked "XL C/C++ is already installed at /opt/ibm/xlC location"
168
 
       
169
 
 
 
126
  juju-log "IBM XL C/C++ : XL C/C++ is already installed at $IBM_XLC_INSTALL_PATH"
 
127
  status-set blocked "XL C/C++ is already installed at $IBM_XLC_INSTALL_PATH"
170
128
fi
171
129
 
172
 
 
173
 
juju-log "IBM XL C/C++: End config-change hook"
 
130
juju-log "IBM XL C/C++ : End config-change hook"