#!/bin/bash set -e # ansible.builtin.script: # chdir: /root # just in case one runs the script outside ansible [[ `pwd` != /root ]] && echo error: assuming current working directory /root/ && exit 1 [[ ! -x `which dpkg` ]] && echo error: dpkg executable not found && exit 1 [[ ! -x `which wget` ]] && echo error: wget executable not found && exit 1 [[ ! -x `which curl` ]] && echo error: curl executable not found && exit 1 [[ ! -x `which lsb_release` ]] && echo error: lsb_release executable not found && exit 1 # ok=1 changed=0 dpkg -s yandex-unified-agent >/dev/null 2>&1 && echo ok - yandex-unified-agent package is there - nothing to do && exit 0 # in case it was installed from source # ok=1 changed=0 [[ -f /etc/yandex/unified_agent/config.yml ]] && echo ok - /etc/yandex/unified_agent/config.yml is there - nothing to do && exit 0 distro=`lsb_release -cs` # using same correspondance for unified agent as for Ansible itself # https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html#installing-ansible-on-debian # bookworm ==> jammy # bullseye ==> focal # buster ==> bionic # https://yandex.cloud/en/docs/monitoring/concepts/data-collection/unified-agent/installation#deb_1 if [[ $distro = bookworm ]]; then ubuntu_name=ubuntu-22.04-jammy elif [[ $distro = jammy ]]; then ubuntu_name=ubuntu-22.04-jammy elif [[ $distro = bullseye ]]; then ubuntu_name=ubuntu-20.04-focal elif [[ $distro = focal ]]; then ubuntu_name=ubuntu-20.04-focal else echo error: $distro - unknown linux distribution codename exit 1 fi ua_version=`(curl -s https://storage.yandexcloud.net/yc-unified-agent/all-versions; echo) | tail -1` echo latest ua version is $ua_version file=yandex-unified-agent_${ua_version}_amd64.deb if [[ -f $file ]]; then echo $file already there else echo -n download $file ... wget -q "https://storage.yandexcloud.net/yc-unified-agent/releases/$ua_version/deb/$ubuntu_name/$file" && echo done fi [[ ! -f $file ]] && echo error: failed to download package file && exit 1 echo -n install $file ... DEBIAN_FRONTEND=noninteractive dpkg -i $file >/dev/null 2>&1 && echo done # eventually failed=1 echo -n checking for yandex-unified-agent package ... dpkg -s yandex-unified-agent >/dev/null 2>&1 && echo done # clean-up package file rm -f $file || true # handy symlink to remind sysadmin about the agent ln -s /etc/yandex/unified_agent/config.yml 2>/dev/null || true # ok=1 changed=1 echo changed - all done