blob: dc7f3e990e31e725e35928119fbbcf3fb4ec2f04 [file] [log] [blame]
Yohann Roussele3f18c22016-02-24 16:16:42 +01001#!/bin/bash
2#
3# Copyright (C) 2016 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
Yohann Roussel90c63e62016-11-18 18:12:50 +010017# Version: 1.3-a11
Yohann Roussele3f18c22016-02-24 16:16:42 +010018#
19set -o nounset
20
21#
22# Settings
23#
24JACK_HOME="${JACK_HOME:=$HOME/.jack-server}"
Yohann Roussel90c63e62016-11-18 18:12:50 +010025JACK_CLIENT_SETTING="${JACK_CLIENT_SETTING:=$HOME/.jack-settings}"
Yohann Roussele3f18c22016-02-24 16:16:42 +010026TMPDIR=${TMPDIR:=/tmp}
27
28LAUNCHER_JAR="$JACK_HOME/launcher.jar"
29LAUNCHER_NAME=com.android.jack.launcher.ServerLauncher
30CURRENT_CHARSET=$(locale charmap)
31if [ -z "$CURRENT_CHARSET" ]; then
32 CHARSET_ARGUMENT=
33else
34 CHARSET_ARGUMENT=";charset=$CURRENT_CHARSET"
35fi
36
37JACK_LOGS_DIR="$JACK_HOME"/logs
38JACK_OUT_ERR="$JACK_LOGS_DIR"/outputs.txt
39JACK_CONNECTION_TIMEOUT=300
40
41#
42# Load client settings
43#
Yohann Roussel90c63e62016-11-18 18:12:50 +010044if [ -f "$JACK_CLIENT_SETTING" ]; then
45 source "$JACK_CLIENT_SETTING"
Yohann Roussele3f18c22016-02-24 16:16:42 +010046fi
47
48
49usage () {
50 echo "Usage : $0"
51}
52
53checkCurl() {
54 CURL_COMMAND=$(which curl)
55
56 if [ $? -ne 0 ] ; then
57 echo "curl not found in PATH"
58 return 255
59 fi
60
61 if ! "$CURL_COMMAND" --version >/dev/null 2>&1 ; then
62 echo "Failed to execute '$CURL_COMMAND'"
63 return 255
64 fi
65
66 if "$CURL_COMMAND" --version | grep -q "SecureTransport" ; then
67 echo "'$CURL_COMMAND' unsupported, please use a curl not based on SecureTransport"
68 fi
69
70 if "$CURL_COMMAND" --version | grep -q "OpenSSL/1.0.0" ; then
71 echo "'$CURL_COMMAND' is using a too old SSL library, please update curl and its dependencies"
72 elif curl --version | grep -q "OpenSSL/0." ; then
73 echo "'$CURL_COMMAND' is using a too old SSL library, please update curl and its dependencies"
74 fi
75}
76
77
78checkJava() {
79 JAVA_COMMAND=$(which java)
80
81 if [ $? -ne 0 ] ; then
82 echo "java not found in PATH"
83 return 255
84 fi
85
86 if ! "$JAVA_COMMAND" -version >/dev/null 2>&1 ; then
87 echo "Failed to execute '$JAVA_COMMAND'"
88 return 255
89 fi
90
91
92 JAVA_VERSION=$("$JAVA_COMMAND" -version 2>&1 | head -1 | grep --only-matching -e \"1\\.[0-9]* | cut -c 4-)
93 if [ -z "$JAVA_VERSION" ] ; then
Yohann Roussel90c63e62016-11-18 18:12:50 +010094 echo "'$JAVA_COMMAND': Failed to parse version, please ensure you're running a supported java"
Yohann Roussele3f18c22016-02-24 16:16:42 +010095 return 255
96 fi
97
98 if [ "$JAVA_VERSION" -lt 7 ] ; then
99 echo "'$JAVA_COMMAND' is too old, please update to 1.7 or newer"
100 fi
101}
102
103
104checkKeytool() {
105 KEYTOOL_COMMAND=$(which keytool)
106
107 if [ $? -ne 0 ] ; then
108 echo "keytool not found in PATH"
109 return 255
110 fi
111
112 if ! $KEYTOOL_COMMAND -help >/dev/null 2>&1 ; then
113 echo "failed to execute '$KEYTOOL_COMMAND'"
114 return 255
115 fi
116
117
118 if ! $KEYTOOL_COMMAND -help 2>&1 | grep -q -e "-genkeypair" ; then
119 echo "'$KEYTOOL_COMMAND' unsupported, please ensure PATH allows finding keytool from a supported Java Runtime Environment ie 1.7 or newer"
120 fi
121}
122
123
124#
125# $1: port number
126#
127checkport() {
128 PID_USING_PORT=$(lsof -F p -i TCP:$1 -sTCP:LISTEN | cut -c 2-)
129 if [ -z "$PID_USING_PORT" ] ; then
130 # port is free nothing to check
131 return 0
132 fi
133
134 PS_OUT=$(ps -p $PID_USING_PORT -o "pid uid args" | tail -1)
135 if [ $? -ne 0 ] ; then
136 # process exited before we could get any info, weird but means the port is now available
137 return 0
138 fi
139
140 if ! echo $PS_OUT | grep -q $LAUNCHER_NAME ; then
Yohann Roussel90c63e62016-11-18 18:12:50 +0100141 echo "Port $1 is used by another process (pid=$(echo $PS_OUT | awk '{print $1}')), please ensure to free the port or change port configuration in '$JACK_CLIENT_SETTING' and '$JACK_HOME/config.properties'"
Yohann Roussele3f18c22016-02-24 16:16:42 +0100142 return 255
143 fi
144
145 if [ "$(echo $PS_OUT | awk '{print $2}')" -ne "$(id -u)" ] ; then
Yohann Roussel90c63e62016-11-18 18:12:50 +0100146 echo "Port $1 is used b a Jack server from another user uid=$(echo $PS_OUT | awk '{print $2}'), please change port configuration in '$JACK_CLIENT_SETTING' and '$JACK_HOME/config.properties'"
Yohann Roussele3f18c22016-02-24 16:16:42 +0100147 return 255
148 fi
149}
150
Yohann Roussele3f18c22016-02-24 16:16:42 +0100151
Yohann Roussel2960f692016-09-20 17:33:21 +0200152checkBase64() {
153 BASE64_COMMAND=$(which base64)
Yohann Roussele3f18c22016-02-24 16:16:42 +0100154
Yohann Roussel2960f692016-09-20 17:33:21 +0200155 if [ $? -ne 0 ] ; then
156 echo "base64 not found in PATH"
157 return 255
158 fi
Yohann Roussele3f18c22016-02-24 16:16:42 +0100159
Yohann Roussel2960f692016-09-20 17:33:21 +0200160 BASE64_CHECK=$((echo amFjaw==;echo LXNlcnZlcg==) | "$BASE64_COMMAND" --decode 2>&1)
161 if [ "$BASE64_CHECK" != jack-server ]; then
162 echo "'$BASE64_COMMAND' is not a supported version"
163 return 255
164 fi
165}
Yohann Roussele3f18c22016-02-24 16:16:42 +0100166
Yohann Roussel2960f692016-09-20 17:33:21 +0200167STATUS=0
168
169if ! checkCurl ; then
170 STATUS=1
171fi
172
173if ! checkJava ; then
174 STATUS=1
175fi
176if ! checkKeytool ; then
177 STATUS=1
178fi
179
180if ! checkport $SERVER_PORT_ADMIN ; then
181 STATUS=1
182fi
183if ! checkport $SERVER_PORT_SERVICE ; then
184 STATUS=1
185fi
186
187if ! checkBase64 ; then
188 echo "base64 is not mandatory but installing a supported version can help with standard output and standard error problems"
189fi
190
191if [ $STATUS -eq 0 ] ; then
192 echo "Diagnostic completed without error."
193fi
Yohann Roussele3f18c22016-02-24 16:16:42 +0100194# Exit
Yohann Roussel2960f692016-09-20 17:33:21 +0200195exit $STATUS