From 836d3aa8832c1c81ee48970f490876b9e3972d82 Mon Sep 17 00:00:00 2001 From: Mark Randall Havens Date: Fri, 30 May 2025 08:20:08 -0500 Subject: [PATCH] Update: 2025-05-30 08:20:08 --- .radicle-push-state | 2 +- .test | 0 .test2 | 0 .test3 | 0 .test4 | 0 .test5 | 0 .../CLI-ONLY_workflow_bitbucket_ubuntu.md | 134 ++++++++++++++++ gitfield-bitbucket | 144 ++++++++++++++++++ 8 files changed, 279 insertions(+), 1 deletion(-) delete mode 100644 .test delete mode 100644 .test2 delete mode 100644 .test3 delete mode 100644 .test4 delete mode 100644 .test5 create mode 100644 bitbucket/CLI-ONLY_workflow_bitbucket_ubuntu.md create mode 100755 gitfield-bitbucket diff --git a/.radicle-push-state b/.radicle-push-state index 07384f3..5cd3724 100644 --- a/.radicle-push-state +++ b/.radicle-push-state @@ -1 +1 @@ -7a86f69629e6970f3901b93cf50c234f5e04c1c2 +7f0867986f60493d8af56526d727a411dbd96ffd diff --git a/.test b/.test deleted file mode 100644 index e69de29..0000000 diff --git a/.test2 b/.test2 deleted file mode 100644 index e69de29..0000000 diff --git a/.test3 b/.test3 deleted file mode 100644 index e69de29..0000000 diff --git a/.test4 b/.test4 deleted file mode 100644 index e69de29..0000000 diff --git a/.test5 b/.test5 deleted file mode 100644 index e69de29..0000000 diff --git a/bitbucket/CLI-ONLY_workflow_bitbucket_ubuntu.md b/bitbucket/CLI-ONLY_workflow_bitbucket_ubuntu.md new file mode 100644 index 0000000..f15aad7 --- /dev/null +++ b/bitbucket/CLI-ONLY_workflow_bitbucket_ubuntu.md @@ -0,0 +1,134 @@ +## 🧭 FULL CLI-ONLY WORKFLOW (Ubuntu + Bitbucket) + +--- + +### πŸ”Ή Step 1 β€” Install prerequisites + +```bash +# Install Git +sudo apt update +sudo apt install git -y + +# Install cURL and OpenSSH if not already +sudo apt install curl openssh-client -y +``` + +--- + +### πŸ”Ή Step 2 β€” Create a Bitbucket account + +Go to: [https://bitbucket.org/account/signup](https://bitbucket.org/account/signup) + +> You’ll need to verify email, set username, and generate an **App Password** with at least: +> +> * `Repository` (read/write) +> * `SSH` (read/write) + +--- + +### πŸ”Ή Step 3 β€” Set your global Git identity + +```bash +git config --global user.name "Your Name" +git config --global user.email "your_email@example.com" +``` + +--- + +### πŸ”Ή Step 4 β€” Generate and register your SSH key + +```bash +# Generate SSH key (if not already present) +ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/id_rsa -N "" + +# Start SSH agent +eval "$(ssh-agent -s)" + +# Add key to agent +ssh-add ~/.ssh/id_rsa +``` + +Then copy your public key: + +```bash +cat ~/.ssh/id_rsa.pub +``` + +Paste it into: +πŸ” **Bitbucket β†’ Personal settings β†’ SSH keys β†’ Add key** + +--- + +### πŸ”Ή Step 5 β€” Create your local project + +```bash +mkdir myproject +cd myproject +git init +echo "# My Bitbucket Project" > README.md +git add . +git commit -m "Initial commit" +``` + +--- + +### πŸ”Ή Step 6 β€” Create a new Bitbucket repo (via browser) + +Unfortunately, **Bitbucket does not have a CLI tool** for creating repositories. +➑️ Go to: [https://bitbucket.org/repo/create](https://bitbucket.org/repo/create) +Create a **public** or **private** repo named the same as your folder (e.g., `myproject`). + +> Ensure it's an **empty repo** (don’t initialize with README or .gitignore). + +--- + +### πŸ”Ή Step 7 β€” Link local repo to Bitbucket via SSH + +```bash +# Use the SSH format: +git remote add origin git@bitbucket.org:your_username/myproject.git + +# Verify connection +ssh -T git@bitbucket.org +``` + +--- + +### πŸ”Ή Step 8 β€” Push to Bitbucket + +```bash +# Set upstream branch +git push -u origin master # or main +``` + +--- + +### πŸ”Ή Step 9 β€” Make further commits + +```bash +# Edit files +nano something.txt + +# Stage, commit, push +git add . +git commit -m "Updated something" +git push +``` + +--- + +### πŸ”Ή Bonus β€” Clone a Bitbucket repo + +```bash +# Clone using SSH +git clone git@bitbucket.org:your_username/your_repo.git +``` + +--- + +### πŸ”’ Tip β€” Use SSH for all Bitbucket CLI work + +Bitbucket heavily rate-limits HTTPS for CLI usage without app passwords. +Always prefer `SSH` for full CLI-based workflows. + +--- diff --git a/gitfield-bitbucket b/gitfield-bitbucket new file mode 100755 index 0000000..acedb35 --- /dev/null +++ b/gitfield-bitbucket @@ -0,0 +1,144 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + +# ───────────────────────────────────────────── +# β–“β–“ CONFIG +# ───────────────────────────────────────────── +GIT_REMOTE_NAME="bitbucket" +REPO_NAME=$(basename "$(pwd)") +DEFAULT_NAME="Mark Randall Havens" +DEFAULT_EMAIL="mark.r.havens@gmail.com" +USERNAME="mrhavens" +BITBUCKET_API="https://api.bitbucket.org/2.0" +BITBUCKET_SSH="git@bitbucket.org:$USERNAME/$REPO_NAME.git" +TOKEN_FILE="$HOME/.bitbucket_app_password" +SSH_KEY="$HOME/.ssh/id_rsa" +SSH_PUB="$HOME/.ssh/id_rsa.pub" + +# ───────────────────────────────────────────── +# β–“β–“ 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; } + +# ───────────────────────────────────────────── +# β–“β–“ DEPENDENCIES +# ───────────────────────────────────────────── +info "Checking prerequisites..." +sudo apt update -qq +sudo apt install -y git curl jq openssh-client >/dev/null + +# ───────────────────────────────────────────── +# β–“β–“ GIT CONFIGURATION +# ───────────────────────────────────────────── +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)>" + +# ───────────────────────────────────────────── +# β–“β–“ SSH KEY MANAGEMENT +# ───────────────────────────────────────────── +if [ ! -f "$SSH_KEY" ]; then + info "Generating new SSH key..." + ssh-keygen -t rsa -b 4096 -C "$DEFAULT_EMAIL" -f "$SSH_KEY" -N "" +fi + +eval "$(ssh-agent -s)" +ssh-add "$SSH_KEY" || warn "SSH key already loaded" + +# ───────────────────────────────────────────── +# β–“β–“ TEST SSH TO BITBUCKET +# ───────────────────────────────────────────── +info "Testing SSH connection to Bitbucket..." +if ! ssh -o StrictHostKeyChecking=no -T git@bitbucket.org 2>&1 | grep -q "authenticated"; then + PUBKEY=$(<"$SSH_PUB") + echo + warn "SSH key not yet registered with Bitbucket." + echo "πŸ” Please upload the following key manually to:" + echo " https://bitbucket.org/account/settings/ssh-keys/" + echo + echo "$PUBKEY" + echo + read -rp "βœ… Press [Enter] once you've uploaded the key..." +fi + +# ───────────────────────────────────────────── +# β–“β–“ BITBUCKET AUTH (App Password) +# ───────────────────────────────────────────── +if [ ! -f "$TOKEN_FILE" ]; then + echo + echo "πŸ”‘ Create a Bitbucket App Password with:" + echo " βœ… permissions: Repositories (Read+Write), SSH, and Webhooks" + echo " 🌐 https://bitbucket.org/account/settings/app-passwords/" + echo + read -rp "πŸ§‘ Username [$USERNAME]: " input_user + read -rsp "πŸ” App Password: " input_pass && echo + echo "$input_user:$input_pass" > "$TOKEN_FILE" + chmod 600 "$TOKEN_FILE" + info "βœ“ App password stored at $TOKEN_FILE" +fi + +AUTH=$(<"$TOKEN_FILE") +AUTH_HEADER="Authorization: Basic $(echo -n "$AUTH" | base64)" + +# ───────────────────────────────────────────── +# β–“β–“ INIT GIT REPO +# ───────────────────────────────────────────── +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 repository already exists." +fi + +# Ensure HEAD exists +git rev-parse HEAD >/dev/null 2>&1 || { + git add . && git commit -m "Initial commit" || warn "Nothing to commit" +} + +# ───────────────────────────────────────────── +# β–“β–“ CREATE REMOTE REPO +# ───────────────────────────────────────────── +if ! git remote get-url "$GIT_REMOTE_NAME" &>/dev/null; then + info "Creating Bitbucket repository '$REPO_NAME' via API..." + CREATE_RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/bb_create.json \ + -X POST "$BITBUCKET_API/repositories/$USERNAME/$REPO_NAME" \ + -H "$AUTH_HEADER" -H "Content-Type: application/json" \ + -d "{\"scm\": \"git\", \"is_private\": false}") + + HTTP_CODE="${CREATE_RESPONSE:(-3)}" + if [ "$HTTP_CODE" == "200" ] || [ "$HTTP_CODE" == "201" ]; then + info "βœ“ Bitbucket repo created." + else + warn "⚠️ Repo may already exist or failed to create (HTTP $HTTP_CODE)" + fi + + git remote add "$GIT_REMOTE_NAME" "$BITBUCKET_SSH" + info "Remote added: $BITBUCKET_SSH" +else + info "Remote already set: $(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 "Nothing to commit" +else + info "No uncommitted changes." +fi + +BRANCH=$(git symbolic-ref --short HEAD) +if ! git config --get branch."$BRANCH".remote &>/dev/null; then + info "Setting upstream and pushing branch '$BRANCH'..." + 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 + +info "πŸŽ‰ Bitbucket publish complete!"