simplify: optimize setup script for public repositories
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
This commit is contained in:
parent
a01771fa4d
commit
0e597b47da
|
|
@ -1,11 +1,12 @@
|
|||
#!/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 Setup Script"
|
||||
echo "HMS Git Configuration (Public Repo)"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
|
|
@ -34,73 +35,58 @@ 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/8] Fixing .gitconfig file permissions..."
|
||||
echo "[1/5] Fixing .gitconfig file..."
|
||||
if [ -f /var/www/.gitconfig ]; then
|
||||
rm -f /var/www/.gitconfig
|
||||
echo " Removed corrupted .gitconfig file"
|
||||
echo " Removed corrupted .gitconfig"
|
||||
fi
|
||||
|
||||
# Create fresh .gitconfig with correct permissions
|
||||
touch /var/www/.gitconfig
|
||||
chown "$WEB_USER:$WEB_USER" /var/www/.gitconfig
|
||||
chmod 600 /var/www/.gitconfig
|
||||
echo " Created fresh .gitconfig with correct permissions"
|
||||
|
||||
# 2. Create .ssh directory for www-data if it doesn't exist
|
||||
echo "[2/8] Creating .ssh directory for $WEB_USER..."
|
||||
sudo -u "$WEB_USER" mkdir -p /var/www/.ssh
|
||||
sudo -u "$WEB_USER" chmod 700 /var/www/.ssh
|
||||
# 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. Configure git user name
|
||||
echo "[3/8] Configuring git user name..."
|
||||
sudo -u "$WEB_USER" git config --global user.name "HMS Deploy User"
|
||||
# 3. Set git email
|
||||
echo "[3/5] Setting git email..."
|
||||
sudo -u "$WEB_USER" git config --global user.email "deploy@localhost"
|
||||
|
||||
# 4. Configure git email
|
||||
echo "[4/8] Configuring git email..."
|
||||
sudo -u "$WEB_USER" git config --global user.email "deploy@hms.local"
|
||||
|
||||
# 5. Disable SSL verification (for HTTPS repos)
|
||||
echo "[5/8] Configuring git SSL settings..."
|
||||
sudo -u "$WEB_USER" git config --global http.sslVerify false
|
||||
|
||||
# 6. Set git to use HTTPS instead of SSH (easier for automated deploys)
|
||||
echo "[6/8] Configuring git to use HTTPS..."
|
||||
cd "$HMS_DIR"
|
||||
sudo -u "$WEB_USER" git remote set-url origin https://github.com/infodevsofttech-admin/devsofttech_hms_ci4.git
|
||||
|
||||
# 7. Fix directory permissions
|
||||
echo "[7/8] Fixing directory permissions..."
|
||||
# 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"
|
||||
|
||||
# 8. Test git status
|
||||
echo "[8/8] Testing git status..."
|
||||
# 5. Test git status
|
||||
echo "[5/5] Testing git pull..."
|
||||
cd "$HMS_DIR"
|
||||
if sudo -u "$WEB_USER" git status &>/dev/null; then
|
||||
if sudo -u "$WEB_USER" git status >/dev/null 2>&1; then
|
||||
echo "✓ Git status check PASSED"
|
||||
else
|
||||
echo "✗ Git status check FAILED"
|
||||
echo " Running git status with error output:"
|
||||
sudo -u "$WEB_USER" git status
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "========================================="
|
||||
echo "✓ Git configuration completed successfully!"
|
||||
echo "✓ Git setup completed successfully!"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
echo "You can now use the 'Update HMS' button in System Operations panel"
|
||||
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 stored at:"
|
||||
echo "Git configuration:"
|
||||
echo " Global: /var/www/.gitconfig"
|
||||
echo " Local: $HMS_DIR/.git/config"
|
||||
echo ""
|
||||
echo "To verify configuration, run:"
|
||||
echo " sudo -u www-data git config --list"
|
||||
echo " Remote: $(cd $HMS_DIR && sudo -u $WEB_USER git config --get remote.origin.url)"
|
||||
echo " Branch: main"
|
||||
echo ""
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user