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 JAB tool into it's own local repository and |
|
26 # puts a wrapper scripts into <source-root>/.jab |
|
27 |
|
28 mydir="$(dirname "${BASH_SOURCE[0]}")" |
|
29 myname="$(basename "${BASH_SOURCE[0]}")" |
|
30 |
|
31 installed_jab_script=${mydir}/../../.jab/jab |
|
32 install_data=${mydir}/../../.jab/.data |
|
33 |
|
34 setup_url() { |
|
35 if [ -f "~/.config/jab/jab.conf" ]; then |
|
36 source ~/.config/jab/jab.conf |
|
37 fi |
|
38 |
|
39 jab_repository="jdk-virtual" |
|
40 jab_organization="jpg/infra/builddeps" |
|
41 jab_module="jab" |
|
42 jab_revision="2.0-SNAPSHOT" |
|
43 jab_ext="jab.sh.gz" |
|
44 |
|
45 closed_script="${mydir}/../../closed/conf/jab-install.conf" |
|
46 if [ -f "${closed_script}" ]; then |
|
47 source "${closed_script}" |
|
48 fi |
|
49 |
|
50 if [ -n "${JAB_SERVER}" ]; then |
|
51 jab_server="${JAB_SERVER}" |
|
52 fi |
|
53 if [ -n "${JAB_REPOSITORY}" ]; then |
|
54 jab_repository="${JAB_REPOSITORY}" |
|
55 fi |
|
56 if [ -n "${JAB_ORGANIZATION}" ]; then |
|
57 jab_organization="${JAB_ORGANIZATION}" |
|
58 fi |
|
59 if [ -n "${JAB_MODULE}" ]; then |
|
60 jab_module="${JAB_MODULE}" |
|
61 fi |
|
62 if [ -n "${JAB_REVISION}" ]; then |
|
63 jab_revision="${JAB_REVISION}" |
|
64 fi |
|
65 if [ -n "${JAB_EXTENSION}" ]; then |
|
66 jab_extension="${JAB_EXTENSION}" |
|
67 fi |
|
68 |
|
69 if [ -n "${JAB_URL}" ]; then |
|
70 jab_url="${JAB_URL}" |
|
71 data_string="${jab_url}" |
|
72 else |
|
73 data_string="${jab_repository}/${jab_organization}/${jab_module}/${jab_revision}/${jab_module}-${jab_revision}.${jab_ext}" |
|
74 jab_url="${jab_server}/${data_string}" |
|
75 fi |
|
76 } |
|
77 |
|
78 install_jab() { |
|
79 if [ -z "${jab_server}" -a -z "${JAB_URL}" ]; then |
|
80 echo "No jab server or URL provided, set either" |
|
81 echo "JAB_SERVER=<base server address>" |
|
82 echo "or" |
|
83 echo "JAB_URL=<full path to install script>" |
|
84 exit 1 |
|
85 fi |
|
86 |
|
87 if command -v curl > /dev/null; then |
|
88 getcmd="curl -s" |
|
89 elif command -v wget > /dev/null; then |
|
90 getcmd="wget --quiet -O -" |
|
91 else |
|
92 echo "Could not find either curl or wget" |
|
93 exit 1 |
|
94 fi |
|
95 |
|
96 if ! command -v gunzip > /dev/null; then |
|
97 echo "Could not find gunzip" |
|
98 exit 1 |
|
99 fi |
|
100 |
|
101 echo "Downloading JAB bootstrap script" |
|
102 mkdir -p "${installed_jab_script%/*}" |
|
103 rm -f "${installed_jab_script}.gz" |
|
104 ${getcmd} ${jab_url} > "${installed_jab_script}.gz" |
|
105 if [ ! -s "${installed_jab_script}.gz" ]; then |
|
106 echo "Failed to download ${jab_url}" |
|
107 exit 1 |
|
108 fi |
|
109 echo "Extracting JAB bootstrap script" |
|
110 rm -f "${installed_jab_script}" |
|
111 gunzip "${installed_jab_script}.gz" |
|
112 chmod +x "${installed_jab_script}" |
|
113 echo "${data_string}" > "${install_data}" |
|
114 } |
|
115 |
|
116 # Main body starts here |
|
117 |
|
118 setup_url |
|
119 |
|
120 if [ ! -x "${installed_jab_script}" ]; then |
|
121 install_jab |
|
122 elif [ ! -e "${install_data}" ] || [ "${data_string}" != "$(cat "${install_data}")" ]; then |
|
123 echo "Install url changed since last time, reinstalling" |
|
124 install_jab |
|
125 fi |
|
126 |
|
127 ${installed_jab_script} "$@" |
|