Update UPDATE.sh

This commit is contained in:
Stefan Pejcic 2025-05-22 12:46:46 +02:00 committed by GitHub
parent 4e386b0440
commit 7d6717091c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,32 +17,32 @@ systemctl restart admin > /dev/null 2>&1
CONFIG_FILE="/etc/openpanel/openpanel/conf/openpanel.config" CONFIG_FILE="/etc/openpanel/openpanel/conf/openpanel.config"
MODULES_TO_CHECK=("mysql" "domains" "autoinstaller" "filemanager" "php") MODULES_TO_CHECK=("mysql" "domains" "autoinstaller" "filemanager" "php")
current_modules=$(grep "^enabled_modules=" "$CONFIG_FILE" | sed -E 's/^enabled_modules="(.*)"/\1/') # Check if the config file exists
modules_modified=0 if [[ ! -f "$CONFIG_FILE" ]]; then
echo "Config file not found: $CONFIG_FILE"
exit 1
fi
IFS=',' read -r -a enabled_array <<< "$current_modules" # Get the current enabled_modules line
current_modules=$(grep "^enabled_modules=" "$CONFIG_FILE" | cut -d= -f2)
# Keep track of changes
modules_modified=false
# Loop through each required module
for module in "${MODULES_TO_CHECK[@]}"; do for module in "${MODULES_TO_CHECK[@]}"; do
if printf '%s\n' "${enabled_array[@]}" | grep -qx "$module"; then if echo "$current_modules" | grep -qw "$module"; then
echo "'$module' is already enabled." echo "'$module' is already enabled."
else else
echo "Adding '$module' to enabled_modules..." echo "Adding '$module' to enabled_modules..."
enabled_array+=("$module") current_modules="${current_modules},$module"
modules_modified=1 modules_modified=true
fi fi
done done
if [[ $modules_modified -eq 1 ]]; then
updated_modules=$(IFS=','; echo "${enabled_array[*]}")
# Use double quotes around the value when writing back
sed -i "s/^enabled_modules=\".*\"/enabled_modules=\"${updated_modules}\"/" "$CONFIG_FILE"
sed -i "s/^enabled_modules=\(.*\)$/enabled_modules=\"\1\"/" "$CONFIG_FILE"
echo "Updated enabled_modules in config file."
fi
# Update the file only if we added new modules # Update the file only if we added new modules
if [ "$modules_modified" -eq 1 ]; then if [ "$modules_modified" = true ]; then
sed -i "s/^enabled_modules=.*/enabled_modules=${current_modules}/" "$CONFIG_FILE" sed -i "s/^enabled_modules=.*/enabled_modules=\"${current_modules}\"/" "$CONFIG_FILE"
echo "Updated enabled_modules in config file." echo "Updated enabled_modules in config file."
fi fi