Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# System Scripts

A collection of system administration and development workflow scripts for macOS/Linux environments.
A collection of system administration and development workflow scripts for
macOS/Linux environments.

## 📁 Project Structure

```text
system-scripts/
├── code-backup/ # Repository backup and management
├── git-scripts/ # Git repository utilities
├── tmux/ # Enhanced tmux session management
└── README.md # This file
```
Expand All @@ -30,6 +32,19 @@ Comprehensive repository backup and management system with:
- ✅ Error handling and recovery
- ✅ Progress indicators and reporting

### 🔧 Git Utilities (`git-scripts/`)

Utilities for managing multiple git repositories:

- `sync-all.sh` - Find all git repos in a path and update their default branch

**Key Features:**

- ✅ **Automatic Detection**: Identifies default branch (main/master/HEAD)
- ✅ **Safe Updates**: Skips repositories with uncommitted changes
- ✅ **Recursive Discovery**: Finds all git repos within a given path
- ✅ **Clean Fetch**: Prunes deleted remote branches during fetch

### 🖥️ Tmux Session Management (`tmux/`)

Enhanced tmux session management following bash and tmux best practices:
Expand All @@ -52,21 +67,7 @@ Enhanced tmux session management following bash and tmux best practices:

## 🚀 Quick Start

### Tmux Sessions

```bash
# Start main session (general purpose)
./tmux/setup-main.sh

# Start development session
./tmux/setup-dev.sh

# Use comprehensive manager
./tmux/session-manager.sh main
./tmux/session-manager.sh dev
```

### Code Backup
### Customizing Code Backup

```bash
# Run backup for all repositories
Expand Down Expand Up @@ -112,9 +113,7 @@ All scripts include comprehensive logging:
- Colored output for better visibility
- Timestamped entries with context

## 🔧 Customization

### Tmux Sessions
### Customizing Tmux Sessions

- Modify window layouts in the respective setup scripts
- Add custom commands and working directories
Expand Down
53 changes: 26 additions & 27 deletions code-backup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

This directory contains two scripts for backing up your GitHub repositories:

1. **`code-backup-local.sh`** - Creates a local, zipped directory of all your non-archived projects
2. **`code-backup-gitlab.sh`** - Mirrors all non-archived public and private projects to similarly named GitLab projects
1. **`code-backup-local.sh`** - Creates a local, zipped directory of all your
non-archived projects
2. **`code-backup-gitlab.sh`** - Mirrors all non-archived public and private
projects to similarly named GitLab projects

---

Expand Down Expand Up @@ -94,19 +96,14 @@ chmod +x code-backup-local.sh

---

## 📦 Script 2: GitLab Mirror (`code-backup-gitlab.sh`)

Mirrors all non-archived public and private GitHub repositories to similarly named GitLab projects.

### Features
### GitLab Mirror Features

- Lists all non-archived GitHub repos you can access
- Creates/updates a local mirror clone (bare repo) for each
- Ensures a same-named GitLab project exists under your namespace
- Pushes a full mirror to GitLab (all branches, tags, and refs)
- Automatically creates GitLab projects if they don't exist (optional)

### 🔐 Authentication
### 🔐 GitLab Authentication

**Required environment variables:**

Expand All @@ -121,19 +118,17 @@ export GITLAB_NAMESPACE="your-username" # Your GitLab username or group
export GITHUB_TOKEN="your_github_token" # For private GitHub repos
export GITHUB_USERNAME="your-username" # Auto-detected if token provided
export USE_GITHUB_SSH="true" # Use SSH for GitHub (default: false)
export AUTO_CREATE_GITLAB_PROJECTS="true" # Auto-create missing projects (default: true)
export GITLAB_VISIBILITY="private" # Visibility for new projects: private/internal/public (default: private)
export GITLAB_HOST="https://gitlab.com" # GitLab instance URL (default: gitlab.com)
export BACKUP_ROOT="$HOME/GitHub-GitLab-Backup" # Where to store local mirrors
export AUTO_CREATE_GITLAB_PROJECTS="true" # Auto-create missing
projects (default: true)
export GITLAB_VISIBILITY="private" # Visibility for new
projects: private/internal/public (default: private)
export GITLAB_HOST="https://gitlab.com" # GitLab instance URL
(default: gitlab.com)
export BACKUP_ROOT="$HOME/GitHub-GitLab-Backup" # Where to store local
mirrors
```

