Update: 2025-05-30 23:56:58

This commit is contained in:
Mark Randall Havens 2025-05-30 23:56:58 -05:00
parent a56283ca37
commit 68ba28d426
5 changed files with 576 additions and 112 deletions

View file

@ -0,0 +1,152 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# ╭─────────────────────────────────────╮
# │ CONFIGURATION │
# ╰─────────────────────────────────────╯
BITBUCKET_USER="mrhavens"
BITBUCKET_WORKSPACE="thefoldwithin"
REMOTE_NAME="bitbucket"
REPO_NAME=$(basename "$(pwd)")
EMAIL="mark.r.havens@gmail.com"
FULL_NAME="Mark Randall Havens"
APP_PASS_FILE="$HOME/.bitbucket_app_password"
API_URL="https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$REPO_NAME"
SSH_REMOTE="git@bitbucket.org:$BITBUCKET_WORKSPACE/$REPO_NAME.git"
WEB_LINK="https://bitbucket.org/$BITBUCKET_WORKSPACE/$REPO_NAME"
# ╭─────────────────────────────────────╮
# │ LOGGING UTILS │
# ╰─────────────────────────────────────╯
info() { echo -e "\n\e[1;34m[INFO]\e[0m $*"; }
warn() { echo -e "\n\e[1;33m[WARN]\e[0m $*"; }
error() { echo -e "\n\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; }
# ╭─────────────────────────────────────╮
# │ CHECK + INSTALL TOOLS │
# ╰─────────────────────────────────────╯
info "Checking prerequisites..."
sudo apt update -qq
sudo apt install -y git curl jq openssh-client || error "Dependency install failed"
# ╭─────────────────────────────────────╮
# │ GIT IDENTITY SETUP │
# ╰─────────────────────────────────────╯
git config --global user.name "$FULL_NAME"
git config --global user.email "$EMAIL"
info "Git identity: $FULL_NAME <$EMAIL>"
# ╭─────────────────────────────────────╮
# │ SSH KEYGEN + AGENT │
# ╰─────────────────────────────────────╯
if [ ! -f ~/.ssh/id_rsa ]; then
info "Generating new SSH key..."
ssh-keygen -t rsa -b 4096 -C "$EMAIL" -f ~/.ssh/id_rsa -N ""
fi
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa || error "Failed to add SSH key"
ssh-keyscan -t rsa bitbucket.org >> ~/.ssh/known_hosts 2>/dev/null || true
# ╭─────────────────────────────────────╮
# │ SSH AUTH VERIFICATION │
# ╰─────────────────────────────────────╯
info "Verifying SSH access to Bitbucket..."
if ssh -T git@bitbucket.org 2>&1 | grep -q "authenticated"; then
info "✓ SSH access to Bitbucket verified."
else
warn "❌ SSH key not authorized with Bitbucket."
echo "→ Visit: https://bitbucket.org/account/settings/ssh-keys/"
echo "→ Paste this key:"
echo
cat ~/.ssh/id_rsa.pub
echo
exit 1
fi
# ╭─────────────────────────────────────╮
# │ BITBUCKET APP PASSWORD SETUP │
# ╰─────────────────────────────────────╯
if [ ! -f "$APP_PASS_FILE" ]; then
echo
echo "🔐 Create a Bitbucket App Password (repo:admin + write + webhook)"
echo "→ https://bitbucket.org/account/settings/app-passwords/"
read -rsp "Enter Bitbucket App Password (input hidden): " APP_PASS
echo "$APP_PASS" > "$APP_PASS_FILE"
chmod 600 "$APP_PASS_FILE"
echo
info "App password saved at $APP_PASS_FILE"
fi
APP_PASS=$(<"$APP_PASS_FILE")
# ╭─────────────────────────────────────╮
# │ GIT INIT & COMMIT │
# ╰─────────────────────────────────────╯
if [ ! -d .git ]; then
info "Initializing Git repository..."
git init
git add . || warn "Nothing to add"
git commit -m "Initial commit" || warn "Nothing to commit"
else
info "✓ Git repo already initialized."
fi
# ╭─────────────────────────────────────╮
# │ CREATE REMOTE IF NOT EXISTS │
# ╰─────────────────────────────────────╯
REPO_EXISTS=$(curl -s -u "$BITBUCKET_USER:$APP_PASS" "$API_URL" | jq -r '.name // empty')
if [ -z "$REPO_EXISTS" ]; then
info "Creating Bitbucket repository '$REPO_NAME'..."
CREATE_RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/create_resp.txt -u "$BITBUCKET_USER:$APP_PASS" -X POST "$API_URL" \
-H "Content-Type: application/json" \
-d "{\"scm\": \"git\", \"is_private\": false}")
if [[ "$CREATE_RESPONSE" != "200" && "$CREATE_RESPONSE" != "201" ]]; then
cat /tmp/create_resp.txt
error "Failed to create repository (HTTP $CREATE_RESPONSE)"
fi
info "✓ Repository created."
else
info "✓ Remote Bitbucket repo already exists."
fi
# ╭─────────────────────────────────────╮
# │ REMOTE VALIDATION + SETUP │
# ╰─────────────────────────────────────╯
EXPECTED_REMOTE="$SSH_REMOTE"
CURRENT_REMOTE=$(git remote get-url "$REMOTE_NAME" 2>/dev/null || echo "")
if [[ "$CURRENT_REMOTE" != "$EXPECTED_REMOTE" ]]; then
if [ -n "$CURRENT_REMOTE" ]; then
warn "Removing incorrect remote: $CURRENT_REMOTE"
git remote remove "$REMOTE_NAME"
fi
info "Setting correct Bitbucket remote: $EXPECTED_REMOTE"
git remote add "$REMOTE_NAME" "$EXPECTED_REMOTE"
else
info "✓ Remote already correctly set to: $EXPECTED_REMOTE"
fi
# ╭─────────────────────────────────────╮
# │ COMMIT + PUSH LOGIC │
# ╰─────────────────────────────────────╯
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if ! git diff --quiet || ! git diff --cached --quiet; then
git add . && git commit -m "Update: $(date '+%Y-%m-%d %H:%M:%S')" || warn "Nothing to commit"
else
info "No uncommitted changes."
fi
if ! git config --get branch."$BRANCH".remote &>/dev/null; then
info "Pushing with upstream..."
git push -u "$REMOTE_NAME" "$BRANCH" || error "Push failed"
else
info "Pushing to $REMOTE_NAME/$BRANCH..."
git push "$REMOTE_NAME" "$BRANCH" || error "Push failed"
fi
# ╭─────────────────────────────────────╮
# │ FINAL LINK OUTPUT │
# ╰─────────────────────────────────────╯
info "✅ Bitbucket push complete."
echo -e "\n🔗 View in browser: $WEB_LINK\n"

