apache.bash

#!/usr/bin/env bash

import core/apache_fedora

function apache(){
    run help apache
}

# Sets up the current directory as apache user & set permissions & update selinux to run under apache
function apache_dir(){

    source "${SCRIPT_ROOT}/secrets/general.bash" 

    curDir="$(pwd)"

    read -p "Set dir {$curDir} as apache group? (y/n)" doServer
    if [[ "${doServer}" != "y" ]]; then
        echo "Canceled...";
        return;
    fi

    didSudo="$(sudo pwd)";
    sudo find "${curDir}" -type d -exec chmod g+s {} +
    sudo chmod +x "${curDir}/.htaccess"
    sudo chown -R "${apache_user}" "${curDir}"
    sudo chgrp -R "${apache_group}" "${curDir}"
    find $SERVER_PATH -type d -print0 | sudo xargs -0 chmod 771 
    find $SERVER_PATH -type f -print0 | sudo xargs -0 chmod 660
    find $SERVER_PATH -type f -name ".htaccess" -print0 | sudo xargs -0 chmod o+r
    sudo semanage fcontext -a -t httpd_sys_rw_content_t "${curDir}(/.*)?"; 
    sudo restorecon -RF "${curDir}/"
    return;
    ## old code I'm not using any more...

    SERVER_PATH="${curDir}"

    sudo chgrp -R "${apache_group}" $SERVER_PATH
    sudo chown -R "${apache_user}" $SERVER_PATH

    find $SERVER_PATH -type f -name "*.sh" -print0 | sudo xargs -0 chmod ug+x

    sudo chmod -R ug+x $BASH_DIR

}