Medowar 6 päivää sitten
vanhempi
sitoutus
f12bf6f668
2 muutettua tiedostoa jossa 37 lisäystä ja 7 poistoa
  1. 13 1
      _create_folder_ubuntu.sh
  2. 24 6
      setup_testenv_ubuntu.sh

+ 13 - 1
_create_folder_ubuntu.sh

@@ -28,7 +28,7 @@ if [[ $# -lt 1 || -z "$1" ]]; then
 fi
 
 FOLDER_NAME="$1"
-BASE_DIR="/home/josef/Code"
+BASE_DIR="/var/www/html"
 NEW_FOLDER="$BASE_DIR/$FOLDER_NAME"
 
 # Check if target already exists
@@ -84,4 +84,16 @@ setfacl -R -d -m u:"$REGULAR_USER":rwx,u:"$APACHE_USER":rwx "$NEW_FOLDER"
 setfacl -R -m g:"$APACHE_GROUP":r-x "$NEW_FOLDER"
 setfacl -R -d -m g:"$APACHE_GROUP":r-x "$NEW_FOLDER"
 
+# Grant traverse-only (--x) access on every ancestor directory above
+# BASE_DIR (e.g. /home/josef) so Apache can reach it. Required since
+# BASE_DIR lives under a user's home directory, which is typically 750.
+PARENT_DIR="$(dirname "$BASE_DIR")"
+while [[ "$PARENT_DIR" != "/" && -n "$PARENT_DIR" ]]; do
+    if ! sudo -u "$APACHE_USER" test -x "$PARENT_DIR" 2>/dev/null; then
+        setfacl -m u:"$APACHE_USER":--x "$PARENT_DIR"
+        echo "  Granted traverse (--x) access on $PARENT_DIR"
+    fi
+    PARENT_DIR="$(dirname "$PARENT_DIR")"
+done
+
 echo -e "${GREEN}✓ Folder '$FOLDER_NAME' created successfully in $BASE_DIR!${NC}"

+ 24 - 6
setup_testenv_ubuntu.sh

@@ -12,6 +12,12 @@
 
 set -euo pipefail
 
+# ── Configuration ─────────────────────────────────────────────────────────
+DOCROOT="/var/www/html"
+APACHE_USER="www-data"
+APACHE_GROUP="www-data"
+APACHE_CONF="/etc/apache2/conf-available/dev.conf"
+
 # ── Colors for output ─────────────────────────────────────────────────────
 RED='\033[0;31m'
 GREEN='\033[0;32m'
@@ -52,12 +58,6 @@ fi
 echo ""
 echo "Note: sudo commands will prompt for your password if required."
 
-# ── Configuration ─────────────────────────────────────────────────────────
-DOCROOT="/home/josef/Code"
-APACHE_USER="www-data"
-APACHE_GROUP="www-data"
-APACHE_CONF="/etc/apache2/conf-available/dev.conf"
-
 # ── 1. Install Apache, PHP, and required modules ──────────────────────────
 echo ""
 echo "→ Installing Apache (apache2), PHP, and required modules..."
@@ -100,6 +100,24 @@ sudo setfacl -R -d -m g:"$APACHE_GROUP":r-x "$DOCROOT"
 
 echo -e "${GREEN}✓${NC} Permissions configured (ACLs set for $CURRENT_USER and $APACHE_USER)"
 
+# Grant traverse-only (--x) access on every ancestor directory above DOCROOT
+# (e.g. /home/josef) so Apache can reach it. This is required when DOCROOT
+# lives under a user's home directory, since home dirs are typically 750 and
+# ACLs on DOCROOT itself don't help if a parent blocks the path.
+echo ""
+echo "→ Ensuring '$APACHE_USER' can traverse into $DOCROOT..."
+
+PARENT_DIR="$(dirname "$DOCROOT")"
+while [[ "$PARENT_DIR" != "/" && -n "$PARENT_DIR" ]]; do
+    if ! sudo -u "$APACHE_USER" test -x "$PARENT_DIR" 2>/dev/null; then
+        sudo setfacl -m u:"$APACHE_USER":--x "$PARENT_DIR"
+        echo "  Granted traverse (--x) access on $PARENT_DIR"
+    fi
+    PARENT_DIR="$(dirname "$PARENT_DIR")"
+done
+
+echo -e "${GREEN}✓${NC} Traverse access confirmed for $APACHE_USER"
+
 # ── 4. Create/update Apache configuration ─────────────────────────────────
 echo ""
 echo "→ Creating Apache configuration: $APACHE_CONF"