From fed8a1fc84f002ca17993de3308756a36ca2d27b Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Mon, 25 Mar 2019 11:34:03 +0100 Subject: [PATCH] Added function to search occurence of given name in vhosts --- scripts/web-add.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 532f634..b421326 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -131,6 +131,10 @@ update-servername VHOST SERVERNAME OLD_SERVERNAME Replace the OLD_SERVERNAME with the SERVERNAME for an Apache vhost Also apply to rules +check-occurence NAME + + List all occurences of NAME in vhosts + setphpversion LOGIN VERSION Change PHP version for LOGIN @@ -745,6 +749,9 @@ arg_processing() { update-servername) op_servernameupdate "$@" ;; + check-occurence) + op_checkoccurencename "$@" + ;; setphpversion) op_setphpversion "$@" ;; @@ -848,6 +855,26 @@ op_servernameupdate() { fi } +op_checkoccurencename() { + if [ $# -eq 1 ]; then + name=${1} + configlist="$VHOST_PATH/*"; + servernames='' + aliases='' + + for configfile in $configlist; do + if [ -r "$configfile" ]; then + aliases="$aliases $(perl -ne 'print "$1 " if /^[[:space:]]*ServerAlias (.*)/' "$configfile" | head -n 1)" + servernames="$servernames $(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | uniq)" + fi + done + + echo "$servernames" "$aliases" | grep -w "$name" + + else usage + fi +} + op_add() { #