create_vhost.sh: fix handling in case of unix socket.

This commit is contained in:
Christoph 2018-10-09 04:09:54 +02:00
parent b003005c86
commit 0cd0ab607c

View File

@ -95,6 +95,18 @@ trim() {
echo -n "$var"
}
is_number() {
return $(test ! -z "${1##*[!0-9]*}" > /dev/null 2>&1);
# - also possible
# -
#[[ ! -z "${1##*[!0-9]*}" ]] && return 0 || return 1
#return $([[ ! -z "${1##*[!0-9]*}" ]])
}
echononl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
@ -1773,37 +1785,45 @@ if [ "$_type" = "PHP-FPM" ]; then
echo ""
echo "Use unix socket or tcp for connection to PHP-FPM ?"
echo ""
echo "[1] Unix Socket"
echo -e "[1] \033[1mUnix Socket\033[m"
echo "[2] TCP Conection"
echo ""
echononl "Your choice: "
echononl "Eingabe: "
while [ "$connection" != "unix_socket" -a "$connection" != "tcp_connection" ];do
read OPTION
case $OPTION in
1) connection="unix_socket"
_connection_msg="Unix Socket"
;;
2) connection="tcp_connection"
_connection_msg="TCP Conection"
;;
*) echo ""
echo -e "\t\033[1;33mFalsche Eingabe ! [ 1 = Unix Socket ; 2 = TCP Conection ]\033[m"
echo ""
echononl "Your choice: "
;;
esac
read _IN
if [[ -z "$_IN" ]] ; then
connection="unix_socket"
_connection_msg="Unix Socket"
else
case $_IN in
1) connection="unix_socket"
_connection_msg="Unix Socket"
;;
2) connection="tcp_connection"
_connection_msg="TCP Conection"
;;
*) echo ""
echo -e "\t\033[1;33mFalsche Eingabe ! [ 1 = Unix Socket ; 2 = TCP Conection ]\033[m"
echo ""
echononl "Eingabe: "
;;
esac
fi
done
fi
if [ "$connection" == "unix_socket" ]; then
# - If unix_socket was not given on the command line
# -
if [ "X$unix_socket" = "X" ] ; then
_unix_socket=`ls /tmp/php-${major_php_verison}*.sock 2>/dev/null`
_unix_socket_arr=();
if [[ "$(wc -w <<< "$_unix_socket")" -gt 1 ]]; then
if [[ "$(wc -w <<< "$_unix_socket")" -gt 0 ]]; then
for _socket in ${_unix_socket} ; do
_unix_socket_arr+=("$_socket")
done
@ -1815,19 +1835,46 @@ if [ "$_type" = "PHP-FPM" ]; then
echo ""
echo "Where to find the unix php-fpm socket.."
if [[ ${#_unix_socket_arr[@]} -gt 1 ]]; then
if [[ ${#_unix_socket_arr[@]} -gt 0 ]]; then
echo ""
for _socket in ${_unix_socket} ; do
echo " $_socket"
declare -i i=0
declare -i i_default=-1
for _socket in ${_unix_socket_arr[@]} ; do
if [[ $_socket =~ www ]] || [[ ${#_unix_socket_arr[@]} -eq 1 ]] ; then
echo -e "[${i}] \033[1m${_socket}\033[m"
i_default=$i
else
echo "[${i}] ${_socket}"
fi
(( i++ ))
done
_OK=false
echo ""
echononl "Eingabe: "
while ! $_OK ; do
read _IN
if [[ -z "$_IN" ]] && [[ $i_default -gt -1 ]] ; then
_IN=$i_default
fi
if is_number "$_IN" && [[ -n ${_unix_socket_arr[$_IN]} ]]; then
unix_socket="${_unix_socket_arr[$_IN]}"
_OK=true
else
echo ""
echo -e "\tFalsche Eingabe !"
echo ""
echononl "Eingabe: "
fi
done
_unix_socket=""
fi
echo ""
echo ""
unix_socket=
if [[ -z $_unix_socket ]] ; then
while [ "X$unix_socket" = "X" ] ; do
if [[ ! -S "$unix_socket" ]]; then
echo -e "\n\t\033[1;33mNo Unix Socket found at \"$unix_socket\"!\033[m\n"
unix_socket=""
while [ "X$unix_socket" = "X" ] ; do
echononl "Unix PHP-FPM socket: "
read unix_socket
@ -1836,31 +1883,22 @@ if [ "$_type" = "PHP-FPM" ]; then
continue
fi
if [ ! -S "$unix_socket" ]; then
echo -e "\n\t\033[1;33mNo Unix Socket found at \"unix_socket\"! Try again..\033[m\n"
echo -e "\n\t\033[1;33mNo Unix Socket found at \"$unix_socket\"! Try again..\033[m\n"
unix_socket=""
fi
done
else
while [ "X$unix_socket" = "X" ] ; do
echononl "Unix PHP-FPM socket [$_unix_socket]: "
read unix_socket
fi
if [ "X$unix_socket" = "X" ]; then
unix_socket=$_unix_socket
fi
if [ ! -S "$unix_socket" ]; then
echo -e "\n\t\033[1;33mNo Unix Socket found at \"unix_socket\"! Try again..\033[m\n"
unix_socket=""
fi
done
fi
else
echo -e "\033[21G\033[32mUsing Unix Socket \033[m\"$unix_socket\""
fi
tcp_host=127.0.0.1
tcp_port=9000
_proxy_match="^/(.*\.php(/.*)?)\$ unix:$unix_socket|fcgi://$tcp_host:$tcp_port$_doc_root"
_set_handler_fpm="\"proxy:unix:$unix_socket|fcgi://$tcp_host\""
unix_socket_owner="$(stat -c '%U' $unix_socket)"
unix_socket_group="$(stat -c '%G' $unix_socket)"
else
echo ""
echo ""
@ -2313,6 +2351,8 @@ fi
echononl "\tChange owner of Web Base directory \"$_web_base_dir\".."
if $_suEXEC ; then
chown -R ${suEXEC_user}:$suEXEC_group $_web_base_dir
elif [[ "$_type" = "PHP-FPM" ]]; then
chown -R ${unix_socket_owner}:${unix_socket_group} $_web_base_dir
else
chown -R ${web_user}:${web_group} $_web_base_dir
fi
@ -2362,6 +2402,8 @@ fi
echononl "\tChange owner of \"DocumentRoot\" directory.."
if $_suEXEC ; then
chown -R ${suEXEC_user}:$suEXEC_group $_doc_root
elif [[ "$_type" = "PHP-FPM" ]]; then
chown -R ${unix_socket_owner}:${unix_socket_group} $_doc_root
else
chown -R ${web_user}:${web_group} $_doc_root
fi