فهرست منبع

Update 'README.md'

rebuilt everything pretty much
computer_glamour 4 هفته پیش
والد
کامیت
a92bb9ec74
1فایلهای تغییر یافته به همراه69 افزوده شده و 2 حذف شده
  1. 69 2
      README.md

+ 69 - 2
README.md

@@ -7,9 +7,76 @@ how to extract webpage from a git repo and then throw it into root of www server
 ```bash
 #!/bin/bash
 
-rm /var/www/root-of-your-page/* -rf
+# Configuration: Define pairs of Repository and Destination
+# Format: REPOS=("repo_path_1" "repo_path_2" ...)
+#         DESTS=("dest_path_1" "dest_path_2" ...)
+# The index of the repo matches the index of the destination.
 
-git --git-dir=/path-to-gogs-install/gogs-repositories/username/repo-name.git archive HEAD | tar -x -C /var/www/root-of-your-page/
+REPOS=(
+    "/home/ubuntu/gogs-repositories/user1/webpage.git"
+    "/home/ubuntu/gogs-repositories/user2/webpage.git"
+    # Add more repos here
+)
+
+DESTS=(
+    "/var/www/user1.glamour.ovh"
+    "/var/www/user2.glamour.ovh"
+    # Add more destinations here (must match count of REPOS)
+)
+
+# Validate that arrays have the same length
+if [ "${#REPOS[@]}" -ne "${#DESTS[@]}" ]; then
+    echo "Error: Number of repositories (${#REPOS[@]}) does not match number of destinations (${#DESTS[@]})."
+    exit 1
+fi
+
+# Iterate through the pairs
+for i in "${!REPOS[@]}"; do
+    REPO="${REPOS[$i]}"
+    DEST="${DESTS[$i]}"
+    
+    echo "----------------------------------------"
+    echo "Deploying: $REPO -> $DEST"
+    
+    # Check if repo exists
+    if [ ! -d "$REPO" ]; then
+        echo "Error: Repository path not found: $REPO"
+        continue
+    fi
+    
+    # Check if destination exists (create if missing)
+    if [ ! -d "$DEST" ]; then
+        echo "Creating destination directory: $DEST"
+        mkdir -p "$DEST"
+    fi
+
+    # Create a temporary directory for this specific deployment
+    TEMP_DIR=$(mktemp -d -t deploy_XXXXXX)
+    
+    # Extract the archive to the temp directory
+    if ! git --git-dir="$REPO" archive HEAD | tar -x -C "$TEMP_DIR/"; then
+        echo "Error: Failed to extract archive for $REPO"
+        rm -rf "$TEMP_DIR"
+        continue
+    fi
+
+    # Sync to destination:
+    # -a: archive mode (preserves permissions, timestamps, etc.)
+    # -v: verbose
+    # --delete: removes files in DEST that are not in the source
+    if rsync -av --delete "$TEMP_DIR/" "$DEST/"; then
+        echo "Successfully deployed $REPO to $DEST"
+        chown -R www-data:www-data "$DEST"
+    else
+        echo "Error: Rsync failed for $REPO"
+    fi
+
+    # Cleanup temp directory
+    rm -rf "$TEMP_DIR"
+done
+
+echo "----------------------------------------"
+echo "Deployment process finished."
 
 ```