From 78c072b7dd6c92075e4694c7ee0fc9999550a6ae Mon Sep 17 00:00:00 2001 From: Mark Randall Havens Date: Sat, 31 May 2025 00:28:44 -0500 Subject: [PATCH] updated github --- gitfield-github | 234 +++++++++++++++++++++++++++++------------------- 1 file changed, 141 insertions(+), 93 deletions(-) diff --git a/gitfield-github b/gitfield-github index 903d7fd..aa85439 100755 --- a/gitfield-github +++ b/gitfield-github @@ -2,144 +2,192 @@ set -euo pipefail IFS=$'\n\t' +# ╭─────────────────────────────────────╮ +# │ CONFIGURATION │ +# ╰─────────────────────────────────────╯ GIT_REMOTE_NAME="github" REPO_NAME=$(basename "$(pwd)") DEFAULT_NAME="Mark Randall Havens" DEFAULT_EMAIL="mark.r.havens@gmail.com" +SCRIPT_VERSION="1.0" -# ──────────────── -# Logging Helpers -# ──────────────── +# ╭─────────────────────────────────────╮ +# │ 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 and GitHub CLI Setup -# ──────────────── +# ╭─────────────────────────────────────╮ +# │ TOOLCHAIN 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 +sudo apt update -qq +sudo apt install -y git curl jq openssh-client lsb-release || error "Tool install failed" 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)" + sudo apt update && sudo apt install gh -y || error "GitHub CLI install failed" fi -# ──────────────── -# GitHub Authentication -# ──────────────── +# ╭─────────────────────────────────────╮ +# │ AUTH + IDENTITY │ +# ╰─────────────────────────────────────╯ 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) +git config --global user.name "${DEFAULT_NAME}" +git config --global user.email "${DEFAULT_EMAIL}" -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 -# ──────────────── +# ╭─────────────────────────────────────╮ +# │ SSH + GIT INIT │ +# ╰─────────────────────────────────────╯ 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 "" + ssh-keygen -t ed25519 -C "$DEFAULT_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." + gh ssh-key add "$HOME/.ssh/id_ed25519.pub" --title "$(hostname)" || warn "Manual add may be needed" fi -# ──────────────── -# Initialize Git Repo -# ──────────────── -if [ ! -d ".git" ]; then - info "Initializing Git repo..." +if [ ! -d .git ]; then git init git add . - git commit -m "Initial commit" || warn "Nothing to commit" -else - info "Git repo already initialized." + git commit -m "Initial commit" 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) -# ──────────────── +# ╭─────────────────────────────────────╮ +# │ GITHUB REPO CONFIGURATION │ +# ╰─────────────────────────────────────╯ USERNAME=$(gh api user | jq -r .login) SSH_REMOTE_URL="git@github.com:$USERNAME/$REPO_NAME.git" +WEB_LINK="https://github.com/$USERNAME/$REPO_NAME" 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" + gh repo create "$REPO_NAME" --public --source=. --remote="$GIT_REMOTE_NAME" --push || error "Failed to create 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" +# ╭─────────────────────────────────────╮ +# │ GIT METADATA SNAPSHOT │ +# ╰─────────────────────────────────────╯ +MARKDOWN_FILE=".github-link.md" +TIMESTAMP="$(date '+%Y-%m-%d %H:%M:%S')" +DEFAULT_BRANCH="$(git symbolic-ref --short HEAD)" +REPO_PATH="$(pwd)" +LATEST_SHA=$(git rev-parse HEAD) +LAST_COMMIT_MSG=$(git log -1 --pretty=format:"%s") +LAST_COMMIT_DATE=$(git log -1 --pretty=format:"%ad") +LAST_COMMIT_AUTHOR=$(git log -1 --pretty=format:"%an <%ae>") +TOTAL_COMMITS=$(git rev-list --count HEAD) +TRACKED_FILES=$(git ls-files | wc -l) +UNCOMMITTED=$(if ! git diff --quiet || ! git diff --cached --quiet; then echo "Yes"; else echo "No"; fi) +LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "None") +HOSTNAME=$(hostname) +CURRENT_USER=$(whoami) +TIMEZONE=$(date +%Z) + +# ╭─────────────────────────────────────╮ +# │ HARDWARE + OS FINGERPRINT BLOCK │ +# ╰─────────────────────────────────────╯ +OS_NAME=$(uname -s) +KERNEL_VERSION=$(uname -r) +ARCHITECTURE=$(uname -m) +OS_PRETTY_NAME=$(grep PRETTY_NAME /etc/os-release 2>/dev/null | cut -d= -f2 | tr -d '"') || OS_PRETTY_NAME="Unknown" +DOCKER_CHECK=$(grep -qE '/docker|/lxc' /proc/1/cgroup 2>/dev/null && echo "Yes" || echo "No") +WSL_CHECK=$(grep -qi microsoft /proc/version 2>/dev/null && echo "Yes" || echo "No") +VM_CHECK=$(systemd-detect-virt 2>/dev/null || echo "Unknown") +UPTIME=$(uptime -p 2>/dev/null || echo "Unknown") +MAC_ADDR=$(ip link | awk '/ether/ {print $2}' | head -n 1) +LOCAL_IP=$(hostname -I | awk '{print $1}') +CPU_MODEL=$(grep -m1 'model name' /proc/cpuinfo | cut -d: -f2 | sed 's/^ //') +RAM_GB=$(awk '/MemTotal/ {printf "%.2f", $2/1024/1024}' /proc/meminfo) + +# ╭─────────────────────────────────────╮ +# │ WRITE RICH MARKDOWN ARTIFACT │ +# ╰─────────────────────────────────────╯ +cat > "$MARKDOWN_FILE" </dev/null; then + git push -u "$GIT_REMOTE_NAME" "$DEFAULT_BRANCH" else - info "No uncommitted changes found." + git push "$GIT_REMOTE_NAME" "$DEFAULT_BRANCH" 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" +info "✅ GitHub push complete." +echo -e "\n🔗 View in browser: $WEB_LINK\n"