For public repos, only minimal git config needed: - Fix corrupted .gitconfig file - Set git user.name and user.email (required by git) - Remove unnecessary SSL and SSH configuration - Fix directory permissions for www-data user - Test git status Removed: - SSH key setup (not needed for public repos) - SSL verification config (not needed for public HTTPS) - HTTPS remote URL configuration (already correct) Updated from 8 steps to 5 simpler steps
93 lines
2.5 KiB
Bash
93 lines
2.5 KiB
Bash
#!/bin/bash
|
|
# Setup script to configure git for www-data user
|
|
# For PUBLIC repositories - no authentication required
|
|
# Run this on your live server as root to fix git pull issues
|
|
|
|
set -e
|
|
|
|
echo "========================================="
|
|
echo "HMS Git Configuration (Public Repo)"
|
|
echo "========================================="
|
|
echo ""
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "ERROR: This script must be run as root"
|
|
echo "Usage: sudo bash setup_git_config.sh"
|
|
exit 1
|
|
fi
|
|
|
|
# Determine web server user
|
|
WEB_USER="www-data"
|
|
if ! id "$WEB_USER" &>/dev/null; then
|
|
echo "ERROR: User '$WEB_USER' not found. Please adjust WEB_USER variable."
|
|
exit 1
|
|
fi
|
|
|
|
# HMS installation directory
|
|
HMS_DIR="/var/www/html/hms_etria"
|
|
if [ ! -d "$HMS_DIR" ]; then
|
|
echo "ERROR: HMS directory not found at $HMS_DIR"
|
|
echo "Please update HMS_DIR in this script"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Configuration Details:"
|
|
echo " Web user: $WEB_USER"
|
|
echo " HMS dir: $HMS_DIR"
|
|
echo " Repo type: PUBLIC (no authentication needed)"
|
|
echo ""
|
|
|
|
# 1. Fix global git config file permissions
|
|
echo "[1/5] Fixing .gitconfig file..."
|
|
if [ -f /var/www/.gitconfig ]; then
|
|
rm -f /var/www/.gitconfig
|
|
echo " Removed corrupted .gitconfig"
|
|
fi
|
|
touch /var/www/.gitconfig
|
|
chown "$WEB_USER:$WEB_USER" /var/www/.gitconfig
|
|
chmod 600 /var/www/.gitconfig
|
|
|
|
# 2. Set minimal git config (name and email required for git)
|
|
echo "[2/5] Setting git user name..."
|
|
sudo -u "$WEB_USER" git config --global user.name "www-data"
|
|
|
|
# 3. Set git email
|
|
echo "[3/5] Setting git email..."
|
|
sudo -u "$WEB_USER" git config --global user.email "deploy@localhost"
|
|
|
|
# 4. Fix directory permissions
|
|
echo "[4/5] Fixing directory permissions..."
|
|
chown -R "$WEB_USER:$WEB_USER" "$HMS_DIR"
|
|
chmod -R 755 "$HMS_DIR"
|
|
chmod -R 755 "$HMS_DIR/.git"
|
|
|
|
# 5. Test git status
|
|
echo "[5/5] Testing git pull..."
|
|
cd "$HMS_DIR"
|
|
if sudo -u "$WEB_USER" git status >/dev/null 2>&1; then
|
|
echo "✓ Git status check PASSED"
|
|
else
|
|
echo "✗ Git status check FAILED"
|
|
sudo -u "$WEB_USER" git status
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "========================================="
|
|
echo "✓ Git setup completed successfully!"
|
|
echo "========================================="
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Go to System Operations panel"
|
|
echo " 2. Click 'Update HMS' button"
|
|
echo " 3. Confirm the git pull action"
|
|
echo ""
|
|
echo "Git configuration:"
|
|
echo " Global: /var/www/.gitconfig"
|
|
echo " Remote: $(cd $HMS_DIR && sudo -u $WEB_USER git config --get remote.origin.url)"
|
|
echo " Branch: main"
|
|
echo ""
|
|
|
|
|