#!/usr/bin/env bash

set -eu

PMM_DIR="/usr/local/percona/pmm-client"
QAN_DIR="/usr/local/percona/qan-agent"

if [ $(id -u) -ne 0 ]; then
    echo "The script requires superuser privileges."
    exit 1
fi

mkdir -p $PMM_DIR $QAN_DIR/bin $PMM_DIR/textfile_collector

# delete old symlink
rm -f /usr/sbin/pmm-admin

cp -f bin/pmm-admin /usr/sbin/
cp -f bin/node_exporter $PMM_DIR/
cp -f bin/mysqld_exporter $PMM_DIR/
cp -f bin/postgres_exporter $PMM_DIR/
cp -f bin/mongodb_exporter $PMM_DIR/
cp -f bin/proxysql_exporter $PMM_DIR/
cp -f bin/percona-qan-agent $QAN_DIR/bin/
cp -f bin/percona-qan-agent-installer $QAN_DIR/bin/
cp -f bin/pt-summary $QAN_DIR/bin/
cp -f bin/pt-mongodb-summary $QAN_DIR/bin/
cp -f bin/pt-mysql-summary $QAN_DIR/bin/
install -m 0644 queries-mysqld.yml $PMM_DIR/
install -m 0755 example.prom $PMM_DIR/textfile_collector/
