| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #!/bin/bash
- # ============================================================
- # Git Auto Sync Script
- # ============================================================
- # This script configures and pushes code to Gogs repository
- # ============================================================
- set -e
- GOGS_URL="https://git.zhonjin.com:40717/steven_roc"
- REPO_NAME="hikvision-isup-client"
- ACCESS_TOKEN="1942ce3d6478f7a572fee3dd4891e49f6c416aad"
- FULL_URL="${GOGS_URL}/${REPO_NAME}.git"
- echo "=== Git Repository Setup ==="
- echo ""
- # Check if git is installed
- if ! command -v git &> /dev/null; then
- echo "Git is not installed. Installing..."
- sudo apt-get install -y git
- fi
- # Initialize git repository if not already initialized
- if [ ! -d ".git" ]; then
- echo "[1/4] Initializing git repository..."
- git init
- git branch -M main
- echo "Git repository initialized"
- else
- echo "[1/4] Git repository already exists"
- fi
- # Add remote origin with access token
- echo "[2/4] Configuring remote origin..."
- # Remove existing remote if exists
- git remote remove origin 2>/dev/null || true
- # Add remote with credentials in URL
- git remote add origin "https://steven_roc:${ACCESS_TOKEN}@git.zhonjin.com:40717/steven_roc/${REPO_NAME}.git"
- echo "Remote origin added: ${FULL_URL}"
- # Configure git user (if not already configured)
- if ! git config user.name &> /dev/null || [ "$(git config user.name)" = "" ]; then
- git config user.name "steven_roc"
- fi
- if ! git config user.email &> /dev/null || [ "$(git config user.email)" = "" ]; then
- git config user.email "steven_roc@zhonjin.com"
- fi
- # Add all files
- echo "[3/4] Staging files..."
- git add -A
- # Check if there are changes to commit
- if git diff --staged --quiet; then
- echo "No changes to commit"
- else
- # Commit
- echo "[4/4] Committing changes..."
- git commit -m "Initial commit: Hikvision ISUP Client project"
- echo "Changes committed"
-
- # Push to remote
- echo "Pushing to remote..."
- git push -u origin main
-
- echo ""
- echo "=== Git setup complete ==="
- echo "Repository: ${FULL_URL}"
- echo ""
- echo "Future sync commands:"
- echo " git add -A"
- echo " git commit -m 'Your commit message'"
- echo " git push"
- else
- echo "Nothing to push"
- fi
- echo ""
- echo "=== Git setup complete ==="
|