145
.legacy-gitfield/gitfield-github Executable file
View file

@ -0,0 +1,145 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
GIT_REMOTE_NAME="github"
REPO_NAME=$(basename "$(pwd)")
DEFAULT_NAME="Mark Randall Havens"
DEFAULT_EMAIL="mark.r.havens@gmail.com"
# ────────────────
# Logging Helpers
# ────────────────
info() { echo -e "\e[1;34m[INFO]\e[0m $*"; }
warn() { echo -e "\e[1;33m[WARN]\e[0m $*"; }
error() { echo -e "\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; }
# ────────────────
# Git and GitHub CLI Setup
# ────────────────
info "Checking for required tools..."
if ! command -v git &>/dev/null; then
info "Installing Git..."
sudo apt update && sudo apt install git -y || error "Failed to install Git"
else
info "Git already installed: $(git --version)"
fi
if ! command -v gh &>/dev/null; then
info "Installing GitHub CLI..."
sudo apt install curl -y
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture)] signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg https://cli.github.com/packages stable main" | \
sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update && sudo apt install gh -y || error "Failed to install GitHub CLI"
else
info "GitHub CLI already installed: $(gh --version | head -n 1)"
fi
# ────────────────
# GitHub Authentication
# ────────────────
if ! gh auth status &>/dev/null; then
info "Authenticating GitHub CLI..."
gh auth login || error "GitHub authentication failed"
else
info "GitHub CLI authenticated."
fi
# ────────────────
# Git Identity
# ────────────────
USER_NAME=$(git config --global user.name || true)
USER_EMAIL=$(git config --global user.email || true)
if [[ -z "$USER_NAME" || -z "$USER_EMAIL" ]]; then
git config --global user.name "$DEFAULT_NAME"
git config --global user.email "$DEFAULT_EMAIL"
info "Git identity set to: $DEFAULT_NAME <$DEFAULT_EMAIL>"
else
info "Git identity already set to: $USER_NAME <$USER_EMAIL>"
fi
# ────────────────
# Ensure SSH Key Exists
# ────────────────
if [ ! -f "$HOME/.ssh/id_ed25519" ]; then
warn "SSH key not found. Generating a new one..."
read -rp "[PROMPT] Enter your GitHub email: " SSH_EMAIL
ssh-keygen -t ed25519 -C "$SSH_EMAIL" -f "$HOME/.ssh/id_ed25519" -N ""
eval "$(ssh-agent -s)"
ssh-add "$HOME/.ssh/id_ed25519"
info "Public key:"
cat "$HOME/.ssh/id_ed25519.pub"
info "Now adding key to GitHub..."
gh ssh-key add "$HOME/.ssh/id_ed25519.pub" --title "$(hostname)" || warn "You may need to add it manually"
else
info "SSH key already exists."
fi
# ────────────────
# Initialize Git Repo
# ────────────────
if [ ! -d ".git" ]; then
info "Initializing Git repo..."
git init
git add .
git commit -m "Initial commit" || warn "Nothing to commit"
else
info "Git repo already initialized."
fi
# ────────────────
# Ensure First Commit
# ────────────────
if ! git rev-parse HEAD &>/dev/null; then
git add .
git commit -m "Initial commit" || warn "Nothing to commit"
fi
# ────────────────
# Setup GitHub Remote (SSH)
# ────────────────
USERNAME=$(gh api user | jq -r .login)
SSH_REMOTE_URL="git@github.com:$USERNAME/$REPO_NAME.git"
if ! git remote get-url "$GIT_REMOTE_NAME" &>/dev/null; then
if gh repo view "$USERNAME/$REPO_NAME" &>/dev/null; then
info "Linking to existing GitHub repo via SSH..."
git remote add "$GIT_REMOTE_NAME" "$SSH_REMOTE_URL"
else
info "Creating GitHub repo..."
gh repo create "$REPO_NAME" --public --source=. --remote="$GIT_REMOTE_NAME" --push || error "Failed to create GitHub repo"
fi
else
info "Remote '$GIT_REMOTE_NAME' already set."
git remote set-url "$GIT_REMOTE_NAME" "$SSH_REMOTE_URL"
fi
# ────────────────
# Commit Changes
# ────────────────
if ! git diff --quiet || ! git diff --cached --quiet; then
info "Changes detected — committing..."
git add .
git commit -m "Update: $(date '+%Y-%m-%d %H:%M:%S')" || warn "Nothing to commit"
else
info "No uncommitted changes found."
fi
# ────────────────
# Push via SSH
# ────────────────
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if ! git config --get branch."$BRANCH".remote &>/dev/null; then
info "Setting upstream and pushing..."
git push -u "$GIT_REMOTE_NAME" "$BRANCH" || error "Push failed"
else
info "Pushing via SSH to '$GIT_REMOTE_NAME'..."
git push "$GIT_REMOTE_NAME" "$BRANCH" || error "Push failed"
fi
info "✅ Sync complete: $SSH_REMOTE_URL"

