#!/bin/bash

set -xe

# Copy the old MCollective configuration to the location of the
# MCollective configuration file in the ruby193 SCL.
command mv -f /etc/openshift/upgrade/2/server.cfg /opt/rh/ruby193/root/etc/mcollective/server.cfg

# Delete any old facts (it is autogenerated).
command rm -f /etc/mcollective/facts.yaml.rpmsave

# RHOSE 1.2 should have already libdir pointing to ruby193 SCL for the
# OpenShift agent.
#
# For RHOSE 2.0, we need to make the following changes:
#
#  * Update the name of the log file.
#
#  * Update the location of facts.yaml.
#
sed -i /opt/rh/ruby193/root/etc/mcollective/server.cfg \
  -e '/^\s*logfile\s*=\s*/ s,/var/log/mcollective.log,/var/log/ruby193-mcollective.log,' \
  -e '/^\s*plugin\.yaml\s*=\s*/ s,/etc/mcollective/facts.yaml,/opt/rh/ruby193/root/etc/mcollective/facts.yaml,'

# Make sure that the log file at the new location has the correct
# permissions.
touch /var/log/ruby193-mcollective-client.log
chown apache:root /var/log/ruby193-mcollective-client.log

# Enable the new service.
#
# Note: We have already uninstalled the mcollective package in order to
# get around versioned dependencies on the ruby193-mcollective-common
# package, so we do not need to worry about the old mcollective
# service script.
chkconfig ruby193-mcollective on
