|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | + |
| 20 | +# stop on error |
| 21 | +set -e |
| 22 | + |
| 23 | +CLOUSEAU_VSN=${CLOUSEAU_VERSION:-2.22.0} |
| 24 | +CLOUSEAU_DIST=https://github.com/cloudant-labs/clouseau/releases/download/"${CLOUSEAU_VSN}"/clouseau-"${CLOUSEAU_VSN}"-dist.zip |
| 25 | + |
| 26 | +# Dependencies: |
| 27 | +# - SLF4J Provider |
| 28 | +SLF4J_VSN=${SLF4J_VERSION:-1.6.1} |
| 29 | +SLF4J_SIMPLE_JAR=https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/"${SLF4J_VSN}"/slf4j-simple-"${SLF4J_VSN}".jar |
| 30 | +# - JDK |
| 31 | +ZULU_VSN=${ZULU_VERSION:-7.56.0.11-ca-jdk7.0.352} |
| 32 | +ZULU_PLATFORM=${ZULU_ARCH:-linux_x64} |
| 33 | +ZULU_DIST=https://static.azul.com/zulu/bin/zulu"${ZULU_VSN}"-"${ZULU_PLATFORM}".tar.gz |
| 34 | + |
| 35 | +SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 36 | + |
| 37 | +# Zulu 7 requires x86_64 |
| 38 | +case "${ARCH}" in |
| 39 | + x86_64) |
| 40 | + ;; |
| 41 | + *) |
| 42 | + echo "Clouseau cannot run on ${ARCH} hence it will not be installed" |
| 43 | + exit 0 |
| 44 | + ;; |
| 45 | +esac |
| 46 | + |
| 47 | +# Check if running as root |
| 48 | +if [[ ${EUID} -ne 0 ]]; then |
| 49 | + echo "Sorry, this script must be run as root." |
| 50 | + echo "Try: sudo $0 $*" |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +function ensure_tool() { |
| 55 | + _tool="$1" |
| 56 | + |
| 57 | + if ! type "${_tool}" > /dev/null 2>&1; then |
| 58 | + echo "Please install `${_tool}`" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | +} |
| 62 | + |
| 63 | +function download() { |
| 64 | + _output="$1" |
| 65 | + _url="$2" |
| 66 | + |
| 67 | + wget -q --max-redirect=1 -O "${_output}" "${_url}" |
| 68 | +} |
| 69 | + |
| 70 | +ensure_tool unzip |
| 71 | +ensure_tool tar |
| 72 | +ensure_tool wget |
| 73 | + |
| 74 | +echo "==> Downloading Clouseau from ${CLOUSEAU_DIST}" |
| 75 | +if ! download /tmp/clouseau.zip "${CLOUSEAU_DIST}"; then |
| 76 | + echo "===> Cannot download Clouseau distribution" |
| 77 | + exit 1 |
| 78 | +fi |
| 79 | +mkdir -p /opt/ |
| 80 | +if ! unzip -qq /tmp/clouseau.zip -d /opt/; then |
| 81 | + echo "===> Cannot unpack Clouseau distribution" |
| 82 | + exit 1 |
| 83 | +fi |
| 84 | +rm -f /tmp/clouseau.zip |
| 85 | + |
| 86 | +echo "==> Downloading Zulu JDK from ${ZULU_DIST}" |
| 87 | +if ! download /tmp/zulu.tar.gz "${ZULU_DIST}"; then |
| 88 | + echo "===> Cannot download Zulu JDK distribution" |
| 89 | + exit 1 |
| 90 | +fi |
| 91 | +mkdir -p /opt/java/ |
| 92 | +if ! tar -xf /tmp/zulu.tar.gz -C /opt/java/; then |
| 93 | + echo "===> Cannot unpack Zulu JDK distribution" |
| 94 | + exit 1 |
| 95 | +fi |
| 96 | +rm -f /tmp/zulu.tar.gz |
| 97 | + |
| 98 | +CLOUSEAU_HOME=/opt/clouseau-"${CLOUSEAU_VSN}" |
| 99 | +JDK_HOME=/opt/java/zulu"${ZULU_VSN}"-"${ZULU_PLATFORM}" |
| 100 | + |
| 101 | +if ! download "${CLOUSEAU_HOME}"/slf4j-simple-"${SLF4J_VSN}".jar "${SLF4J_SIMPLE_JAR}"; then |
| 102 | + echo "Cannot download slf4j-simple" |
| 103 | + exit 1 |
| 104 | +fi |
| 105 | + |
| 106 | +echo "===> Finalizing Clouseau deployment" |
| 107 | +# Extras: |
| 108 | +# - Configuration |
| 109 | +_INI="${CLOUSEAU_HOME}"/clouseau.ini |
| 110 | +cat <<EOF > "${_INI}" |
| 111 | +[clouseau] |
| 112 | +name = clouseau1@127.0.0.1 |
| 113 | +dir = /tmp/clouseau/indexes |
| 114 | +close_if_idle = false |
| 115 | +idle_check_interval_secs = 300 |
| 116 | +EOF |
| 117 | +# - Launcher script |
| 118 | +_JARS=$(find "${CLOUSEAU_HOME}" -type f -name '*.jar' | paste -sd ':') |
| 119 | +_LAUNCHER="${CLOUSEAU_HOME}"/clouseau |
| 120 | +cat <<EOF > "${_LAUNCHER}" |
| 121 | +epmd -daemon |
| 122 | +"${JDK_HOME}/bin/java" \\ |
| 123 | + -cp "${_JARS}" \\ |
| 124 | + com.cloudant.clouseau.Main \\ |
| 125 | + "${_INI}" |
| 126 | +EOF |
| 127 | +chmod +x "${_LAUNCHER}" |
| 128 | + |
| 129 | +echo "===> ALL DONE" |
0 commit comments