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