From: Gunnar Beutner Date: Sat, 12 Apr 2014 23:59:25 +0000 (+0200) Subject: Make the agent setup scripts more user-friendly. X-Git-Tag: v0.0.10~111 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4932df11712a2c28bebb9956006f8ce27fc107cb;p=icinga2 Make the agent setup scripts more user-friendly. Refs #4865 --- diff --git a/pki/icinga2-setup-agent.cmake b/pki/icinga2-setup-agent.cmake index 50c8dfab4..b92a04ef4 100644 --- a/pki/icinga2-setup-agent.cmake +++ b/pki/icinga2-setup-agent.cmake @@ -15,18 +15,120 @@ if [ -n "$1" ]; then fi while true; do - echo -n "Upstream Icinga instance name: " - if ! read UPSTREAM; then + echo -n "Are you setting up a new master instance? [n] " + if ! read master; then exit 1 fi - if [ -n "$UPSTREAM" ]; then + 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/ -xf "$1" + tar -C $ICINGA2CONFIG/pki/agent/ -zxf "$1" || exit 1 chown @ICINGA2_USER@:@ICINGA2_GROUP@ $ICINGA2CONFIG/pki/agent/* || exit 1 echo "Setting up agent configuration..." @@ -41,10 +143,31 @@ object AgentListener "agent" { cert_path = SysconfDir + "/icinga2/pki/agent/agent.crt" key_path = SysconfDir + "/icinga2/pki/agent/agent.key" ca_path = SysconfDir + "/icinga2/pki/agent/ca.crt" +AGENT + + if [ "$master" = "n" ]; then + cat >>$ICINGA2CONFIG/features-available/agent.conf <>$ICINGA2CONFIG/features-available/agent.conf <>$ICINGA2CONFIG/features-available/agent.conf <>$ICINGA2CONFIG/features-available/agent.conf < $ICINGA_CA/$pubkfile.crt && \ - rm -f $ICINGA_CA/$csrfile.tmp +openssl x509 -days "$REQ_DAYS" -CA $ICINGA_CA/ca.crt -CAkey $ICINGA_CA/ca.key -req -in $ICINGA_CA/$csrfile -outform PEM -out $ICINGA_CA/$pubkfile.crt -CAserial $ICINGA_CA/serial # Make an agent bundle file mkdir -p $ICINGA_CA/agent cp $ICINGA_CA/$pubkfile.crt $ICINGA_CA/agent/agent.crt cp $ICINGA_CA/ca.crt $ICINGA_CA/agent/ca.crt -tar cf $ICINGA_CA/$pubkfile.bundle -C $ICINGA_CA/agent/ ca.crt agent.crt +tar cz -C $ICINGA_CA/agent/ ca.crt agent.crt | base64 > $ICINGA_CA/$pubkfile.bundle rm -rf $ICINGA_CA/agent echo "Done. $pubkfile.crt and $pubkfile.bundle files were written."