### Creating GitLab Token

1. Go to GitLab.com → Settings → Access Tokens
2. Create a token with `api` scope (and `write_repository` if needed)
3. Set it as `GITLAB_TOKEN` environment variable

### Usage
### GitLab Usage

```bash
chmod +x code-backup-gitlab.sh
Expand All @@ -155,9 +150,8 @@ export GITHUB_TOKEN="your_github_token"
- Creates/updates a local bare mirror clone
- Checks if a GitLab project exists (creates it if `AUTO_CREATE_GITLAB_PROJECTS=true`)
- Pushes all branches, tags, and refs to GitLab as a mirror
3. Assumes GitHub and GitLab usernames are the same, and projects have the same name

### Output
### GitLab Output

- **Local mirrors**: `$BACKUP_ROOT/mirrors-YYYYMMDD-HHMMSS/` (bare repos)
- **Logs**: `logs/gh-gl-backup-YYYYMMDD-HHMMSS.log`
Expand Down Expand Up @@ -249,7 +243,8 @@ crontab -e
0 3 * * 0 /path/to/code-backup-gitlab.sh
```

**Note:** When using cron, make sure to set environment variables in your crontab or in a script that sources them:
**Note:** When using cron, make sure to set environment variables in your
crontab or in a script that sources them:

```bash
# In crontab
Expand All @@ -262,12 +257,14 @@ crontab -e

### Repository Filtering

Both scripts only process **non-archived** repositories. Archived repositories are automatically excluded.
Both scripts only process **non-archived** repositories. Archived
repositories are automatically excluded.

### Private Repositories

- **Local backup**: Requires `GITHUB_TOKEN` to access private repos
- **GitLab mirror**: Requires both `GITHUB_TOKEN` (for GitHub) and `GITLAB_TOKEN` (for GitLab)
- **GitLab mirror**: Requires both `GITHUB_TOKEN` (for GitHub) and
`GITLAB_TOKEN` (for GitLab)

### SSH vs HTTPS

Expand All @@ -278,10 +275,12 @@ Both scripts support both SSH and HTTPS for GitHub operations:

### GitLab Project Creation

The GitLab mirror script can automatically create GitLab projects if they don't exist:
The GitLab mirror script can automatically create GitLab projects if they
don't exist:

- Set `AUTO_CREATE_GITLAB_PROJECTS="true"` (default)
- New projects will be created with visibility set by `GITLAB_VISIBILITY` (default: `private`)
- New projects will be created with visibility set by
`GITLAB_VISIBILITY` (default: `private`)

### Submodules

Expand Down
8 changes: 5 additions & 3 deletions code-backup/code-backup-gitlab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ set -euo pipefail
# ----------------------------
# Configuration
# ----------------------------
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly SCRIPT_DIR
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
readonly LOG_DIR="$SCRIPT_DIR/logs"
mkdir -p "$LOG_DIR"

readonly RUN_TS="$(date +%Y%m%d-%H%M%S)"
readonly RUN_TS
RUN_TS=$( date +%Y%m%d-%H%M%S )
readonly LOG_FILE="$LOG_DIR/gh-gl-backup-$RUN_TS.log"
readonly ERROR_LOG="$LOG_DIR/gh-gl-errors-$RUN_TS.log"

Expand Down Expand Up @@ -277,7 +279,7 @@ process_repo() {
local effective_clone_url="$clone_url"
if [ "$USE_GITHUB_SSH" != "true" ] && [ -n "${GITHUB_TOKEN:-}" ]; then
# GitHub supports token auth via x-access-token username.
effective_clone_url="$(echo "$clone_url" | sed "s#https://#https://x-access-token:${GITHUB_TOKEN}@#")"
effective_clone_url="${clone_url//https:\/\//https:\/\/x-access-token:${GITHUB_TOKEN}@\/}"
fi

# Clone/update local mirror
Expand Down
Loading
Loading