aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/start.sh
blob: a443d58441d63173f162f52aea563cb9aab7e17c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
###############################
# usage: start.sh [ -p ARG ]
#  -p ARG: name(s) of patch separated by colon (name of patch is filename without extension)
###############################

ROOT=$(pwd)

PATCHES=""
while getopts ":p:" opt; do
  case "$opt" in
    p) PATCHES=$OPTARG
       ;;
    \?)
      echo "Unsupported option $OPTARG" >&2
      exit 1 
      ;;
  esac
done

if [[ "$OSTYPE" == "darwin"* ]]; then
  OS='macosx-universal-64'
else
  OS='linux-x86-64'
fi

if ! ls sonar-application/target/sonarqube-*.zip &> /dev/null; then
  echo 'Sources are not built'
  ./build.sh
fi

cd sonar-application/target/
if ! ls sonarqube-*/bin/$OS/sonar.sh &> /dev/null; then
  echo "Unzipping SQ..."
  unzip -qq sonarqube-*.zip
fi
cd sonarqube-*

# from that point on, strict bash
set -euo pipefail
SQ_HOME=$(pwd)
cd "$ROOT"

source "$ROOT"/scripts/patches_utils.sh

SQ_EXEC=$SQ_HOME/bin/$OS/sonar.sh

"$SQ_EXEC" stop

# invoke patches if at least one was specified
# each patch is passed the path to the SQ instance home directory as first and only argument
if [ "$PATCHES" ]; then
  call_patches "$PATCHES" "$SQ_HOME"
fi

"$SQ_EXEC" start
sleep 1
tail -fn 100 "$SQ_HOME"/logs/sonar.log