Ubuntu Pastebin

Paste from install.sh at Thu, 17 Dec 2015 18:25:27 +0000

Download as text
  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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
set -ex

source charms.reactive.sh

ARCHIVE_DIR=$CHARM_DIR/files/archives

# Fail fast if we're not on a supported arch. Also set defaults for filename
# and sha1sum based on arch.
ARCHITECTURE=`uname -m`
DEFAULT_INSTALLER_FILE=""
DEFAULT_INSTALLER_SHA=""
if [ "$ARCHITECTURE" = "x86_64" ]; then
        DEFAULT_INSTALLER_FILE="ibm-java-x86_64-sdk-8.0-1.0.bin"
        DEFAULT_INSTALLER_SHA="83a1945e74b0ac0120296a217647c7920723b431"
elif [ "$ARCHITECTURE" = "ppc64le" ]; then
        DEFAULT_INSTALLER_FILE="ibm-java-ppc64le-sdk-8.0-1.10.bin"
        DEFAULT_INSTALLER_SHA="4e20a11a7a2213e04b3fba06b21b6cc3aeb9adf8"
else
        status-set blocked "IBM Java SDK: Platform not supported"
fi

# Ensure we have a target installation directory
JAVASDK_INSTALL_PATH=$(config-get javasdk_path_name)
if [ "$JAVASDK_INSTALL_PATH" == "" ]; then
        status-set blocked "Set 'javasdk_path_name' to the target installation directory"
fi

# Ensure we have a url to download the installer
JAVASDK_URL=$(config-get javasdk_url)
if [ "$JAVASDK_URL" == "" ]; then
        status-set blocked "Set 'javasdk_url' to the URL hosting the installer"
fi

javasdk_license_accepted=`config-get accept-ibm-javasdk-license`
if [ "$javasdk_license_accepted" == "" ]; then
        status-set blocked "Set 'accept-ibm-javasdk-license' to True or False"
fi

# Check whether IBM Java JDK is installed
function is_javasdk_installed()
{

        if  [ -d $JAVASDK_INSTALL_PATH/bin ]; then
                echo "True"
        else
                echo "False"
        fi

}


# Remove IBM Java SDK, if installed. This function doesn't log or set status
# when it runs because we have different reasons for removing this software.
# Be sure to set appropriate log and status messages before and after this
# function is called.
function remove_javasdk_software()
{

        javasdk_installed=`is_javasdk_installed`
        if  [ $javasdk_installed == "True" ]; then
                $JAVASDK_INSTALL_PATH/_uninstall/uninstall
                rm -rf $JAVASDK_INSTALL_PATH
                sed --in-place '/export/d' /etc/profile
                update-alternatives --remove "java" "$JAVASDK_INSTALL_PATH/bin/java"
        fi
}

