Add script 'get_apache2_info.sh'.

This commit is contained in:
Christoph 2021-02-12 13:16:51 +01:00
parent 81a6ea2c6c
commit b584d3c2e2
2 changed files with 322 additions and 0 deletions

View File

@ -790,6 +790,10 @@ if [ -z "$_existing_vhost_config_file" ]; then
if [ "X$_doc_root" = "X" ]; then
_doc_root=$__document_root
fi
echo ""
echo "_doc_root: $_doc_root"
echo "_web_base_dir: $_web_base_dir"
echo ""
if [ "`dirname $_doc_root`" != "$_web_base_dir" ]; then
echo -e "\n\t\033[1;33mDocument Root Directory must be a subdirectory of \"$_web_base_dir\".\n\tTry again..\033[m\n"
_doc_root=

318
get_apache2_info.sh Executable file
View File

@ -0,0 +1,318 @@
!#/usr/bin/env bash
script_name="$(basename $(realpath $0))"
working_dir="$(dirname $(realpath $0))"
conf_file="${working_dir}/conf/${script_name%%.*}.conf"
log_file="$(mktemp)"
random_prefix="$(head -c 300 /dev/urandom | tr -cd 'a-zA-Z0-9' | head -c 8)"
backup_date=$(date +%Y-%m-%d-%H%M)
# =============
# --- Some Variables
# =============
DEFAULT_HTTP_USER="www-data"
DEFAULT_HTTP_GROUP="www-data"
# =============
# --- Some Functions
# =============
clean_up() {
# Perform program exit housekeeping
rm -f $log_file
rm -rf /tmp/*.${random_prefix}
blank_line
exit $1
}
echononl(){
if $terminal ; then
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n "\033[4G[ \033[5m\033[1m....\033[m ]\033[13G$*\\c" 1>&2
else
echo -e -n "\033[4G[ \033[5m\033[1m....\033[m ]\033[13G$*" 1>&2
fi
rm /tmp/shprompt$$
fi
}
echoprompt(){
if $terminal ; then
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n "\033[4G$*\\c" 1>&2
else
echo -e -n "\033[4G$*" 1>&2
fi
rm /tmp/shprompt$$
fi
}
echo_done() {
if $terminal ; then
echo -e "\033[4G[ \033[1;32mdone\033[m ]"
fi
}
echo_ok() {
if $terminal ; then
echo -e "\033[4G[ \033[1;32mok\033[m ]"
fi
}
echo_ignore() {
if $terminal ; then
echo -e "\033[4G[ \033[1;33mignore\033[m ]"
fi
}
echo_warning() {
if $terminal ; then
echo -e "\033[4G[ \033[1;33m\033[1mwarn\033[m ]"
fi
}
echo_failed(){
if $terminal ; then
echo -e "\033[4G[ \033[1;31mfail\033[m ]"
fi
}
echo_skipped() {
if $terminal ; then
echo -e "\033[4G[ \033[1;37mskip\033[m ]"
fi
}
echo_wait(){
if $terminal ; then
echo -en "\033[4G[ \033[5m\033[1m...\033[m ]"
fi
}
fatal (){
blank_line
if $terminal ; then
echo ""
echo -e "\033[1m---\033[m"
echo ""
echo -e "[ \033[31m\033[1mFatal\033[m ]: \033[37m\033[1m$*\033[m"
echo ""
echo -e "\033[31m\033[1m Script will be interrupted..\033[m\033[m"
else
echo ""
echo "---"
echo ""
echo "fatal: $*"
echo "Script will be interrupted.."
fi
clean_up 1
}
error(){
blank_line
if $terminal ; then
echo -e " [ \033[31m\033[1mFehler\033[m ]: $*"
else
echo ""
echo "[ Error ]: $*"
echo ""
fi
blank_line
}
warn (){
if $terminal ; then
echo ""
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
echo ""
fi
}
info (){
if $terminal ; then
echo ""
echo -e " [ \033[32m\033[1mInfo\033[m ]: $*"
echo ""
fi
}
## - Check if a given array (parameter 2) contains a given string (parameter 1)
## -
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var"
}
blank_line() {
if $terminal ; then
echo ""
fi
}
# =============
# --- Jobhandling
# =============
# - Run 'clean_up' for signals SIGHUP SIGINT SIGTERM
# -
trap clean_up SIGHUP SIGINT SIGTERM
# =============
# --- Some Checks
# =============
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
# ==========
# - Begin Main Script
# ==========
# ----------
# - Headline
# ----------
if $terminal ; then
echo ""
echo -e "\033[1m----------\033[m"
echo -e "\033[32m\033[1mRunning script \033[m\033[1m$script_name\033[32m .. \033[m"
echo -e "\033[1m----------\033[m"
echo ""
fi
echononl "Determin httpd binary .."
_httpd_binary="$(which httpd)"
if [[ -z "$_httpd_binary" ]] ; then
_httpd_binary="$(which apache2)"
if [[ -n "$_httpd_binary" ]] ; then
[[ -f "/etc/apache2/envvars" ]] && source "/etc/apache2/envvars"
fi
fi
if [[ -z "$_httpd_binary" ]]; then
_httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
if [[ -z "$_httpd_binary" ]]; then
if [[ -x "/usr/local/apache2/bin/httpd" ]]; then
_httpd_binary="/usr/local/apache2/bin/httpd"
echo_done
else
echo_failed
fatal "Apache2 installation not found!"
fi
else
echo_done
fi
else
echo_done
fi
HTTPD_COMMAND="$_httpd_binary"
echononl "Determin websevers user/group.."
HTTP_USER="$($_httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d"=" -f2 | tr -d '"')"
if [[ $? -gt 0 ]]; then
echo_failed
else
HTTP_GROUP="$($_httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d"=" -f2 | tr -d '"')"
if [[ $? -gt 0 ]]; then
echo_failed
else
if [ -z "$HTTP_USER" -o -z "$HTTP_GROUP" ]; then
echo_failed
else
echo_done
fi
fi
fi
echononl "Determin ServerRoot Directory.."
APACHE_SERVER_ROOT="$($_httpd_binary -t -D DUMP_RUN_CFG | grep ServerRoot | awk '{print$2}' | tr -d '"')"
if [[ $? -gt 0 ]]; then
echo_failed
else
if [[ -z "$APACHE_SERVER_ROOT" ]]; then
if [[ -d "$(realpath "/usr/local/apache2/bin")" ]] \
&& [[ "$(realpath "$(dirname "$_httpd_binary")")" = $(realpath /usr/local/apache2/bin) ]]; then
echo_done
APACHE_SERVER_ROOT="/usr/local/apache2"
else
echo_failed
fi
else
echo_done
if [[ "$(realpath "/usr/local/apache2")" = "${APACHE_SERVER_ROOT}" ]] ; then
APACHE_SERVER_ROOT="/usr/local/apache2"
fi
fi
fi
echononl "Determin Apache2 version number.."
APACHE_VERSION="$(trim $($HTTPD_COMMAND -v | head -1 | cut -d ":" -f2))"
if [[ $? -gt 0 ]]; then
echo_failed
else
echo_done
fi
if $terminal ; then
echo ""
echo ""
echo -e "\033[4G\033[33m\033[1mApache2 Info:\033[m"
echo -e "\033[4G\033[33m\033[1m=============\033[m"
echo ""
fi
if [[ -n $APACHE_VERSION ]]; then
echo -e "\033[4GApache2 version..................: $APACHE_VERSION"
else
echo -e "\033[4GApache2 version..................: \033[33m-- could not be determined --\033[m"
fi
echo ""
if [[ -x "$HTTPD_COMMAND" ]] ; then
echo -e "\033[4GApache2 daemon ..................: $HTTPD_COMMAND"
else
echo -e "\033[4GApache2 daemon ..................: \033[33m-- could not be determined --\033[m"
fi
echo ""
if [[ -n "$APACHE_SERVER_ROOT" ]] ; then
echo -e "\033[4GServer Root Directory............: $APACHE_SERVER_ROOT"
else
echo "\033[4GServer Root Directory............: \033[33m-- could not be determined --\033[m"
fi
echo ""
if [[ -n "$HTTP_USER" ]] ; then
echo -e "\033[4GApache2 User.....................: $HTTP_USER"
else
echo -e "\033[4GApache2 User.....................: \033[33m-- could not be determined --\033[m"
fi
if [[ -n "$HTTP_GROUP" ]] ; then
echo -e "\033[4GApache2 Group....................: $HTTP_GROUP"
else
echo -e "\033[4GApache2 Group....................: \033[33m-- could not be determined --\033[m"
fi
clean_up 0