#!/bin/sh ICINGA2PKIDIR=@CMAKE_INSTALL_FULL_DATADIR@/icinga2/pki ICINGA2CONFIG=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2 name=`hostname --fqdn` echo "Agent name: $name" if [ -n "$1" ]; then if [ ! -e $ICINGA2CONFIG/pki/$name.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 if ! base64 -d $1 >/dev/null 2>&1; then echo "The bundle file is invalid or corrupted." 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 "Master 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 listener_port="" while true; do echo -n "Which TCP port should the agent listen on? [5665] " if ! read listener_port; then exit 1 fi break done if [ -z "$listener_port" ]; then listener_port=5665 fi upstream_connect=n if [ "$master" = "n" ]; then while true; do echo -n "Do you want this agent instance to connect to the master 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 echo -n "Master instance IP address/hostname [$upstream_name]: " if ! read upstream_host; then exit 1 fi if [ -z "$upstream_host" ]; then upstream_host=$upstream_name fi echo -n "Master instance port [5665]: " if ! read upstream_port; then exit 1 fi if [ -z "$upstream_port" ]; then upstream_port=5665 fi fi fi echo "Installing the certificate bundle..." base64 -d < $1 | tar -C $ICINGA2CONFIG/pki/ -zx || exit 1 chown @ICINGA2_USER@:@ICINGA2_GROUP@ $ICINGA2CONFIG/pki/* || exit 1 echo "Setting up api.conf..." cat >$ICINGA2CONFIG/features-available/api.conf <$ICINGA2CONFIG/zones.conf <>$ICINGA2CONFIG/zones.conf <>$ICINGA2CONFIG/zones.conf <>$ICINGA2CONFIG/zones.conf <." exit 0