#Downloading IBM Java SDK Package
function download_SDK()
{
        # If an install was done, get the name of the package from which it was done
        if [ -f  $ARCHIVE_DIR/*.bin ]; then
                pkg_name=`ls $ARCHIVE_DIR/*.bin`
                if [ $? == 0 ]; then
                        pkg_name=`basename $pkg_name`
                fi
        fi

        # Get the package name to check whether the user wants to install a different package
        cfg_pkg_name=`config-get javasdk_file_name`

        # Set package name to a predefined value if the user has not provided a package name
        if [ "$cfg_pkg_name" == "" ]; then
                cfg_pkg_name=${DEFAULT_INSTALLER_FILE}
        fi

        # The user has configured a different package name
        if  [ "$pkg_name" != "$cfg_pkg_name" ]; then

                #Download the new IBM Java SDK package
                set +e
                status-set maintenance "Downloading IBM Java SDK installer"
                wget -t 2  -P $ARCHIVE_DIR $JAVASDK_URL/$cfg_pkg_name
                if [ $? == 0 ]; then
                        juju-log "IBM Java SDK: Downloaded IBM Java SDK package."
                        chmod -R 777 $ARCHIVE_DIR/*
                        # Remove previously downloaded and installed IBM Java SDK software
                        if [ "$pkg_name" != "" ]; then
                                rm  $ARCHIVE_DIR/$pkg_name
                                status-set maintenance "Removing older IBM Java SDK (if installed)"
                                remove_javasdk_software
                        fi
                else
                        status-set blocked "Download failed from $JAVASDK_URL/$cfg_pkg_name; set valid 'javasdk_url' and 'javasdk_file_name' options"
                        exit 0
                fi
                set -e
        fi

        # Check integrity of downloaded package
        SHA=`config-get sha`
        if [ "$SHA" == "" ]; then
                SHA=${DEFAULT_INSTALLER_SHA}
        fi
        if [ "$SHA" != "`sha1sum $ARCHIVE_DIR/$cfg_pkg_name | cut -d" " -f1`" ]; then
                status-set blocked "SHA mismatch; set 'sha' to the sha1sum of ${cfg_pkg_name}"
                exit 0
        fi
}

# Check Environment Variables for IBM Java SDK/JRE
function check_javapath()
{
        cd /etc
        if grep -q "$JAVASDK_INSTALL_PATH" profile
        then
                echo "True"
        else
                echo "False"
        fi
}

javasdk_license_accepted=`config-get accept-ibm-javasdk-license`
if [ $javasdk_license_accepted == "True" ]; then
        set_state 'license.accepted'
else
        remove_state 'license.accepted'
fi


@when 'java.connected' 'license.accepted'
@when_not 'java.installed'
function install() {
        java_major=$(config-get 'java-major')
        cd $ARCHIVE_DIR
        echo "LICENSE_ACCEPTED=TRUE" >> installer.properties
        echo "USER_INSTALL_DIR=$JAVASDK_INSTALL_PATH" >> installer.properties
        echo "INSTALLER_UI=silent" >> installer.properties
        download_SDK
        status-set maintenance "Installing IBM Java SDK"
        $ARCHIVE_DIR/$cfg_pkg_name -i silent -f $ARCHIVE_DIR/installer.properties
        set_java_path=`check_javapath`
        if [ $set_java_path == "False" ]; then
                cd /etc
                echo "export PATH=$JAVASDK_INSTALL_PATH/bin:$JAVASDK_INSTALL_PATH/jre/bin:$PATH" >> profile
                echo "export PATH=${PATH}:$JAVASDK_INSTALL_PATH/bin:$JAVASDK_INSTALL_PATH/jre/bin:$PATH" >> profile
                source /etc/profile
        else
                source /etc/profile
        fi
        echo "Set Point 1"
        update-alternatives --install "/usr/bin/java" "java" "$JAVASDK_INSTALL_PATH/bin/java" 1
        echo "Set Point 2"
        update-alternatives --set "java" "$JAVASDK_INSTALL_PATH/bin/java"

        # Send relation data
        java_home=$(readlink -f /usr/bin/java | sed "s:/bin/java::")
        java_version=$(java -version 2>&1 | head -1 | awk -F '"' {'print $2'})
        relation_call --relation_name=java set_ready $java_home $java_version

        set_state 'java.installed'
        echo "Set Point 3"
        status-set active "IBM Java SDK ${java_major} installed"
        java -version
        if [ $? == 0 ]; then
                status-set active "Ready: IBM Java SDK $java_version"
        else
                update-alternatives --remove "java" "$JAVASDK_INSTALL_PATH/bin/java"
                status-set blocked "IBM Java SDK: Error while installing IBM Java SDK"
        fi
}

@when 'java.connected' 'java.installed'
function check_version() {
        java_major=$(config-get 'java-major')
        echo "Set Point 4"
        java_major_installed=$(java -version 2>&1 | head -n 1 | awk -F '"' '{print $2}')
        echo "Set Point 5"
        if [[ $java_major != $java_major_installed ]]; then
                status-set maintenance "Uninstalling all IBM Java SDK versions before installing new one"
                remove_javasdk_software
                status-set maintenance "Installing IBM Java SDK ${java_major}"
                install
                status-set active "IBM Java SDK ${java_major} is installed"
        fi
}

@when 'java.installed'
@when_not 'java.connected' 'license.accepted'
function uninstall() {
    # Uninstall all versions of IBM Java SDK
    echo "Set Point 6"
    status-set maintenance "Uninstalling all IBM Java SDK versions"
    remove_javasdk_software
    remove_state 'java.installed'
    status-set blocked "IBM (all versions) uninstalled"
}

reactive_handler_main
Download as text