Update UPDATE.sh

This commit is contained in:
Stefan Pejcic 2025-03-31 15:34:23 +02:00 committed by GitHub
parent b265f53e10
commit 959adac5a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,8 @@ INSERT_TEXT="Listen 443"
for dir in /home/*; do
file="$dir/httpd.conf"
user=$(basename "$dir")
# ADDS :443 FOR APACHE HTTPD
if [[ -f "$file" ]]; then
if ! grep -q "$INSERT_TEXT" "$file"; then
@ -23,9 +25,54 @@ $INSERT_TEXT" "$file"
fi
fi
# ADDS ROOT USER FOR PHP-FPM
file="$dir/docker-compose.yml"
if [[ -f "$file" ]]; then
sed -i '/^\s*php-fpm\s*$/s/php-fpm/php-fpm --allow-to-run-as-root/' $file
fi
BACKUP_FILE="${file}.bak"
# Create a backup before modifying
cp "$file" "$BACKUP_FILE"
echo "Backup created at $BACKUP_FILE"
# Remove duplicate old values
sed -i '/- APP_USER=${CONTEXT:-www-data}/d' "$file"
sed -i '/- APP_GROUP=${CONTEXT:-www-data}/d' "$file"
sed -i '/- APP_UID=0 #${USER_ID:-0}/d' "$file"
sed -i '/- APP_GID=0 #${USER_ID:-0}/d' "$file"
# Replace existing values if found
sed -i 's|- APP_USER=${CONTEXT:-www-data}|- APP_USER=${CONTEXT:-root}|' "$file"
sed -i 's|- APP_GROUP=${CONTEXT:-www-data}|- APP_GROUP=${CONTEXT:-root}|' "$file"
sed -i 's|- APP_UID=0 #${USER_ID:-0}|- APP_UID=${USER_ID:-0}|' "$file"
sed -i 's|- APP_GID=0 #${USER_ID:-0}|- APP_GID=${USER_ID:-0}|' "$file"
# Check if PHP_UPLOAD_MAX_FILESIZE exists
if grep -q "PHP_UPLOAD_MAX_FILESIZE=" "$file"; then
# Extract indentation of PHP_UPLOAD_MAX_FILESIZE=
INDENTATION=$(grep -m1 "PHP_UPLOAD_MAX_FILESIZE=" "$file" | sed -E 's/(.*)- PHP_UPLOAD_MAX_FILESIZE=.*/\1/')
# Construct formatted lines
INSERT_LINES="${INDENTATION}- APP_USER=\${CONTEXT:-root}\n\
${INDENTATION}- APP_GROUP=\${CONTEXT:-root}\n\
${INDENTATION}- APP_UID=\${USER_ID:-0}\n\
${INDENTATION}- APP_GID=\${USER_ID:-0}"
# Ensure the lines are present after PHP_UPLOAD_MAX_FILESIZE=
if ! grep -q "APP_USER=" "$file"; then
sed -i "/PHP_UPLOAD_MAX_FILESIZE=/a\\
$INSERT_LINES" "$file"
echo "Lines added after PHP_UPLOAD_MAX_FILESIZE."
fi
else
echo "PHP_UPLOAD_MAX_FILESIZE not found in the file."
fi
done