jib.sh revision 1844:ba256c014bff
1#!/bin/bash 2# 3# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5# 6# This code is free software; you can redistribute it and/or modify it 7# under the terms of the GNU General Public License version 2 only, as 8# published by the Free Software Foundation. 9# 10# This code is distributed in the hope that it will be useful, but WITHOUT 11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13# version 2 for more details (a copy is included in the LICENSE file that 14# accompanied this code). 15# 16# You should have received a copy of the GNU General Public License version 17# 2 along with this work; if not, write to the Free Software Foundation, 18# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19# 20# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21# or visit www.oracle.com if you need additional information or have any 22# questions. 23# 24 25# This script installs the JIB tool into it's own local repository and 26# puts a wrapper scripts into <source-root>/.jib 27 28mydir="$(dirname "${BASH_SOURCE[0]}")" 29myname="$(basename "${BASH_SOURCE[0]}")" 30 31installed_jib_script=${mydir}/../../.jib/jib 32install_data=${mydir}/../../.jib/.data 33 34setup_url() { 35 if [ -f ~/.config/jib/jib.conf ]; then 36 source ~/.config/jib/jib.conf 37 fi 38 39 jib_repository="jdk-virtual" 40 jib_organization="jpg/infra/builddeps" 41 jib_module="jib" 42 jib_revision="2.0-SNAPSHOT" 43 jib_ext="jib.sh.gz" 44 45 closed_script="${mydir}/../../closed/conf/jib-install.conf" 46 if [ -f "${closed_script}" ]; then 47 source "${closed_script}" 48 fi 49 50 if [ -n "${JIB_SERVER}" ]; then 51 jib_server="${JIB_SERVER}" 52 fi 53 if [ -n "${JIB_SERVER_MIRRORS}" ]; then 54 jib_server_mirrors="${JIB_SERVER_MIRRORS}" 55 fi 56 if [ -n "${JIB_REPOSITORY}" ]; then 57 jib_repository="${JIB_REPOSITORY}" 58 fi 59 if [ -n "${JIB_ORGANIZATION}" ]; then 60 jib_organization="${JIB_ORGANIZATION}" 61 fi 62 if [ -n "${JIB_MODULE}" ]; then 63 jib_module="${JIB_MODULE}" 64 fi 65 if [ -n "${JIB_REVISION}" ]; then 66 jib_revision="${JIB_REVISION}" 67 fi 68 if [ -n "${JIB_EXTENSION}" ]; then 69 jib_extension="${JIB_EXTENSION}" 70 fi 71 72 if [ -n "${JIB_URL}" ]; then 73 jib_url="${JIB_URL}" 74 data_string="${jib_url}" 75 else 76 jib_path="${jib_repository}/${jib_organization}/${jib_module}/${jib_revision}/${jib_module}-${jib_revision}.${jib_ext}" 77 data_string="${jib_path}" 78 jib_url="${jib_server}/${jib_path}" 79 fi 80} 81 82install_jib() { 83 if [ -z "${jib_server}" -a -z "${JIB_URL}" ]; then 84 echo "No jib server or URL provided, set either" 85 echo "JIB_SERVER=<base server address>" 86 echo "or" 87 echo "JIB_URL=<full path to install script>" 88 exit 1 89 fi 90 91 if command -v curl > /dev/null; then 92 getcmd="curl -s" 93 elif command -v wget > /dev/null; then 94 getcmd="wget --quiet -O -" 95 else 96 echo "Could not find either curl or wget" 97 exit 1 98 fi 99 100 if ! command -v gunzip > /dev/null; then 101 echo "Could not find gunzip" 102 exit 1 103 fi 104 105 echo "Downloading JIB bootstrap script" 106 mkdir -p "${installed_jib_script%/*}" 107 rm -f "${installed_jib_script}.gz" 108 ${getcmd} ${jib_url} > "${installed_jib_script}.gz" 109 if [ ! -s "${installed_jib_script}.gz" ]; then 110 echo "Failed to download ${jib_url}" 111 if [ -n "${jib_path}" -a -n "${jib_server_mirrors}" ]; then 112 OLD_IFS="${IFS}" 113 IFS=" ," 114 for mirror in ${jib_server_mirrors}; do 115 echo "Trying mirror ${mirror}" 116 jib_url="${mirror}/${jib_path}" 117 ${getcmd} ${jib_url} > "${installed_jib_script}.gz" 118 if [ -s "${installed_jib_script}.gz" ]; then 119 echo "Download from mirror successful" 120 break 121 else 122 echo "Failed to download ${jib_url}" 123 fi 124 done 125 IFS="${OLD_IFS}" 126 fi 127 if [ ! -s "${installed_jib_script}.gz" ]; then 128 exit 1 129 fi 130 fi 131 echo "Extracting JIB bootstrap script" 132 rm -f "${installed_jib_script}" 133 gunzip "${installed_jib_script}.gz" 134 chmod +x "${installed_jib_script}" 135 echo "${data_string}" > "${install_data}" 136} 137 138# Main body starts here 139 140setup_url 141 142if [ ! -x "${installed_jib_script}" ]; then 143 install_jib 144elif [ ! -e "${install_data}" ] || [ "${data_string}" != "$(cat "${install_data}")" ]; then 145 echo "Install url changed since last time, reinstalling" 146 install_jib 147fi 148 149${installed_jib_script} "$@" 150