140
.legacy-gitfield/gitfield-gitlab Executable file
View file

@ -0,0 +1,140 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# ────────────────
# Configuration
# ────────────────
GIT_REMOTE_NAME="gitlab"
REPO_NAME=$(basename "$(pwd)")
DEFAULT_NAME="Mark Randall Havens"
DEFAULT_EMAIL="mark.r.havens@gmail.com"
GITLAB_WEB="https://gitlab.com"
GITLAB_API="$GITLAB_WEB/api/v4"
GITLAB_SSH="git@gitlab.com"
TOKEN_FILE="$HOME/.gitfield_token"
# ────────────────
# Logging
# ────────────────
info() { echo -e "\e[1;34m[INFO]\e[0m $*"; }
warn() { echo -e "\e[1;33m[WARN]\e[0m $*"; }
error() { echo -e "\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; }
# ────────────────
# Token Handling
# ────────────────
RESET_TOKEN=false
if [[ "${1:-}" == "--reset-token" ]]; then
RESET_TOKEN=true
rm -f "$TOKEN_FILE"
info "Token reset requested."
fi
if [ -f "$TOKEN_FILE" ] && [ "$RESET_TOKEN" = false ]; then
TOKEN=$(<"$TOKEN_FILE")
info "Using cached token from $TOKEN_FILE"
else
echo
echo "🔐 Paste your GitLab Personal Access Token (scopes: api, read_user, write_repository, write_ssh_key)"
echo "→ Generate at: $GITLAB_WEB/-/user_settings/personal_access_tokens"
read -rp "🔑 Token: " TOKEN
echo "$TOKEN" > "$TOKEN_FILE"
chmod 600 "$TOKEN_FILE"
info "Token saved for future use at $TOKEN_FILE"
fi
# ────────────────
# Git Identity
# ────────────────
git config --global user.name "$DEFAULT_NAME"
git config --global user.email "$DEFAULT_EMAIL"
info "Git identity set to: $DEFAULT_NAME <$DEFAULT_EMAIL>"
# ────────────────
# Git Init
# ────────────────
if [ ! -d .git ]; then
info "Initializing Git repository..."
git init
git add . || warn "Nothing to add"
git commit -m "Initial commit" || warn "Nothing to commit"
else
info "Git repo already initialized."
fi
if ! git rev-parse HEAD &>/dev/null; then
git add . && git commit -m "Initial commit" || warn "Nothing to commit"
fi
# ────────────────
# SSH Key Setup
# ────────────────
if [ ! -f ~/.ssh/id_rsa ]; then
info "Generating new SSH key..."
ssh-keygen -t rsa -b 4096 -C "$DEFAULT_EMAIL" -f ~/.ssh/id_rsa -N "" || error "SSH keygen failed"
fi
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa || error "Failed to add SSH key"
# ────────────────
# Username from GitLab
# ────────────────
USERNAME=$(curl -s --header "PRIVATE-TOKEN: $TOKEN" "$GITLAB_API/user" | grep -oP '(?<="username":")[^"]*') || {
error "Failed to retrieve GitLab username — invalid token?"
}
info "GitLab username: $USERNAME"
# ────────────────
# Upload SSH Key if Needed
# ────────────────
if ! ssh -T "$GITLAB_SSH" 2>&1 | grep -q "Welcome"; then
PUBKEY=$(<~/.ssh/id_rsa.pub)
TITLE="AutoKey-$(hostname)-$(date +%s)"
info "Uploading SSH key to GitLab..."
curl -s --fail -X POST "$GITLAB_API/user/keys" \
-H "PRIVATE-TOKEN: $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"title\": \"$TITLE\", \"key\": \"$PUBKEY\"}" || warn "SSH key upload may have failed"
sleep 2
fi
# ────────────────
# Create GitLab Repo (Graceful Fallback)
# ────────────────
if ! git remote get-url "$GIT_REMOTE_NAME" &>/dev/null; then
info "Creating GitLab repository '$REPO_NAME'..."
if curl -s --fail -X POST "$GITLAB_API/projects" \
-H "PRIVATE-TOKEN: $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"name\": \"$REPO_NAME\", \"visibility\": \"public\"}" | grep -q '"ssh_url_to_repo":'; then
info "Repository created."
else
warn "Repo may already exist or creation failed — continuing..."
fi
REMOTE_URL="$GITLAB_SSH:$USERNAME/$REPO_NAME.git"
git remote add "$GIT_REMOTE_NAME" "$REMOTE_URL"
info "Remote set to: $REMOTE_URL"
else
info "Remote already configured: $(git remote get-url "$GIT_REMOTE_NAME")"
fi
# ────────────────
# Commit & Push
# ────────────────
if ! git diff --quiet || ! git diff --cached --quiet; then
git add . && git commit -m "Update: $(date '+%Y-%m-%d %H:%M:%S')" || warn "No changes"
else
info "No uncommitted changes."
fi
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if ! git config --get branch."$BRANCH".remote &>/dev/null; then
info "Pushing with upstream..."
git push -u "$GIT_REMOTE_NAME" "$BRANCH" || error "Push failed"
else
info "Pushing to $GIT_REMOTE_NAME/$BRANCH..."
git push "$GIT_REMOTE_NAME" "$BRANCH" || error "Push failed"
fi

139
.legacy-gitfield/gitfield-radicle Executable file
View file

@ -0,0 +1,139 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# ╭───────────────────────────────╮
# │ Config & Paths │
# ╰───────────────────────────────╯
PROJECT_NAME=$(basename "$(pwd)")
DEFAULT_NAME="Mark Randall Havens"
DEFAULT_EMAIL="mark.r.havens@gmail.com"
RAD_HOME="$HOME/.radicle"
RAD_BIN="$RAD_HOME/bin/rad"
RAD_KEYS="$RAD_HOME/keys.json"
RAD_BACKUP=".radicle-backup/keys.json"
RAD_PATH_LINE='export PATH="$HOME/.radicle/bin:$PATH"'
PROFILE_FILE="$HOME/.bashrc"
PUSH_STATE_FILE=".radicle-push-state"
# ╭───────────────────────────────╮
# │ Logging Utils │
# ╰───────────────────────────────╯
info() { echo -e "\e[1;34m[INFO]\e[0m $*"; }
warn() { echo -e "\e[1;33m[WARN]\e[0m $*"; }
error() { echo -e "\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; }
# ╭───────────────────────────────╮
# │ Git + Tools Precheck │
# ╰───────────────────────────────╯
info "Checking Git..."
command -v git >/dev/null || {
info "Installing Git..."
sudo apt update && sudo apt install -y git || error "Failed to install Git"
}
info "Git version: $(git --version)"
NAME=$(git config --global user.name || true)
EMAIL=$(git config --global user.email || true)
[[ -z "$NAME" || -z "$EMAIL" ]] && {
info "Setting Git identity..."
git config --global user.name "$DEFAULT_NAME"
git config --global user.email "$DEFAULT_EMAIL"
}
info "Git identity: $(git config --global user.name) <$(git config --global user.email)>"
# ╭───────────────────────────────╮
# │ Radicle CLI Setup │
# ╰───────────────────────────────╯
if [ ! -x "$RAD_BIN" ]; then
info "Installing Radicle CLI..."
sudo apt install -y curl jq unzip || error "Missing dependencies"
curl -sSf https://radicle.xyz/install | sh || error "Radicle install failed"
fi
export PATH="$HOME/.radicle/bin:$PATH"
if ! grep -Fxq "$RAD_PATH_LINE" "$PROFILE_FILE"; then
echo "$RAD_PATH_LINE" >> "$PROFILE_FILE"
info "→ Added PATH to $PROFILE_FILE"
warn "→ Run 'source $PROFILE_FILE' to make Radicle CLI persistent"
fi
command -v rad >/dev/null || error "Radicle CLI still unavailable. Try restarting terminal."
info "Radicle CLI ready: $(rad --version)"
# ╭────────────────────────────────────────────────────╮
# │ Restore or Create Radicle Identity & Backup │
# ╰────────────────────────────────────────────────────╯
mkdir -p "$(dirname "$RAD_BACKUP")"
if [ ! -f "$RAD_KEYS" ]; then
if [ -f "$RAD_BACKUP" ]; then
info "Restoring Radicle identity from backup..."
cp "$RAD_BACKUP" "$RAD_KEYS" || error "Failed to restore identity"
else
info "Creating new Radicle identity..."
rad auth || error "Identity creation failed"
cp "$RAD_KEYS" "$RAD_BACKUP" || warn "Backup of identity failed"
fi
else
info "Radicle identity already exists."
fi
# ╭───────────────────────────────╮
# │ Start Rad Node │
# ╰───────────────────────────────╯
pgrep -f "rad node start" >/dev/null || {
info "Starting Radicle node..."
nohup rad node start > /dev/null 2>&1 &
sleep 3
}
# ╭───────────────────────────────╮
# │ Git Repo Initialization │
# ╰───────────────────────────────╯
if [ ! -d .git ]; then
git init
git add . || warn "Nothing to add"
git commit -m "Initial commit" || warn "Nothing to commit"
else
info "Git repo already initialized."
fi
# ╭───────────────────────────────╮
# │ Radicle Project Registration│
# ╰───────────────────────────────╯
if ! rad projects | grep -q "$PROJECT_NAME"; then
info "Registering Radicle project '$PROJECT_NAME'..."
rad init --name "$PROJECT_NAME" --description "Radicle sovereign repo for $PROJECT_NAME" || warn "Repo may already exist"
else
info "Project '$PROJECT_NAME' already registered."
fi
# ╭───────────────────────────────╮
# │ Push Current Commit Logic │
# ╰───────────────────────────────╯
CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
CURRENT_COMMIT=$(git rev-parse HEAD)
LAST_PUSHED_COMMIT=$(cat "$PUSH_STATE_FILE" 2>/dev/null || echo "none")
if [[ "$CURRENT_COMMIT" == "$LAST_PUSHED_COMMIT" ]]; then
info "✓ Already pushed commit: $CURRENT_COMMIT"
else
info "Pushing commit '$CURRENT_COMMIT' on branch '$CURRENT_BRANCH'..."
if git push rad "$CURRENT_BRANCH"; then
echo "$CURRENT_COMMIT" > "$PUSH_STATE_FILE"
info "✓ Pushed to Radicle successfully"
else
warn "Push may have failed — check 'rad sync status'"
fi
fi
# ╭───────────────────────────────╮
# │ Final Output Block │
# ╰───────────────────────────────╯
PROJECT_ID=$(rad self | grep 'Project ID' | awk '{print $NF}' || true)
PEER_ID=$(rad self | grep 'Peer ID' | awk '{print $NF}' || true)
[[ -n "$PROJECT_ID" ]] && info "✓ Project ID: $PROJECT_ID"
[[ -n "$PEER_ID" ]] && info "→ Peer ID: $PEER_ID (Share to connect)"

112
gitfield
View file

@ -1,112 +0,0 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# ╭───────────────────────────────╮
# │ Configuration │
# ╰───────────────────────────────╯
CONFIG_DIR="$HOME/.gitfield"
CONFIG_FILE="$CONFIG_DIR/config"
REPO_NAME=$(basename "$(pwd)")
DEFAULT_NAME="Mark Randall Havens"
DEFAULT_EMAIL="mark.r.havens@gmail.com"
# ╭───────────────────────────────╮
# │ Logging Utils │
# ╰───────────────────────────────╯
info() { echo -e "\e[1;34m[INFO]\e[0m $*"; }
warn() { echo -e "\e[1;33m[WARN]\e[0m $*"; }
error() { echo -e "\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; }
# ╭───────────────────────────────╮
# │ Shared Functions │
# ╰───────────────────────────────╯
setup_git() {
command -v git >/dev/null || { sudo apt update && sudo apt install -y git || error "Git install failed"; }
git config --global user.name "$DEFAULT_NAME"
git config --global user.email "$DEFAULT_EMAIL"
[ -d .git ] || { git init; git add .; git commit -m "Initial commit" || warn "Nothing to commit"; }
}
setup_ssh() {
[ -f ~/.ssh/id_ed25519 ] || {
ssh-keygen -t ed25519 -C "$DEFAULT_EMAIL" -f ~/.ssh/id_ed25519 -N ""
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
}
}
commit_changes() {
if ! git diff --quiet || ! git diff --cached --quiet; then
git add . && git commit -m "Update: $(date '+%Y-%m-%d %H:%M:%S')" || warn "Nothing to commit"
else
info "No uncommitted changes."
fi
}
# ╭───────────────────────────────╮
# │ Platform Functions │
# ╰───────────────────────────────╯
bitbucket_init() {
local user workspace app_pass_file remote web_url
user=$(grep -A4 "\[bitbucket\]" "$CONFIG_FILE" | grep "username" | cut -d'=' -f2)
workspace=$(grep -A4 "\[bitbucket\]" "$CONFIG_FILE" | grep "workspace" | cut -d'=' -f2)
app_pass_file=$(grep -A4 "\[bitbucket\]" "$CONFIG_FILE" | grep "app_password_file" | cut -d'=' -f2)
remote=$(grep -A4 "\[bitbucket\]" "$CONFIG_FILE" | grep "remote" | cut -d'=' -f2)
web_url=$(grep -A4 "\[bitbucket\]" "$CONFIG_FILE" | grep "web_url" | cut -d'=' -f2)
# Bitbucket-specific setup (e.g., app password, repo creation)
# ...
info "Bitbucket: $(git remote get-url "$remote" 2>/dev/null || echo "Not set")"
info "Web: $(printf "$web_url" "$REPO_NAME")"
}
github_init() {
# Similar setup for GitHub
# ...
}
gitlab_init() {
# Similar setup for GitLab
# ...
}
radicle_init() {
# Similar setup for Radicle
# ...
}
# ╭───────────────────────────────╮
# │ Main Logic │
# ╰───────────────────────────────╯
mkdir -p "$CONFIG_DIR"
[ -f "$CONFIG_FILE" ] || { echo "[bitbucket]\n...\n[github]\n...\n[gitlab]\n...\n[radicle]\n..." > "$CONFIG_FILE"; }
case "${1:-status}" in
status)
setup_git
info "Git Repository Status"
git status --short
info "Branch: $(git rev-parse --abbrev-ref HEAD)"
info "Configured Remotes"
bitbucket_init
github_init
gitlab_init
radicle_init
;;
push)
setup_git
setup_ssh
commit_changes
bitbucket_push
github_push
gitlab_push
radicle_push
info "All remotes synced."
;;
configure)
# Prompt for credentials and update $CONFIG_FILE
;;
*)
error "Usage: gitfield [status|push|configure]"
;;
esac