#!/bin/bash set -e ES_VERSION="9.1.2" ES_DEB_URL="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}-amd64.deb" ES_RPM_URL="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}-x86_64.rpm" ES_CONFIG_DIR="/etc/elasticsearch" ES_JVM_OPTIONS="/etc/elasticsearch/jvm.options" ES_JVM_OPTIONS_D="/etc/elasticsearch/jvm.options.d" GO_SERVICE_NAME="tixel-watch" GO_INSTALL_TARGET="/opt/tixel/tixel-watch" install_es_deb() { echo "Installing Elasticsearch (Debian package)..." wget "${ES_DEB_URL}" -O elasticsearch.deb sudo dpkg -i elasticsearch.deb sudo apt-get install -f -y } install_es_rpm() { echo "Installing Elasticsearch (RPM package)..." wget "${ES_RPM_URL}" -O elasticsearch.rpm sudo rpm --install elasticsearch.rpm } setup_configuration() { echo "Copying Elasticsearch configuration files..." sudo cp ./configs/elasticsearch.yml "${ES_CONFIG_DIR}/elasticsearch.yml" sudo cp ./configs/jvm.options "${ES_JVM_OPTIONS}" sudo cp -r ./configs/jvm.options.d "${ES_JVM_OPTIONS_D}" sudo chown root:elasticsearch "${ES_CONFIG_DIR}/elasticsearch.yml" "${ES_JVM_OPTIONS}" sudo chmod 640 "${ES_CONFIG_DIR}/elasticsearch.yml" "${ES_JVM_OPTIONS}" } setup_tixel_watch_service() { echo "Setting up tixel-watch systemd service..." if [ ! -d ${GO_INSTALL_TARGET} ]; then mkdir -p ${GO_INSTALL_TARGET} fi sudo cp ./tixel-watch "$GO_INSTALL_TARGET"/ sudo cp ./configs/config.yaml "$GO_INSTALL_TARGET"/ sudo cp ./${GO_SERVICE_NAME}.service /etc/systemd/system/${GO_SERVICE_NAME}.service sudo systemctl daemon-reload sudo systemctl enable "${GO_SERVICE_NAME}" } start_services() { echo "Enabling and starting Elasticsearch service..." sudo systemctl enable elasticsearch sudo systemctl start elasticsearch echo "Starting tixel-watch service..." sudo systemctl start "${GO_SERVICE_NAME}" } main() { if command -v apt-get &>/dev/null; then install_es_deb elif command -v yum &>/dev/null || command -v dnf &>/dev/null; then install_es_rpm else echo "Unsupported package manager. Aborting." exit 1 fi setup_configuration setup_tixel_watch_service start_services echo "All done." } main "$@"