how to extract webpage from a git repo and then throw it into root of www server
|
|
il y a 4 semaines | |
|---|---|---|
| LICENSE | il y a 1 mois | |
| README.md | il y a 4 semaines |
how to extract webpage from a git repo and then throw it into root of www server
Operations listed below need to be done at the backend of the git server !!!!
#!/bin/bash
# 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.
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."
now run sudo crontab -e and add this to cron
*/5 * * * * /path/to/your/script.sh
This example runs every 5 min