From 8cf5b33e70b5ede02e3c44362af433b5641e146f Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 29 Oct 2014 07:43:26 +0100 Subject: [PATCH] Make the migrate-hosts script work on OS X refs #7398 --- tools/CMakeLists.txt | 4 ++- tools/migrate-hosts | 53 --------------------------- tools/migrate-hosts.cmake | 75 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 54 deletions(-) delete mode 100644 tools/migrate-hosts create mode 100644 tools/migrate-hosts.cmake diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 215ecd2e1..51744a4cb 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -19,8 +19,10 @@ add_subdirectory(mkclass) add_subdirectory(mkembedconfig) add_subdirectory(mkunity) +configure_file(migrate-hosts.cmake ${CMAKE_CURRENT_BINARY_DIR}/migrate-hosts @ONLY) + install( - FILES ${CMAKE_CURRENT_SOURCE_DIR}/migrate-hosts + FILES ${CMAKE_CURRENT_BINARY_DIR}/migrate-hosts DESTINATION ${CMAKE_INSTALL_DATADIR}/icinga2 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE ) diff --git a/tools/migrate-hosts b/tools/migrate-hosts deleted file mode 100644 index d253b7a8a..000000000 --- a/tools/migrate-hosts +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh -# Moves configuration files from /etc/icinga2/conf.d/hosts -# to /etc/icinga2/repository.d - -sysconfdir=`icinga2 variable get --current SysconfDir` - -if [ -z "$sysconfdir" ]; then - echo "Could not determine SysconfDir" - exit 1 -fi - -if [ ! -d $sysconfdir/icinga2/conf.d/hosts ]; then - exit 0 -fi - -mkdir -p $sysconfdir/icinga2/repository.d/hosts - -for hostFile in $sysconfdir/icinga2/conf.d/hosts/*.conf; do - host=`basename $hostFile .conf` - - if [ "x$host" = "xlocalhost" ]; then - target="`hostname --fqdn`" - else - target=$host - fi - - mv $sysconfdir/icinga2/conf.d/hosts/$host.conf $sysconfdir/icinga2/repository.d/hosts/$target.conf - sed -i "s/localhost/$target/g" $sysconfdir/icinga2/repository.d/hosts/$target.conf - - if [ -d $sysconfdir/icinga2/conf.d/hosts/$host ]; then - mv $sysconfdir/icinga2/conf.d/hosts/$host $sysconfdir/icinga2/repository.d/hosts/$target - sed -i "s/localhost/$target/g" $sysconfdir/icinga2/repository.d/hosts/$target/*.conf - fi -done - -cat >$sysconfdir/icinga2/conf.d/hosts/README < $sysconfdir/icinga2/repository.d/hosts/$target.conf.tmp + mv $sysconfdir/icinga2/repository.d/hosts/$target.conf.tmp $sysconfdir/icinga2/repository.d/hosts/$target.conf + else + rm -f $sysconfdir/icinga2/conf.d/hosts/$host.conf + fi + + if [ -d $sysconfdir/icinga2/conf.d/hosts/$host ]; then + service_count=$(($service_count + 1)) + + if [ ! -e $sysconfdir/icinga2/repository.d/hosts/$target ]; then + mv $sysconfdir/icinga2/conf.d/hosts/$host $sysconfdir/icinga2/repository.d/hosts/$target + for file in $sysconfdir/icinga2/repository.d/hosts/$target/*.conf; do + sed "s/localhost/$target/g" $file > $file.tmp + mv $file.tmp $file + done + else + rm -rf $sysconfdir/icinga2/conf.d/hosts/$host + fi + fi +done + +cat >$sysconfdir/icinga2/conf.d/hosts/README <