From 48bafce6f0e80163a07827529616c248096da4ec Mon Sep 17 00:00:00 2001 From: Matt Cotter Date: Tue, 3 Dec 2024 10:44:06 -0500 Subject: [PATCH] feat: add linux install script for manual installation support --- scripts/install_linux.sh | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 scripts/install_linux.sh diff --git a/scripts/install_linux.sh b/scripts/install_linux.sh new file mode 100644 index 00000000..3b1b42f8 --- /dev/null +++ b/scripts/install_linux.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +set -e + +observeagent_install_dir="/etc/observe-agent" +tmp_dir="/tmp/observe-agent" + +if [ -z "$ZIP_DIR" ]; then + # Download the file from the latest release when there is no zip provided + echo "Downloading latest release from GitHub" + curl -L -o /tmp/observe-agent.tar.gz https://github.com/observeinc/observe-agent/releases/latest/download/observe-agent_Linux_$(arch).tar.gz + ZIP_DIR="/tmp/observe-agent.tar.gz" +else + echo "Installing from provided zip file: $ZIP_DIR" +fi + +# Set up the temp dir and extract files. +rm -rf $tmp_dir +mkdir -p $tmp_dir +tar -xzf $ZIP_DIR -C $tmp_dir + +# If the observe-agent.yaml file already exists, leave it alone. +# Otherwise we need to know what the collection endpoint and token are. +if [ ! -f "$observeagent_install_dir/observe-agent.yaml" ]; then + if [ -z "$OBSERVE_URL" ]; then + echo "OBSERVE_URL env var is not set" + exit 1 + fi + + if [ -z "$TOKEN" ]; then + echo "TOKEN env var is not set" + exit 1 + fi +fi + +# Create the needed directories +echo "Creating system install folders. This may ask for your password..." +sudo mkdir -p $observeagent_install_dir /var/lib/observe-agent/filestorage +sudo chmod +rw /var/lib/observe-agent/filestorage + +# Copy all files to the install dir. +sudo cp -f $tmp_dir/observe-agent /usr/bin/observe-agent +sudo cp -f $tmp_dir/otel-collector.yaml $observeagent_install_dir/otel-collector.yaml +sudo rm -rf $observeagent_install_dir/connections +sudo cp -fR $tmp_dir/connections $observeagent_install_dir/connections +sudo chown -R root:root $observeagent_install_dir + +# Initialize the agent config file if it doesn't exist +if [ -f "$observeagent_install_dir/observe-agent.yaml" ]; then + echo "Leaving existing observe-agent.yaml in place." +else + echo "Initializing observe-agent.yaml" + sudo /usr/bin/observe-agent init-config --token $TOKEN --observe_url $OBSERVE_URL --config_path $observeagent_install_dir/observe-agent.yaml + sudo chown root:root $observeagent_install_dir/observe-agent.yaml +fi + +echo "Observe agent successfully installed to $observeagent_install_dir"