From 22f792a40c91ba6e134d0b41d3eb1c7e7e3bddb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radovan=20Je=C4=8Dmenica?= <147708271+radovanjecmenica@users.noreply.github.com> Date: Tue, 29 Apr 2025 13:10:47 +0200 Subject: [PATCH] Update UPDATE.sh --- version/1.2.5/UPDATE.sh | 106 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 10 deletions(-) diff --git a/version/1.2.5/UPDATE.sh b/version/1.2.5/UPDATE.sh index 34c46c05..ce88f175 100644 --- a/version/1.2.5/UPDATE.sh +++ b/version/1.2.5/UPDATE.sh @@ -1,32 +1,118 @@ #!/bin/bash echo "" -echo "Downloading crons.ini template.." +echo "📥 Downloading crons.ini template.." mkdir -p /etc/openpanel/ofelia/ -wget -O "/etc/openpanel/ofelia/users.ini" "https://raw.githubusercontent.com/stefanpejcic/openpanel-configuration/refs/heads/main/ofelia/users.ini" +wget -q -O "/etc/openpanel/ofelia/users.ini" "https://raw.githubusercontent.com/stefanpejcic/openpanel-configuration/refs/heads/main/ofelia/users.ini" && \ + echo "✔ Template downloaded to /etc/openpanel/ofelia/users.ini" +echo "" +echo "🛠 Creating crons.ini files for each user in /home.." for dir in /home/*; do username=$(basename "$dir") CONF_PATH="$dir/crons.ini" - USER_CONF="/etc/openpanel/$username/users.ini" - if [ -d "$CONF_PATH" ]; then - rm -rf "$CONF_PATH" && touch "$CONF_PATH" + if [ -f "$CONF_PATH" ] || [ -e "$CONF_PATH" ]; then + rm -f "$CONF_PATH" fi + touch "$CONF_PATH" + echo "→ Created: $CONF_PATH" done echo "" -echo "Adding demo_mode option for both OpenAdmin and OpenPanel.." +echo "⚙ Adding dev_mode option for both OpenAdmin and OpenPanel.." FILE="/etc/openpanel/openpanel/conf/openpanel.config" -# Check if dev_mode exists under the [PANEL] section if ! grep -q "dev_mode" "$FILE"; then if grep -q "\[PANEL\]" "$FILE"; then sed -i '/\[PANEL\]/a dev_mode=off' "$FILE" - echo "dev_mode=off added under [PANEL]." + echo "✔ dev_mode=off added under [PANEL]." else - echo "error: PANEL section doesn't exist!" + echo "❌ Error: [PANEL] section doesn't exist in $FILE!" fi else - echo "dev_mode already exists." + echo "✔ dev_mode already exists in config." fi + +echo "" +echo "🔧 Modifying docker-compose.yml and .env for each user..." + +for dir in /home/*/; do + user=$(basename "$dir") + compose_file="${dir}docker-compose.yml" + env_file="/home/$user/.env" + + + if [ -f "$compose_file" ]; then + cp "$compose_file" "${dir}024_docker-compose.yml" + echo "→ Checking $compose_file for $user" + + # Check if backup service exists + if grep -q "^\s*backup:" "$compose_file"; then + echo " ✔ backup: block found" + + # Check if the html_data volume is present + if grep -A10 "^\s*backup:" "$compose_file" | grep -q "\- html_data:/backup/html:ro"; then + echo " ✔ html_data:/backup/html:ro already present" + else + # Add html_data:/backup/html:ro under the 'volumes:' section in the backup block + inserted=0 + awk ' + BEGIN { in_backup=0; in_volumes=0 } + { + if ($1 == "backup:" || $2 == "backup:") { in_backup=1 } + if (in_backup && $1 == "volumes:" || $2 == "volumes:") { in_volumes=1 } + if (in_backup && in_volumes && $0 ~ /^ *[^-]/ && !inserted) { + print " - html_data:/backup/html:ro" + inserted=1 + in_volumes=0 + in_backup=0 + } + print $0 + } + END { + if (in_backup && in_volumes && !inserted) { + print " - html_data:/backup/html:ro" + } + }' "$compose_file" > "${compose_file}.tmp" && mv "${compose_file}.tmp" "$compose_file" + echo " ✔ html_data:/backup/html:ro added" + fi + else + echo " ✖ backup: block not found, skipping" + fi + else + echo "❌ $compose_file not found for $user" + fi + + # --- Update .env file --- + if [ -f "$env_file" ]; then + cp "$env_file" "/home/$user/024_.env" + echo "→ Modifying $env_file for $user" + + # Only insert if BACKUP_CPU not already in the file + if ! grep -q "BACKUP_CPU=" "$env_file"; then + awk ' + BEGIN { found = 0 } + { + print + if ($0 ~ /^# WEBSERVER$/ && found == 0) { + found = 1 + print "WEB_SERVER=\"nginx\"" + print "HTTP_PORT=\"0:80\"" + print "HTTPS_PORT=\"0:443\"" + print "PROXY_HTTP_PORT=\"\"" + print "" + print "# BACKUP" + print "BACKUP_CPU=\"1.0\"" + print "BACKUP_RAM=\"1.0G\"" + } + } + ' "$env_file" > "$env_file.tmp" && mv "$env_file.tmp" "$env_file" + echo " ✔ Backup config inserted after WEBSERVER block" + else + echo " ✔ Backup config already present" + fi + else + echo "❌ .env file not found for $user" + fi +done