#!/bin/bash ICINGA2PKIDIR=@CMAKE_INSTALL_FULL_DATADIR@/icinga2/pki ICINGA2CONFIG=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2 if [ -n "$1" ]; then if [ ! -e $ICINGA2CONFIG/pki/agent/agent.key ]; then echo "You haven't generated a private key for this Icinga 2 instance" echo "yet. Please run this script without any parameters to generate a key." exit 1 fi if [ ! -e "$1" ]; then echo "The specified key bundle does not exist." exit 1 fi while true; do echo -n "Are you setting up a new master instance? [n] " if ! read master; then exit 1 fi if [ "$master" = "y" -o "$master" = "n" -o -z "$master" ]; then break fi echo "Please enter 'y' or 'n'." done if [ -z "$master" ]; then master=n fi upstream_name="" if [ "$master" = "n" ]; then while true; do echo -n "Upstream Icinga instance name: " if ! read upstream_name; then exit 1 fi if [ -n "$upstream_name" ]; then break fi echo "Please enter an instance name." done fi while true; do echo -n "Do you want this agent instance to listen on a TCP port? [y] " if ! read listener; then exit 1 fi if [ "$listener" = "y" -o "$listener" = "n" -o -z "$listener" ]; then break fi echo "Please enter 'y' or 'n'." done if [ -z "$listener" ]; then listener=y fi listener_port="" if [ "$listener" = "y" ]; then while true; do echo -n "Which TCP port should the agent listen on? [8483] " if ! read listener_port; then exit 1 fi break done if [ -z "$listener_port" ]; then listener_port=8483 fi fi while true; do echo -n "Do you want this agent instance to connect to the upstream instance? [y] " if ! read upstream_connect; then exit 1 fi if [ "$upstream_connect" = "y" -o "$upstream_connect" = "n" -o -z "$upstream_connect" ]; then break fi echo "Please enter 'y' or 'n'." done if [ -z "$upstream_connect" ]; then upstream_connect=y fi if [ "$upstream_connect" = "y" ]; then while true; do echo -n "Upstream IP address/hostname: " if ! read upstream_host; then exit 1 fi if [ -n "$upstream_host" ]; then break fi echo "Please enter the upstream instance's hostname." done while true; do echo -n "Upstream port: " if ! read upstream_port; then exit 1 fi if [ -n "$upstream_port" ]; then break fi echo "Please enter the upstream instance's port." done fi echo "Installing the certificate bundle..." tar -C $ICINGA2CONFIG/pki/agent/ -zxf "$1" || exit 1 chown @ICINGA2_USER@:@ICINGA2_GROUP@ $ICINGA2CONFIG/pki/agent/* || exit 1 echo "Setting up agent configuration..." cat >$ICINGA2CONFIG/features-available/agent.conf <>$ICINGA2CONFIG/features-available/agent.conf <>$ICINGA2CONFIG/features-available/agent.conf <>$ICINGA2CONFIG/features-available/agent.conf <>$ICINGA2CONFIG/features-available/agent.conf <." exit 0