#!/usr/bin/env bash # Script to install fluent-bit on ubuntu based off of instructions from # https://docs.fluentbit.io/manual/installation/linux/ubuntu # The binary is td-agent-bit and will be in /opt/td-agent-bit/bin/ # https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html set -o errexit # exit script if a command fails set -o nounset # exit script if a varialbe is undeclared set -o pipefail # do not hide errors within pipes [[ $(id -u) -ne 0 ]] && echo "This script must run as root" && exit 1 os_type_error="Error: This script is only supported on ubuntu focal, bionic or xenial" fb_url="https://packages.fluentbit.io" fb_bin="td-agent-bit" fb_dir="/etc/td-agent-bit" fb_config="./td-agent-bit.conf" fb_parsers="./parsers.conf" fb_secret="./creds.json" if [[ ! -f "${fb_config}" || ! -f "${fb_parsers}" || ! -f "${fb_secret}" ]]; then echo "required files are missing: ${fb_config} ${fb_parsers} ${fb_secret}" exit 1 fi # source the env variables which tells us which version of ubnutu we're on(focal/bionic/xenial) if [[ -r /etc/os-release ]]; then # shellcheck disable=SC1091 . /etc/os-release case "${UBUNTU_CODENAME}" in "focal" | "bionic" | "xenial") ;; *) echo "${os_type_error}. Found version ${UBUNTU_CODENAME}" exit 1 ;; esac else echo "${os_type_error}" exit 1 fi # add the fluentbit gpg key so we can apt-get the signed td-agent-bit package if ! wget -qO - "${fb_url}"/fluentbit.key | apt-key add - ; then echo "There was a problem adding fluentbit.key" exit 1 fi sources_file="/etc/apt/sources.list" sources_string="deb ${fb_url}/ubuntu/${UBUNTU_CODENAME} ${UBUNTU_CODENAME} main" echo "checking ${sources_file} for ${sources_string}" if ! grep -q "${sources_string}" "${sources_file}"; then echo "Updating ${sources_file} with ${sources_string}" echo "${sources_string}" >> "${sources_file}" fi apt-get update -y echo "checking if we can download ${fb_bin} from ${fb_url}" apt-get -qq --dry-run install "${fb_bin}" # an apt-get error here could indicate an expired root certificate # https://docs.fluentbit.io/manual/installation/linux/ubuntu#certificate-issue if [ $? == 100 ]; then apt-get install ca-certificates -y fi echo "installing ${fb_bin}" apt-get install "${fb_bin}" -y echo "copying fluent-bit configs to ${fb_dir}" cp "${fb_config}" "${fb_parsers}" "${fb_secret}" "${fb_dir}" echo "staring the ${fb_bin} service" service "${fb_bin}" start service "${fb_bin}" status