Yohann Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 1 | #!/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 Roussel | 90c63e6 | 2016-11-18 18:12:50 +0100 | [diff] [blame] | 17 | # Version: 1.3-a11 |
Yohann Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 18 | # |
| 19 | set -o nounset |
| 20 | |
| 21 | # |
| 22 | # Settings |
| 23 | # |
| 24 | JACK_HOME="${JACK_HOME:=$HOME/.jack-server}" |
Yohann Roussel | 90c63e6 | 2016-11-18 18:12:50 +0100 | [diff] [blame] | 25 | JACK_CLIENT_SETTING="${JACK_CLIENT_SETTING:=$HOME/.jack-settings}" |
Yohann Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 26 | TMPDIR=${TMPDIR:=/tmp} |
| 27 | |
| 28 | LAUNCHER_JAR="$JACK_HOME/launcher.jar" |
| 29 | LAUNCHER_NAME=com.android.jack.launcher.ServerLauncher |
| 30 | CURRENT_CHARSET=$(locale charmap) |
| 31 | if [ -z "$CURRENT_CHARSET" ]; then |
| 32 | CHARSET_ARGUMENT= |
| 33 | else |
| 34 | CHARSET_ARGUMENT=";charset=$CURRENT_CHARSET" |
| 35 | fi |
| 36 | |
| 37 | JACK_LOGS_DIR="$JACK_HOME"/logs |
| 38 | JACK_OUT_ERR="$JACK_LOGS_DIR"/outputs.txt |
| 39 | JACK_CONNECTION_TIMEOUT=300 |
| 40 | |
| 41 | # |
| 42 | # Load client settings |
| 43 | # |
Yohann Roussel | 90c63e6 | 2016-11-18 18:12:50 +0100 | [diff] [blame] | 44 | if [ -f "$JACK_CLIENT_SETTING" ]; then |
| 45 | source "$JACK_CLIENT_SETTING" |
Yohann Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 46 | fi |
| 47 | |
| 48 | |
| 49 | usage () { |
| 50 | echo "Usage : $0" |
| 51 | } |
| 52 | |
| 53 | checkCurl() { |
| 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 | |
| 78 | checkJava() { |
| 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 Roussel | 90c63e6 | 2016-11-18 18:12:50 +0100 | [diff] [blame] | 94 | echo "'$JAVA_COMMAND': Failed to parse version, please ensure you're running a supported java" |
Yohann Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 95 | 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 | |
| 104 | checkKeytool() { |
| 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 | # |
| 127 | checkport() { |
| 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 Roussel | 90c63e6 | 2016-11-18 18:12:50 +0100 | [diff] [blame] | 141 | 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 Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 142 | return 255 |
| 143 | fi |
| 144 | |
| 145 | if [ "$(echo $PS_OUT | awk '{print $2}')" -ne "$(id -u)" ] ; then |
Yohann Roussel | 90c63e6 | 2016-11-18 18:12:50 +0100 | [diff] [blame] | 146 | 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 Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 147 | return 255 |
| 148 | fi |
| 149 | } |
| 150 | |
Yohann Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 151 | |
Yohann Roussel | 2960f69 | 2016-09-20 17:33:21 +0200 | [diff] [blame] | 152 | checkBase64() { |
| 153 | BASE64_COMMAND=$(which base64) |
Yohann Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 154 | |
Yohann Roussel | 2960f69 | 2016-09-20 17:33:21 +0200 | [diff] [blame] | 155 | if [ $? -ne 0 ] ; then |
| 156 | echo "base64 not found in PATH" |
| 157 | return 255 |
| 158 | fi |
Yohann Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 159 | |
Yohann Roussel | 2960f69 | 2016-09-20 17:33:21 +0200 | [diff] [blame] | 160 | 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 Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 166 | |
Yohann Roussel | 2960f69 | 2016-09-20 17:33:21 +0200 | [diff] [blame] | 167 | STATUS=0 |
| 168 | |
| 169 | if ! checkCurl ; then |
| 170 | STATUS=1 |
| 171 | fi |
| 172 | |
| 173 | if ! checkJava ; then |
| 174 | STATUS=1 |
| 175 | fi |
| 176 | if ! checkKeytool ; then |
| 177 | STATUS=1 |
| 178 | fi |
| 179 | |
| 180 | if ! checkport $SERVER_PORT_ADMIN ; then |
| 181 | STATUS=1 |
| 182 | fi |
| 183 | if ! checkport $SERVER_PORT_SERVICE ; then |
| 184 | STATUS=1 |
| 185 | fi |
| 186 | |
| 187 | if ! checkBase64 ; then |
| 188 | echo "base64 is not mandatory but installing a supported version can help with standard output and standard error problems" |
| 189 | fi |
| 190 | |
| 191 | if [ $STATUS -eq 0 ] ; then |
| 192 | echo "Diagnostic completed without error." |
| 193 | fi |
Yohann Roussel | e3f18c2 | 2016-02-24 16:16:42 +0100 | [diff] [blame] | 194 | # Exit |
Yohann Roussel | 2960f69 | 2016-09-20 17:33:21 +0200 | [diff] [blame] | 195 | exit $STATUS |