2015-12-11 16:18:08 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2022-10-17 09:28:23 +00:00
|
|
|
# Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
|
2015-12-11 16:18:08 +00:00
|
|
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
#
|
|
|
|
# This code is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License version 2 only, as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
# version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
# accompanied this code).
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License version
|
|
|
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
# or visit www.oracle.com if you need additional information or have any
|
|
|
|
# questions.
|
|
|
|
#
|
|
|
|
|
|
|
|
# This script installs the JIB tool into it's own local repository and
|
|
|
|
# puts a wrapper scripts into <source-root>/.jib
|
|
|
|
|
|
|
|
mydir="$(dirname "${BASH_SOURCE[0]}")"
|
|
|
|
myname="$(basename "${BASH_SOURCE[0]}")"
|
|
|
|
|
2017-09-29 13:26:13 +00:00
|
|
|
installed_jib_script=${mydir}/../.jib/jib
|
|
|
|
install_data=${mydir}/../.jib/.data
|
2015-12-11 16:18:08 +00:00
|
|
|
|
|
|
|
setup_url() {
|
2015-12-23 09:00:37 +00:00
|
|
|
if [ -f ~/.config/jib/jib.conf ]; then
|
2015-12-11 16:18:08 +00:00
|
|
|
source ~/.config/jib/jib.conf
|
|
|
|
fi
|
|
|
|
|
|
|
|
jib_repository="jdk-virtual"
|
|
|
|
jib_organization="jpg/infra/builddeps"
|
|
|
|
jib_module="jib"
|
2017-10-10 13:20:10 +00:00
|
|
|
jib_revision="3.0-SNAPSHOT"
|
2015-12-11 16:18:08 +00:00
|
|
|
jib_ext="jib.sh.gz"
|
|
|
|
|
2017-09-29 13:26:13 +00:00
|
|
|
closed_script="${mydir}/../../closed/make/conf/jib-install.conf"
|
2015-12-11 16:18:08 +00:00
|
|
|
if [ -f "${closed_script}" ]; then
|
|
|
|
source "${closed_script}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${JIB_SERVER}" ]; then
|
|
|
|
jib_server="${JIB_SERVER}"
|
|
|
|
fi
|
2015-12-23 09:00:37 +00:00
|
|
|
if [ -n "${JIB_SERVER_MIRRORS}" ]; then
|
|
|
|
jib_server_mirrors="${JIB_SERVER_MIRRORS}"
|
|
|
|
fi
|
2015-12-11 16:18:08 +00:00
|
|
|
if [ -n "${JIB_REPOSITORY}" ]; then
|
|
|
|
jib_repository="${JIB_REPOSITORY}"
|
|
|
|
fi
|
|
|
|
if [ -n "${JIB_ORGANIZATION}" ]; then
|
|
|
|
jib_organization="${JIB_ORGANIZATION}"
|
|
|
|
fi
|
|
|
|
if [ -n "${JIB_MODULE}" ]; then
|
|
|
|
jib_module="${JIB_MODULE}"
|
|
|
|
fi
|
|
|
|
if [ -n "${JIB_REVISION}" ]; then
|
|
|
|
jib_revision="${JIB_REVISION}"
|
|
|
|
fi
|
|
|
|
if [ -n "${JIB_EXTENSION}" ]; then
|
|
|
|
jib_extension="${JIB_EXTENSION}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${JIB_URL}" ]; then
|
|
|
|
jib_url="${JIB_URL}"
|
|
|
|
data_string="${jib_url}"
|
|
|
|
else
|
2015-12-23 09:00:37 +00:00
|
|
|
jib_path="${jib_repository}/${jib_organization}/${jib_module}/${jib_revision}/${jib_module}-${jib_revision}.${jib_ext}"
|
|
|
|
data_string="${jib_path}"
|
|
|
|
jib_url="${jib_server}/${jib_path}"
|
2015-12-11 16:18:08 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
install_jib() {
|
|
|
|
if [ -z "${jib_server}" -a -z "${JIB_URL}" ]; then
|
|
|
|
echo "No jib server or URL provided, set either"
|
|
|
|
echo "JIB_SERVER=<base server address>"
|
|
|
|
echo "or"
|
|
|
|
echo "JIB_URL=<full path to install script>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if command -v curl > /dev/null; then
|
2016-05-11 11:42:31 +00:00
|
|
|
getcmd="curl -s -L --retry 3 --retry-delay 5"
|
2015-12-11 16:18:08 +00:00
|
|
|
elif command -v wget > /dev/null; then
|
|
|
|
getcmd="wget --quiet -O -"
|
|
|
|
else
|
|
|
|
echo "Could not find either curl or wget"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! command -v gunzip > /dev/null; then
|
|
|
|
echo "Could not find gunzip"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Downloading JIB bootstrap script"
|
|
|
|
mkdir -p "${installed_jib_script%/*}"
|
|
|
|
rm -f "${installed_jib_script}.gz"
|
|
|
|
${getcmd} ${jib_url} > "${installed_jib_script}.gz"
|
|
|
|
if [ ! -s "${installed_jib_script}.gz" ]; then
|
|
|
|
echo "Failed to download ${jib_url}"
|
2015-12-23 09:00:37 +00:00
|
|
|
if [ -n "${jib_path}" -a -n "${jib_server_mirrors}" ]; then
|
|
|
|
OLD_IFS="${IFS}"
|
|
|
|
IFS=" ,"
|
|
|
|
for mirror in ${jib_server_mirrors}; do
|
|
|
|
echo "Trying mirror ${mirror}"
|
|
|
|
jib_url="${mirror}/${jib_path}"
|
|
|
|
${getcmd} ${jib_url} > "${installed_jib_script}.gz"
|
|
|
|
if [ -s "${installed_jib_script}.gz" ]; then
|
|
|
|
echo "Download from mirror successful"
|
|
|
|
break
|
|
|
|
else
|
|
|
|
echo "Failed to download ${jib_url}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
IFS="${OLD_IFS}"
|
|
|
|
fi
|
|
|
|
if [ ! -s "${installed_jib_script}.gz" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-12-11 16:18:08 +00:00
|
|
|
fi
|
2022-11-23 14:26:45 +00:00
|
|
|
# Want to check the filetype using file, to see if we got served a HTML error page.
|
|
|
|
# This is sensitive to the filename containing a specific string, but good enough.
|
2023-03-22 14:58:34 +00:00
|
|
|
file "${installed_jib_script}.gz" | grep "gzip compressed data" > /dev/null
|
2022-11-23 14:26:45 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Warning: ${installed_jib_script}.gz is not a gzip file."
|
|
|
|
echo "If you are behind a proxy you may need to configure exceptions using no_proxy."
|
|
|
|
echo "The download URL was: ${jib_url}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-12-11 16:18:08 +00:00
|
|
|
echo "Extracting JIB bootstrap script"
|
|
|
|
rm -f "${installed_jib_script}"
|
|
|
|
gunzip "${installed_jib_script}.gz"
|
|
|
|
chmod +x "${installed_jib_script}"
|
|
|
|
echo "${data_string}" > "${install_data}"
|
|
|
|
}
|
|
|
|
|
2022-10-17 09:28:23 +00:00
|
|
|
# Returns a shell-escaped version of the argument given.
|
|
|
|
shell_quote() {
|
|
|
|
if [[ -n "$1" ]]; then
|
|
|
|
# Uses only shell-safe characters? No quoting needed.
|
|
|
|
# '=' is a zsh meta-character, but only in word-initial position.
|
|
|
|
if echo "$1" | grep '^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\.:,%/+=_-]\{1,\}$' > /dev/null \
|
|
|
|
&& ! echo "$1" | grep '^=' > /dev/null; then
|
|
|
|
quoted="$1"
|
|
|
|
else
|
|
|
|
if echo "$1" | grep "[\'!]" > /dev/null; then
|
|
|
|
# csh does history expansion within single quotes, but not
|
|
|
|
# when backslash-escaped!
|
|
|
|
local quoted_quote="'\\''" quoted_exclam="'\\!'"
|
|
|
|
word="${1//\'/${quoted_quote}}"
|
|
|
|
word="${1//\!/${quoted_exclam}}"
|
|
|
|
fi
|
|
|
|
quoted="'$1'"
|
|
|
|
fi
|
|
|
|
echo "$quoted"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-12-11 16:18:08 +00:00
|
|
|
# Main body starts here
|
|
|
|
|
|
|
|
setup_url
|
|
|
|
|
|
|
|
if [ ! -x "${installed_jib_script}" ]; then
|
|
|
|
install_jib
|
|
|
|
elif [ ! -e "${install_data}" ] || [ "${data_string}" != "$(cat "${install_data}")" ]; then
|
|
|
|
echo "Install url changed since last time, reinstalling"
|
|
|
|
install_jib
|
|
|
|
fi
|
|
|
|
|
2017-10-10 13:20:10 +00:00
|
|
|
# Provide a reasonable default for the --src-dir parameter if run out of tree
|
|
|
|
if [ -z "${JIB_SRC_DIR}" ]; then
|
|
|
|
export JIB_SRC_DIR="${mydir}/../"
|
|
|
|
fi
|
|
|
|
|
2022-10-17 09:28:23 +00:00
|
|
|
|
|
|
|
# Save the original command line
|
|
|
|
conf_quoted_arguments=()
|
|
|
|
for conf_option; do
|
|
|
|
conf_quoted_arguments=("${conf_quoted_arguments[@]}" "$(shell_quote "$conf_option")")
|
|
|
|
done
|
|
|
|
export REAL_CONFIGURE_COMMAND_LINE="${conf_quoted_arguments[@]}"
|
|
|
|
|
|
|
|
myfulldir="$(cd "${mydir}" > /dev/null && pwd)"
|
|
|
|
export REAL_CONFIGURE_COMMAND_EXEC_FULL="$BASH $myfulldir/$myname"
|
|
|
|
export REAL_CONFIGURE_COMMAND_EXEC_SHORT="$myname"
|
|
|
|
|
2015-12-11 16:18:08 +00:00
|
|
|
${installed_jib_script} "$@"
|