jib.sh revision 1844:ba256c014bff
12061Sjkh#!/bin/bash 250479Speter# 32061Sjkh# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 438666Sjb# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 532427Sjb# 6111131Sru# This code is free software; you can redistribute it and/or modify it 7111131Sru# under the terms of the GNU General Public License version 2 only, as 838666Sjb# published by the Free Software Foundation. 938666Sjb# 1038666Sjb# This code is distributed in the hope that it will be useful, but WITHOUT 1138666Sjb# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1264049Salex# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1364049Salex# version 2 for more details (a copy is included in the LICENSE file that 14116679Ssimokawa# accompanied this code). 1566071Smarkm# 16116679Ssimokawa# You should have received a copy of the GNU General Public License version 1773504Sobrien# 2 along with this work; if not, write to the Free Software Foundation, 1838666Sjb# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1932427Sjb# 2038666Sjb# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21108451Sschweikh# or visit www.oracle.com if you need additional information or have any 2238666Sjb# questions. 2338666Sjb# 2438666Sjb 2538666Sjb# This script installs the JIB tool into it's own local repository and 2617308Speter# puts a wrapper scripts into <source-root>/.jib 2791606Skeramida 2819175Sbdemydir="$(dirname "${BASH_SOURCE[0]}")" 2996205Sjwdmyname="$(basename "${BASH_SOURCE[0]}")" 3096205Sjwd 3138042Sbdeinstalled_jib_script=${mydir}/../../.jib/jib 3296205Sjwdinstall_data=${mydir}/../../.jib/.data 3396205Sjwd 3438042Sbdesetup_url() { 3596205Sjwd if [ -f ~/.config/jib/jib.conf ]; then 3696205Sjwd source ~/.config/jib/jib.conf 3717308Speter fi 3896205Sjwd 3996205Sjwd jib_repository="jdk-virtual" 4017308Speter jib_organization="jpg/infra/builddeps" 4196205Sjwd jib_module="jib" 4296205Sjwd jib_revision="2.0-SNAPSHOT" 4396205Sjwd jib_ext="jib.sh.gz" 4496205Sjwd 4596205Sjwd closed_script="${mydir}/../../closed/conf/jib-install.conf" 4696205Sjwd if [ -f "${closed_script}" ]; then 4796205Sjwd source "${closed_script}" 4896205Sjwd fi 4996205Sjwd 5096205Sjwd if [ -n "${JIB_SERVER}" ]; then 5196205Sjwd jib_server="${JIB_SERVER}" 5296205Sjwd fi 5398775Sdillon if [ -n "${JIB_SERVER_MIRRORS}" ]; then 5498723Sdillon jib_server_mirrors="${JIB_SERVER_MIRRORS}" 5598723Sdillon fi 5698723Sdillon if [ -n "${JIB_REPOSITORY}" ]; then 5798723Sdillon jib_repository="${JIB_REPOSITORY}" 5838666Sjb fi 5938666Sjb if [ -n "${JIB_ORGANIZATION}" ]; then 6017308Speter jib_organization="${JIB_ORGANIZATION}" 61123311Speter fi 62123311Speter if [ -n "${JIB_MODULE}" ]; then 63123311Speter jib_module="${JIB_MODULE}" 64123311Speter fi 6595509Sru if [ -n "${JIB_REVISION}" ]; then 6695793Sru jib_revision="${JIB_REVISION}" 67116679Ssimokawa fi 68120760Sru if [ -n "${JIB_EXTENSION}" ]; then 69116679Ssimokawa jib_extension="${JIB_EXTENSION}" 70123311Speter fi 71123311Speter 72123311Speter if [ -n "${JIB_URL}" ]; then 732061Sjkh jib_url="${JIB_URL}" 7497769Sru data_string="${jib_url}" 7597252Sru else 76119579Sru jib_path="${jib_repository}/${jib_organization}/${jib_module}/${jib_revision}/${jib_module}-${jib_revision}.${jib_ext}" 7797252Sru data_string="${jib_path}" 7895730Sru jib_url="${jib_server}/${jib_path}" 7995793Sru fi 80111617Sru} 8195730Sru 82116679Ssimokawainstall_jib() { 8395730Sru if [ -z "${jib_server}" -a -z "${JIB_URL}" ]; then 84116679Ssimokawa echo "No jib server or URL provided, set either" 8595730Sru echo "JIB_SERVER=<base server address>" 86110035Sru echo "or" 87107516Sru echo "JIB_URL=<full path to install script>" 88110035Sru exit 1 89117234Sru fi 90110035Sru 91117229Sru if command -v curl > /dev/null; then 92117234Sru getcmd="curl -s" 9354324Smarcel elif command -v wget > /dev/null; then 9417308Speter getcmd="wget --quiet -O -" 95119519Smarcel else 96119519Smarcel echo "Could not find either curl or wget" 97119519Smarcel exit 1 98119519Smarcel fi 99119519Smarcel 100119519Smarcel if ! command -v gunzip > /dev/null; then 101119579Sru echo "Could not find gunzip" 102119519Smarcel exit 1 103119519Smarcel fi 104119519Smarcel 105119519Smarcel echo "Downloading JIB bootstrap script" 106119519Smarcel mkdir -p "${installed_jib_script%/*}" 107126031Sgad rm -f "${installed_jib_script}.gz" 108126024Sgad ${getcmd} ${jib_url} > "${installed_jib_script}.gz" 109126024Sgad if [ ! -s "${installed_jib_script}.gz" ]; then 110126024Sgad echo "Failed to download ${jib_url}" 111126024Sgad if [ -n "${jib_path}" -a -n "${jib_server_mirrors}" ]; then 112126024Sgad OLD_IFS="${IFS}" 113126024Sgad IFS=" ," 114126024Sgad for mirror in ${jib_server_mirrors}; do 115126024Sgad echo "Trying mirror ${mirror}" 116126024Sgad jib_url="${mirror}/${jib_path}" 117126024Sgad ${getcmd} ${jib_url} > "${installed_jib_script}.gz" 118126024Sgad if [ -s "${installed_jib_script}.gz" ]; then 119126024Sgad echo "Download from mirror successful" 120126024Sgad break 121126031Sgad else 122126024Sgad echo "Failed to download ${jib_url}" 123126024Sgad fi 124126024Sgad done 125126024Sgad IFS="${OLD_IFS}" 126126024Sgad fi 127126024Sgad if [ ! -s "${installed_jib_script}.gz" ]; then 128126024Sgad exit 1 129126024Sgad fi 130126024Sgad fi 131126024Sgad echo "Extracting JIB bootstrap script" 132126024Sgad rm -f "${installed_jib_script}" 133126024Sgad gunzip "${installed_jib_script}.gz" 134126024Sgad chmod +x "${installed_jib_script}" 135125885Sgad echo "${data_string}" > "${install_data}" 136125885Sgad} 13738666Sjb 13817308Speter# Main body starts here 139119519Smarcel 140119579Srusetup_url 14138666Sjb 142110035Sruif [ ! -x "${installed_jib_script}" ]; then 1432302Spaul install_jib 14439206Sjkhelif [ ! -e "${install_data}" ] || [ "${data_string}" != "$(cat "${install_data}")" ]; then 14539206Sjkh echo "Install url changed since last time, reinstalling" 14639206Sjkh install_jib 147126485Srufi 14873349Sru 149126485Sru${installed_jib_script} "$@" 15017308Speter