#!/bin/bash

# Copyright 2014 Cloud Linux Zug GmbH
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT

yum install liblsapi liblsapi-devel --enablerepo=cloudlinux-updates-testing

if [ ! -e /etc/cl.selector/lsphp -a -e /usr/sbin/cagefsctl -a -e /etc/cl.selector ]; then
    ln -s /usr/local/bin/lsphp /etc/cl.selector/lsphp
    /usr/sbin/cagefsctl --update-etc
    RES=`cat /etc/cl.selector/native.conf | grep lsphp=/usr/local/bin/lsphp `
    if [ -z "$RES" ]; then
        echo "lsphp=/usr/local/bin/lsphp" >> /etc/cl.selector/native.conf
    fi
    /usr/sbin/cagefsctl --setup-cl-selector

    IS_MNT=`cat /etc/cagefs/cagefs.mp | grep /tmp/lshttpd`
    if [ -z "$IS_MNT" ]; then
        mkdir -p /tmp/lshttpd
        chmod 755 /tmp/lshttpd
        echo "/tmp/lshttpd" >> /etc/cagefs/cagefs.mp
        /usr/sbin/cagefsctl --remount-all
    fi

    echo "Reconfiguration completed"
fi

if [ ! -e /tmp/lshttpd ]; then
    mkdir -p /tmp/lshttpd   
fi

chown apache:apache /tmp/lshttpd
chmod 755 /tmp/lshttpd

