From: Matteo Nastasi Date: Sun, 13 Sep 2026 10:33:53 +0000 (+0200) Subject: INSTALL.sh: the root of the site is no longer asked of apache X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=994b9b2a4909630397c4088b540fecf13d53d77f;p=brisk.git INSTALL.sh: the root of the site is no longer asked of apache document_root="$(grep DocumentRoot "${apache_conf}" | ... | awk '{ print $2 }')" Three defects in one line: it tied INSTALL.sh to apache (nginx uses "root", not "DocumentRoot"), it took the first match in any VirtualHost without knowing which site was the right one, and it did not cope with quotes around the path. The value, though, can already be deduced from the parameters: web_path ends with prefix_path, so removing the latter from the former leaves the root. web_path = /home/brisk/web/brisk prefix_path = /brisk/ ------------------- root = /home/brisk/web No server to ask, and it works with multi segment prefixes too (/var/www/html/games/brisk with -P /games/brisk/ gives /var/www/html). The -R option was added to force an explicit value, and the old grep over the file named by -A was kept as a last resort; it now recognises both DocumentRoot and root and strips quotes and semicolons. If no route produces a value, INSTALL.sh stops with a clear message instead of going on with an empty string (which ended up producing requires of "/Etc/brisk_spu.conf.pho"). The derived value is now printed among the parameters, like the others. Checked in the container by running INSTALL.sh WITHOUT -A: it derives /home/brisk/web, writes it into $DOCUMENT_ROOT inside spush/*.ph* and donometer.php, and installs the files from docroot/ there. The site answers. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_014M1jiEq9cHdE5SE5j6vFuE --- diff --git a/INSTALL.sh b/INSTALL.sh index 5336b85..6d1478c 100755 --- a/INSTALL.sh +++ b/INSTALL.sh @@ -37,7 +37,8 @@ function usage () { echo " -f use this config file" echo " -p save preferences in the file" echo " -W web files only" - echo " -A apache_conf - def. $apache_conf" + echo " -A server conf (per DocumentRoot) - def. $apache_conf" + echo " -R document_root - def. ricavato da -w meno -P" echo " -c number cards in hand - def. $card_hand" echo " -n number of players - def. $players_n" echo " -t number of tables - def. $tables_n" @@ -167,6 +168,7 @@ while [ $# -gt 0 ]; do conffile="" case $1 in -A*) apache_conf="$(get_param "-A" "$1" "$2")"; sh=$?;; + -R*) document_root_in="$(get_param "-R" "$1" "$2")"; sh=$?;; -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;; -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;; -c*) card_hand="$(get_param "-c" "$1" "$2")"; sh=$?;; @@ -441,7 +443,35 @@ sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$prefix_path\";@ sed -i "s@\( \+cookiepath *: *\)\"[^\"]*\" *,@\1 \"$prefix_path\",@g" ${web_path}__/xynt-streaming.js -document_root="$(grep DocumentRoot "${apache_conf}" | grep -v '^[ ]*#' | awk '{ print $2 }')" +# The root of the site is needed for two things: substituting +# $DOCUMENT_ROOT in the sources and installing the files from docroot/. It +# used to be derived by grepping DocumentRoot out of the apache configuration +# file, which tied INSTALL.sh to apache (nginx uses "root", not +# "DocumentRoot"), took the first match in any VirtualHost, and did not cope +# with quotes. +# +# Now it is derived from the parameters already known: web_path ends with +# prefix_path, so removing the latter from the former leaves the root. No +# server to ask. An explicit value can still be forced with -R. +if [ ! -z "$document_root_in" ]; then + document_root="$(echo "$document_root_in" | sed 's:/*$::')" +else + _pfx="$(echo "$prefix_path" | sed 's:^/*::;s:/*$::')" # brisk + _web="$(echo "$web_path" | sed 's:/*$::')" # .../web/brisk + document_root="$(echo "$_web" | sed "s:/*$_pfx\$::")" + if [ "$document_root" = "$_web" -o -z "$document_root" ]; then + # web_path does not end with prefix_path: fall back on the server + # configuration file, accepting both DocumentRoot and root + document_root="$(grep -iE '^[ \t]*(DocumentRoot|root)[ \t]' "${apache_conf}" 2>/dev/null \ + | grep -v '^[ \t]*#' | head -1 \ + | awk '{ print $2 }' | tr -d '";' | sed 's:/*$::')" + fi +fi +if [ -z "$document_root" ]; then + echo "Impossibile determinare la radice del sito: usa -R " + exit 1 +fi +echo " document_root: \"$document_root\"" sed -i "s@^\(\$DOCUMENT_ROOT *= *[\"']\)[^\"']*\([\"']\)@\1$document_root\2@g" ${web_path}__/spush/*.ph* ${web_path}__/donometer.php # The files under docroot/ belong in the root of the site, not in the