From 738f2682b0c1eba7b253d38aec90f32ff268726e Mon Sep 17 00:00:00 2001 From: Mathieu Trossevin Date: Wed, 3 Nov 2021 17:40:13 +0100 Subject: [PATCH] packweb-apache: Use $SUDO_USER when possible in phpContainer And rollback to $LOGNAME when it isn't. This remove the need to add $LOGNAME to env_keep in the sudoers file. The $SUDO_USER variable is automatically set by sudo when it is used to the user who used it so it fullfill the same role as $LOGNAME do in phpContainer. --- CHANGELOG.md | 3 ++- packweb-apache/files/multiphp-sudoers | 2 +- packweb-apache/files/phpContainer | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4549cdca..208f3e1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,13 +24,14 @@ The **patch** part changes is incremented if multiple releases happen the same m * mongodb: Deny the install on Debian 11 « Bullseye » when the version is unsupported * mongodb: Support version 5.0 (for buster) * mongodb: Allow to specify a mongodb version for buster & bullseye +* packweb-apache: phpContainer now use $SUDO\_USER when available (so when run through sudo or as an unprivileged user) and $LOGNAME when not. ### Fixed * evolinux-base: fix alert5.service dependency syntax * mysql : Create a default ~root/.my.cnf for compatibility reasons * nginx : fix variable name and debug to actually use nginx-light -* packweb-apache : Support php 8.0 +* packweb-apache : Support php 8.0 ### Removed diff --git a/packweb-apache/files/multiphp-sudoers b/packweb-apache/files/multiphp-sudoers index 8bd0f446..3e428b0b 100644 --- a/packweb-apache/files/multiphp-sudoers +++ b/packweb-apache/files/multiphp-sudoers @@ -1,3 +1,3 @@ -Defaults env_keep += "LOGNAME PWD" +Defaults env_keep += "PWD" ALL ALL = NOPASSWD: /usr/local/bin/phpContainer diff --git a/packweb-apache/files/phpContainer b/packweb-apache/files/phpContainer index 0f634d6a..33319b62 100644 --- a/packweb-apache/files/phpContainer +++ b/packweb-apache/files/phpContainer @@ -6,10 +6,10 @@ if [ "$EUID" -ne 0 ]; then exit 0; fi; -PHPVersion=$(grep SetHandler /etc/apache2/sites-enabled/$LOGNAME.conf 2>/dev/null | grep -m 1 -o 'fpm[0-9][0-9]' | head -n 1 | sed 's/php//g' | sed 's/fpm//g') +PHPVersion=$(grep SetHandler /etc/apache2/sites-enabled/${SUDO_USER:-${LOGNAME}}.conf 2>/dev/null | grep -m 1 -o 'fpm[0-9][0-9]' | head -n 1 | sed 's/php//g' | sed 's/fpm//g') if [ "$PHPVersion" != "" ]; then - lxc-attach -n php$PHPVersion -- su - $LOGNAME -c "cd \"${PWD@E}\" && php ${*@Q}" + lxc-attach -n php$PHPVersion -- su - ${SUDO_USER:-${LOGNAME}} -c "cd \"${PWD@E}\" && php ${*@Q}" else # TODO: fallback? # command php $* -- 2.39.2