aboutsummaryrefslogtreecommitdiff
path: root/helpers/update-paths.sh
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/update-paths.sh')
-rw-r--r--helpers/update-paths.sh58
1 files changed, 58 insertions, 0 deletions
diff --git a/helpers/update-paths.sh b/helpers/update-paths.sh
new file mode 100644
index 0000000..60f6444
--- /dev/null
+++ b/helpers/update-paths.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+BASE_DIR="$(dirname "$SCRIPT_DIR")"
+echo "Base directory detected as: $BASE_DIR"
+
+mkdir -p "$BASE_DIR/config"
+mkdir -p "$BASE_DIR/logs/python"
+mkdir -p "$BASE_DIR/logs/php"
+mkdir -p "$BASE_DIR/logs/nginx"
+
+touch "$BASE_DIR/logs/python/proxy.log"
+touch "$BASE_DIR/logs/php/webui.log"
+touch "$BASE_DIR/logs/nginx/nginx-access.log"
+touch "$BASE_DIR/logs/nginx/nginx-error.log"
+
+chmod -R 775 "$BASE_DIR/logs"
+chmod 664 "$BASE_DIR/logs/python/proxy.log"
+chmod 664 "$BASE_DIR/logs/php/webui.log"
+chmod 664 "$BASE_DIR/logs/nginx/nginx-access.log"
+chmod 664 "$BASE_DIR/logs/nginx/nginx-error.log"
+
+if [ $(id -u) -eq 0 ]; then
+ # Get the current user who is running sudo
+ ACTUAL_USER=$(logname || echo "$SUDO_USER")
+ echo "Setting ownership to $ACTUAL_USER:www-data"
+ chown -R $ACTUAL_USER:www-data "$BASE_DIR/logs"
+else
+ echo "Warning: Not running as root, ownership not changed. May need to manually adjust file ownership."
+ echo "Consider running: sudo chown -R $(whoami):www-data $BASE_DIR/logs"
+fi
+
+CONFIG_FILE="$BASE_DIR/config/config.env"
+echo "Updating paths in $CONFIG_FILE"
+
+sed -i "s|EMAILPROXY_LOG_FILE=.*|EMAILPROXY_LOG_FILE=$BASE_DIR/logs/python/proxy.log|" "$CONFIG_FILE"
+sed -i "s|EMAILPROXY_CONFIG_FILE=.*|EMAILPROXY_CONFIG_FILE=$BASE_DIR/config/emailproxy.config|" "$CONFIG_FILE"
+sed -i "s|EMAILPROXY_AUTH_CONFIG=.*|EMAILPROXY_AUTH_CONFIG=$BASE_DIR/config/emailproxy-auth.config|" "$CONFIG_FILE"
+sed -i "s|DEBUG_WEB_LOG_FILE=.*|DEBUG_WEB_LOG_FILE=$BASE_DIR/logs/php/webui.log|" "$CONFIG_FILE"
+
+PY_FILE="$BASE_DIR/emailproxy-ui.py"
+echo "Updating path in $PY_FILE"
+sed -i "s|CONFIG_FILE = .*|CONFIG_FILE = \"$BASE_DIR/config/config.env\"|" "$PY_FILE"
+
+UI_PHP="$BASE_DIR/emailproxy-ui.php"
+echo "Updating path in $UI_PHP"
+sed -i "s|\$config = parse_ini_file(.*|\$config = parse_ini_file('$BASE_DIR/config/config.env');|" "$UI_PHP"
+
+NGINX_CONF="$BASE_DIR/config/nginx-emailproxy.conf"
+echo "Updating paths in $NGINX_CONF"
+sed -i "s|access_log .*|access_log $BASE_DIR/logs/nginx/nginx-access.log;|" "$NGINX_CONF"
+sed -i "s|error_log .*|error_log $BASE_DIR/logs/nginx/nginx-error.log;|" "$NGINX_CONF"
+
+echo "updated the paths lol"
+echo "Log directories:"
+echo " - Python logs: $BASE_DIR/logs/python"
+echo " - PHP logs: $BASE_DIR/logs/php"
+echo " - Nginx logs: $BASE_DIR/logs/nginx" \ No newline at end of file