mnemo_cards/tools/deploy/fix-git-permissions.sh
2025-11-19 21:13:33 +03:00

82 lines
2.3 KiB
Bash
Executable file

#!/bin/bash
# Script to fix git repository permissions
# Fixes "insufficient permission for adding an object" error
set -e
SERVER_IP="147.45.152.129"
SERVER_USER="root"
REPO_PATH="/home/vscode/cards"
echo "🔧 Fixing git repository permissions on server..."
ssh "$SERVER_USER@$SERVER_IP" << 'EOF'
set -e
REPO_PATH="/home/vscode/cards"
VSCODE_USER="vscode"
echo "📝 Checking current ownership..."
echo "Current ownership of $REPO_PATH:"
ls -la "$REPO_PATH" | head -10
echo ""
echo "🔄 Fixing ownership and permissions..."
# Change ownership of entire repository to vscode user
chown -R $VSCODE_USER:$VSCODE_USER "$REPO_PATH"
# Fix permissions
# Directories: rwxr-xr-x (755)
find "$REPO_PATH" -type d -exec chmod 755 {} \;
# Files: rw-r--r-- (644)
find "$REPO_PATH" -type f -exec chmod 644 {} \;
# Make scripts executable
find "$REPO_PATH" -type f -name "*.sh" -exec chmod 755 {} \;
# Fix .git directory specifically
if [ -d "$REPO_PATH/.git" ]; then
echo "🔐 Fixing .git directory permissions..."
chown -R $VSCODE_USER:$VSCODE_USER "$REPO_PATH/.git"
chmod -R u+rwX "$REPO_PATH/.git"
fi
# Fix all submodules
echo "📦 Fixing submodules if any..."
find "$REPO_PATH" -name ".git" -type d | while read gitdir; do
echo " Fixing: $gitdir"
chown -R $VSCODE_USER:$VSCODE_USER "$gitdir"
chmod -R u+rwX "$gitdir"
done
# Fix common subdirectories
for subdir in mnemo_cards_common mnemo_cards_backend mnemo_cards_web_v2 mnemo_cards_frontend_common; do
if [ -d "$REPO_PATH/$subdir" ]; then
echo " Fixing: $REPO_PATH/$subdir"
chown -R $VSCODE_USER:$VSCODE_USER "$REPO_PATH/$subdir"
if [ -d "$REPO_PATH/$subdir/.git" ]; then
chmod -R u+rwX "$REPO_PATH/$subdir/.git"
fi
fi
done
echo ""
echo "✅ Permissions fixed!"
echo ""
echo "📊 New ownership:"
ls -la "$REPO_PATH" | head -10
echo ""
echo "🧪 Testing git status..."
cd "$REPO_PATH/mnemo_cards_common"
sudo -u $VSCODE_USER git status || echo "Git status check completed"
EOF
echo ""
echo "✅ Done! Git operations should now work without permission errors."
echo "💡 Try running your deployment script again."