|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. |
| 4 | + |
| 5 | +# This program and the accompanying materials are made available under the |
| 6 | +# terms of the Eclipse Public License v. 2.0 which is available at |
| 7 | +# http://www.eclipse.org/legal/epl-2.0, |
| 8 | +# or the Eclipse Distribution License v. 1.0 which is available at |
| 9 | +# http://www.eclipse.org/org/documents/edl-v10.php. |
| 10 | + |
| 11 | +# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause |
| 12 | + |
| 13 | +# This script file is processed with Maven resource filtering |
| 14 | +# so variables expansion must be used with respect to defined |
| 15 | +# maven POM properties. |
| 16 | + |
| 17 | +# Docker image installation file |
| 18 | +# Print timestamp and message to sdtout |
| 19 | +# Arguments: |
| 20 | +# $1 First message to be printed |
| 21 | +# $2 Second message to be printed |
| 22 | +# ... |
| 23 | +print() { |
| 24 | + echo '['`date '+%d.%m.%Y %H:%M:%S'`'] '$@ |
| 25 | +} |
| 26 | + |
| 27 | +JENKINS_USER='${build.user.name}' |
| 28 | +JENKINS_UID='${build.user.uid}' |
| 29 | +JENKINS_GROUP='${build.group.name}' |
| 30 | +JENKINS_GID='${build.group.gid}' |
| 31 | + |
| 32 | +INSTALL_JAVA='${install.java}' |
| 33 | + |
| 34 | +print "Adding Jenkins group ${JENKINS_GROUP}:${JENKINS_GID}" |
| 35 | +groupadd -g "${JENKINS_GID}" "${JENKINS_GROUP}" |
| 36 | + |
| 37 | +print "Adding Jenkins user ${JENKINS_USER}:${JENKINS_UID}" |
| 38 | +useradd -u "${JENKINS_UID}" -g "${JENKINS_GID}" \ |
| 39 | + -s '${build.user.shell}' -c '${build.user.comment}' \ |
| 40 | + -m "${JENKINS_USER}" |
| 41 | + |
| 42 | +print "Updating the system" |
| 43 | +echo '--------------------------------------------------------------------------------' |
| 44 | +yum -y update |
| 45 | +yum -y install git |
| 46 | +echo '--------------------------------------------------------------------------------' |
| 47 | + |
| 48 | +print "Configuring Java tools in ${INSTALL_JAVA}" |
| 49 | + |
| 50 | +JDK_PATH='' |
| 51 | +for i in `ls ${INSTALL_JAVA} | grep 'jdk-'`; do |
| 52 | + JDK_PATH="${JDK_PATH}:${INSTALL_JAVA}/${i}/bin" |
| 53 | +done |
| 54 | +print " - Open JDK ${JDK_PATH}" |
| 55 | + |
| 56 | +ANT_PATH='' |
| 57 | +for i in `ls ${INSTALL_JAVA} | grep '\-ant-'`; do |
| 58 | + ANT_PATH="${ANT_PATH}:${INSTALL_JAVA}/${i}/bin" |
| 59 | +done |
| 60 | +print " - Apache Ant ${ANT_PATH}" |
| 61 | + |
| 62 | +MVN_PATH='' |
| 63 | +for i in `ls ${INSTALL_JAVA} | grep '\-maven-'`; do |
| 64 | + MVN_PATH="${MVN_PATH}:${INSTALL_JAVA}/${i}/bin" |
| 65 | +done |
| 66 | +print " - Apache Maven ${MVN_PATH}" |
| 67 | + |
| 68 | +if [ -n "${JDK_PATH}" ]; then |
| 69 | + TOOLS_PATH="${JDK_PATH}" |
| 70 | +else |
| 71 | + TOOLS_PATH='' |
| 72 | +fi |
| 73 | +if [ -n "${ANT_PATH}" ]; then |
| 74 | + TOOLS_PATH="${TOOLS_PATH}${ANT_PATH}" |
| 75 | +fi |
| 76 | +if [ -n "${MVN_PATH}" ]; then |
| 77 | + TOOLS_PATH="${TOOLS_PATH}${MVN_PATH}" |
| 78 | +fi |
| 79 | + |
| 80 | +print " - Adding shell profile PATH ${TOOLS_PATH}" |
| 81 | +echo '# Java tools path |
| 82 | +PATH="${PATH}'"${TOOLS_PATH}"'" |
| 83 | +' > /etc/profile.d/java_tools.sh |
| 84 | + |
| 85 | +print "Fixing startup scripts permissions" |
| 86 | +cd /opt/bin && chmod uog+x mongo-start.sh mongo-stop.sh mysql-start.sh mysql-stop.sh |
| 87 | + |
| 88 | +print "Configuring MySQL 8 yum repository" |
| 89 | +echo '--------------------------------------------------------------------------------' |
| 90 | +cd /tmp && yum -y localinstall '${mysql.pkg}' |
| 91 | +yum -y module disable mysql |
| 92 | + |
| 93 | +echo '--------------------------------------------------------------------------------' |
| 94 | +print "Installing MySQL 8" |
| 95 | +echo '--------------------------------------------------------------------------------' |
| 96 | +yum -y install sudo mysql-community-server |
| 97 | +groupmod -o -g "${JENKINS_GID}" mysql |
| 98 | +usermod -o -g "${JENKINS_GID}" -u "${JENKINS_UID}" mysql |
| 99 | +chown -v mysql:mysql /var/log/mysqld.log |
| 100 | +chown -v -R mysql:mysql /var/lib/mysql-files /var/lib/mysql-keyring /var/run/mysqld |
| 101 | +mysqld --initialize --user=mysql |
| 102 | +echo '--------------------------------------------------------------------------------' |
| 103 | +cat /var/log/mysqld.log |
| 104 | +echo '--------------------------------------------------------------------------------' |
| 105 | + |
| 106 | +print "Setting up MySQL 8 for tests" |
| 107 | +echo '--------------------------------------------------------------------------------' |
| 108 | +#Addtional permanent settings in configuration file |
| 109 | +#To disable check for some stored functions |
| 110 | +echo 'log_bin_trust_function_creators = 1 |
| 111 | +' >> /etc/my.cnf |
| 112 | +/opt/bin/mysql-start.sh |
| 113 | +ROOT_PWD=`cat /var/log/mysqld.log | grep 'A temporary password is generated for root' | sed -e 's/^.*localhost: *//'` |
| 114 | +echo " |
| 115 | + ALTER USER 'root'@'localhost' IDENTIFIED BY '${db.root.pwd}'; |
| 116 | + CREATE DATABASE ${mysql.database}; |
| 117 | + FLUSH PRIVILEGES; |
| 118 | +" | mysql -v -u root --connect-expired-password --password="${ROOT_PWD}" |
| 119 | +if [ '${db.user}' != 'root' ]; then |
| 120 | + echo " |
| 121 | + CREATE USER '${db.user}'@'localhost' IDENTIFIED BY '${db.pwd}'; |
| 122 | + GRANT ALL PRIVILEGES ON ${mysql.database}.* TO '${db.user}'@'localhost'; |
| 123 | + FLUSH PRIVILEGES; |
| 124 | + " | mysql -v -u root --password='${db.root.pwd}' |
| 125 | +fi |
| 126 | +/opt/bin/mysql-stop.sh |
| 127 | +echo '--------------------------------------------------------------------------------' |
| 128 | + |
| 129 | +print "Configuring Mongo DB 3 yum repository" |
| 130 | +echo '--------------------------------------------------------------------------------' |
| 131 | +echo '[Mongodb] |
| 132 | +name=MongoDB Repository |
| 133 | +baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/3.6/x86_64/ |
| 134 | +gpgcheck=0 |
| 135 | +enabled=1 |
| 136 | +gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc |
| 137 | +' > /etc/yum.repos.d/mongodb.repo |
| 138 | +chmod -v u=rw,og=r /etc/yum.repos.d/mongodb.repo |
| 139 | +echo '--------------------------------------------------------------------------------' |
| 140 | +print "Installing Mongo DB 3" |
| 141 | +echo '--------------------------------------------------------------------------------' |
| 142 | +yum install -y mongodb-org |
| 143 | +groupmod -o -g "${JENKINS_GID}" mongod |
| 144 | +usermod -o -g "${JENKINS_GID}" -u "${JENKINS_UID}" mongod |
| 145 | +chown -v -R mongod:mongod /var/lib/mongo /var/log/mongodb /var/run/mongodb |
| 146 | +echo '--------------------------------------------------------------------------------' |
| 147 | +print "Post install cleanup" |
| 148 | +echo '--------------------------------------------------------------------------------' |
| 149 | +yum -y clean all |
| 150 | +rm -vrf /var/cache/yum |
0 commit comments