fix: ensure .gitconfig created with www-data ownership from start
- Create .gitconfig as www-data user (not root) - Ensures file has correct owner and permissions from creation - Add fallback to use local repository git config if global fails - Prevents 'could not lock config file' permission errors This fixes the issue where www-data user cannot write to root-owned files
This commit is contained in:
parent
0e597b47da
commit
b5950d48e3
|
|
@ -40,21 +40,34 @@ echo ""
|
||||||
|
|
||||||
# 1. Fix global git config file permissions
|
# 1. Fix global git config file permissions
|
||||||
echo "[1/5] Fixing .gitconfig file..."
|
echo "[1/5] Fixing .gitconfig file..."
|
||||||
if [ -f /var/www/.gitconfig ]; then
|
|
||||||
rm -f /var/www/.gitconfig
|
# Make sure /var/www is writable by www-data
|
||||||
echo " Removed corrupted .gitconfig"
|
chmod 755 /var/www
|
||||||
fi
|
|
||||||
touch /var/www/.gitconfig
|
# Remove corrupted .gitconfig if it exists
|
||||||
chown "$WEB_USER:$WEB_USER" /var/www/.gitconfig
|
[ -f /var/www/.gitconfig ] && rm -f /var/www/.gitconfig
|
||||||
chmod 600 /var/www/.gitconfig
|
|
||||||
|
# Create fresh .gitconfig file and set permissions BEFORE writing
|
||||||
|
sudo -u "$WEB_USER" touch /var/www/.gitconfig
|
||||||
|
sudo -u "$WEB_USER" chmod 600 /var/www/.gitconfig
|
||||||
|
|
||||||
|
echo " Fresh .gitconfig created with www-data ownership"
|
||||||
|
|
||||||
# 2. Set minimal git config (name and email required for git)
|
# 2. Set minimal git config (name and email required for git)
|
||||||
echo "[2/5] Setting git user name..."
|
echo "[2/5] Setting git user name..."
|
||||||
sudo -u "$WEB_USER" git config --global user.name "www-data"
|
if ! sudo -u "$WEB_USER" git config --global user.name "www-data" 2>/dev/null; then
|
||||||
|
echo " Warning: Could not set global config, using local repo config instead"
|
||||||
|
cd "$HMS_DIR"
|
||||||
|
sudo -u "$WEB_USER" git config user.name "www-data"
|
||||||
|
fi
|
||||||
|
|
||||||
# 3. Set git email
|
# 3. Set git email
|
||||||
echo "[3/5] Setting git email..."
|
echo "[3/5] Setting git email..."
|
||||||
sudo -u "$WEB_USER" git config --global user.email "deploy@localhost"
|
if ! sudo -u "$WEB_USER" git config --global user.email "deploy@localhost" 2>/dev/null; then
|
||||||
|
echo " Warning: Could not set global config, using local repo config instead"
|
||||||
|
cd "$HMS_DIR"
|
||||||
|
sudo -u "$WEB_USER" git config user.email "deploy@localhost"
|
||||||
|
fi
|
||||||
|
|
||||||
# 4. Fix directory permissions
|
# 4. Fix directory permissions
|
||||||
echo "[4/5] Fixing directory permissions..."
|
echo "[4/5] Fixing directory permissions..."
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user