#!/bin/sh # Verify that the proper version of SSL is installed is_suse11_platform_with_openssl1(){ if [ -e /etc/SuSE-release ];then VERSION=`cat /etc/SuSE-release|grep "VERSION = 11"|awk 'FS=":"{print $3}'` if [ ! -z "$VERSION" ];then which openssl1>/dev/null 2>&1 if [ $? -eq 0 -a $VERSION -eq 11 ];then return 0 fi fi fi return 1 } is_suse11_platform_with_openssl1 if [ $? -eq 0 ];then SSL_VERSION=`openssl1 version | awk '{print $2}'` else SSL_VERSION=`openssl version | awk '{print $2}'` fi case "$SSL_VERSION" in 1.0.*) SSL_FOUND=1.0.0 ;; 1.1.*) SSL_FOUND=1.1.0 ;; 3.*) SSL_FOUND=3.0.0 ;; *) echo "Preinstall script error: Unrecognized version of SSL on the system: $SSL_VERSION" >&2 exit 2 ;; esac if [ "$SSL_FOUND" != "1.1.0" ]; then echo "Expecting SSL version (compatible with): 1.1.0" >&2 echo "SSL version found on system: ${SSL_VERSION}" >&2 echo "" >&2 echo "Incorrect version of OMI for your system, please check SSL version." >&2 exit 3 fi # Various distributions have different paths for systemd unit files ... SYSTEMD_UNIT_DIR="" ResolveSystemdPaths() { local UNIT_DIR_LIST="/usr/lib/systemd/system /lib/systemd/system" if [ -d /run/systemd/system ]; then # Find systemd unit directory for i in ${UNIT_DIR_LIST}; do if [ -d $i ]; then SYSTEMD_UNIT_DIR=${i} return 0 fi done # Didn't fine unit directory, that's fatal echo "FATAL: Unable to resolve systemd unit directory!" 1>&2 exit 1 else return 1 fi } RemoveGenericService() { if [ -f /etc/.omi_disable_service_control ]; then return 0 fi SERVICE=$1 if [ -z "$SERVICE" ]; then echo "FATAL: RemoveGenericService requires parameter (service name)" 1>&2 exit 1 fi # Stop the service in case it's running ResolveSystemdPaths # Does systemd install on this system if [ -d /run/systemd/system ]; then # Do we have a systemd unit file? if [ -f ${SYSTEMD_UNIT_DIR}/${SERVICE}.service ]; then /bin/systemctl stop ${SERVICE} fi fi if [ -f /etc/init/${SERVICE}.conf ]; then initctl stop omid fi if [ -f /etc/init.d/${SERVICE} ]; then if [ -x /bin/systemctl ]; then /bin/systemctl stop ${SERVICE} elif [ -x /sbin/service ]; then /sbin/service ${SERVICE} stop elif [ -x /usr/sbin/service ]; then /usr/sbin/service ${SERVICE} stop elif [ -x /usr/sbin/invoke-rc.d ]; then /usr/sbin/invoke-rc.d ${SERVICE} stop else echo "Unrecognized service controller to stop ${SERVICE} service" 1>&2 exit 1 fi fi # Registered as a systemd service? # # Note: We've never deployed systemd unit files automatically in the %Files # section. Thus, for systemd services, it's safe to remove the file. if [ -f ${SYSTEMD_UNIT_DIR}/${SERVICE}.service ]; then echo "Unconfiguring ${SERVICE} (systemd) service ..." /bin/systemctl disable ${SERVICE} rm -f ${SYSTEMD_UNIT_DIR}/${SERVICE}.service /bin/systemctl daemon-reload fi if [ -f /etc/init/omid.conf ]; then echo "Unconfiguring omid (upstart) service ..." rm -f /usr/init/omid.conf initctl reload-configuration fi if [ -f /etc/init.d/${SERVICE} ]; then echo "Unconfiguring ${SERVICE} service ..." if [ -f /usr/sbin/update-rc.d ]; then /usr/sbin/update-rc.d -f ${SERVICE} remove elif [ -x /usr/lib/lsb/remove_initd ]; then /usr/lib/lsb/remove_initd /etc/init.d/${SERVICE} elif [ -x /sbin/chkconfig ]; then chkconfig --del ${SERVICE} > /dev/null else echo "Unrecognized Service Controller to unregister ${SERVICE} Service." exit 1 fi fi } StopOmiService() { /opt/omi/bin/service_control stop } RemoveOmiService() { if [ -f /etc/.omi_disable_service_control ]; then return 0 fi RemoveGenericService omid [ -f /etc/init.d/omid ] && rm /etc/init.d/omid [ -f /etc/init/omid.conf ] && rm /etc/init/omid.conf } ConfigureOmiService() { # If the marker file /etc/.omi_disable_service_control exists, # OMI will not be configured with service manager. This may be used in a container # environment, where service manager does not work reliably. if [ ! -f /etc/.omi_disable_service_control ]; then echo "Configuring OMI service ..." if [ -d /run/systemd/system ]; then # systemd ResolveSystemdPaths cp /opt/omi/bin/support/omid.systemd ${SYSTEMD_UNIT_DIR}/omid.service /bin/systemctl daemon-reload /bin/systemctl enable omid elif [ -x /sbin/initctl -a -f /etc/init/networking.conf -a ! -z "$(/sbin/initctl list >/dev/null 2>&1 && echo $?)" ]; then # If we have /sbin/initctl, we have upstart. # Note that the upstart script requires networking, # so only use upstart if networking is controlled by upstart (not the case in RedHat 6) cp /opt/omi/bin/support/omid.upstart /etc/init/omid.conf # initctl registers it with upstart initctl reload-configuration else cp /opt/omi/bin/support/omid.initd /etc/init.d/omid if [ -x /usr/sbin/update-rc.d ]; then update-rc.d omid defaults > /dev/null elif [ -x /usr/lib/lsb/install_initd ]; then /usr/lib/lsb/install_initd /etc/init.d/omid elif [ -x /sbin/chkconfig ]; then chkconfig --add omid > /dev/null else echo "Unrecognized Service Controller to configure OMI Service." exit 1 fi fi fi /opt/omi/bin/service_control start } ConfigureCronForLogRotate() { echo "Checking if cron is installed..." # warn user that he need to install cron if cron doesn't install which cron >/dev/null 2>&1 if [ $? -ne 0 ]; then which crond >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "WARNING: LogRotate can't be enabled, please install cron at first!" return fi fi echo "Checking if cron/crond service is started..." # warn user that he need to start cron/crond service if cron doesn't start cronid=$(pidof cron > /dev/null 2>&1) crondid=$(pidof crond > /dev/null 2>&1) if [ ! -z "$cronid" -a ! -z "$crondid" ]; then echo "WARNING: LogRotate can be enabled, but please start cron/crond service!" fi echo "Set up a cron job to OMI logrotate every 15 minutes" # create the cron file if it doesn't exist if [ ! -f /etc/cron.d/omilogrotate ]; then (echo "*/15 * * * * root /usr/sbin/logrotate /etc/logrotate.d/omi --state /var/opt/omi/log/omi-logrotate.status >/dev/null 2>&1" > /etc/cron.d/omilogrotate) > /dev/null 2>&1 fi } RemoveGenericService omiserverd RemoveGenericService scx-cimd RemoveOmiService egrep -q "^omiusers:" /etc/group if [ $? -ne 0 ]; then echo "Creating omiusers group ..." groupadd -r omiusers fi egrep -q "^omi:" /etc/group if [ $? -ne 0 ]; then echo "Creating omi group ..." groupadd -r omi fi egrep -q "^omi:" /etc/passwd if [ $? -ne 0 ]; then echo "Creating omi service account ..." useradd -g omi -s /bin/false -r omi fi exit 0