This commit is contained in:
Mark Randall Havens 2025-05-30 07:55:02 -05:00
parent f780de2146
commit 7a86f69629
2 changed files with 52 additions and 56 deletions

0
.test4 Normal file
View file

View file

@ -2,12 +2,13 @@
set -euo pipefail set -euo pipefail
IFS=$'\n\t' IFS=$'\n\t'
# ╭─────────────────────────────╮ # ╭───────────────────────────────
# │ Config & Constants # │ Config & Paths
# ╰─────────────────────────────╯ # ╰───────────────────────────────
PROJECT_NAME=$(basename "$(pwd)") PROJECT_NAME=$(basename "$(pwd)")
DEFAULT_NAME="Mark Randall Havens" DEFAULT_NAME="Mark Randall Havens"
DEFAULT_EMAIL="mark.r.havens@gmail.com" DEFAULT_EMAIL="mark.r.havens@gmail.com"
RAD_HOME="$HOME/.radicle" RAD_HOME="$HOME/.radicle"
RAD_BIN="$RAD_HOME/bin/rad" RAD_BIN="$RAD_HOME/bin/rad"
RAD_KEYS="$RAD_HOME/keys.json" RAD_KEYS="$RAD_HOME/keys.json"
@ -16,92 +17,86 @@ RAD_PATH_LINE='export PATH="$HOME/.radicle/bin:$PATH"'
PROFILE_FILE="$HOME/.bashrc" PROFILE_FILE="$HOME/.bashrc"
RAD_PUSH_FILE=".radicle-push-done" RAD_PUSH_FILE=".radicle-push-done"
# ╭─────────────────────────────╮ # ╭───────────────────────────────
# │ Logging │ # │ Logging │
# ╰─────────────────────────────╯ # ╰───────────────────────────────
info() { echo -e "\e[1;34m[INFO]\e[0m $*"; } info() { echo -e "\e[1;34m[INFO]\e[0m $*"; }
warn() { echo -e "\e[1;33m[WARN]\e[0m $*"; } warn() { echo -e "\e[1;33m[WARN]\e[0m $*"; }
error() { echo -e "\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; } error() { echo -e "\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; }
# ╭─────────────────────────────╮ # ╭───────────────────────────────
# │ Git + Tools Check # │ Git + Tools Precheck
# ╰─────────────────────────────╯ # ╰───────────────────────────────
info "Checking Git..." info "Checking Git..."
if ! command -v git &>/dev/null; then command -v git >/dev/null || {
info "Installing Git..." info "Installing Git..."
sudo apt update && sudo apt install -y git || error "Failed to install Git" sudo apt update && sudo apt install -y git || error "Failed to install Git"
fi }
info "Git version: $(git --version)" info "Git version: $(git --version)"
NAME=$(git config --global user.name || true) NAME=$(git config --global user.name || true)
EMAIL=$(git config --global user.email || true) EMAIL=$(git config --global user.email || true)
[[ -z "$NAME" || -z "$EMAIL" ]] && { [[ -z "$NAME" || -z "$EMAIL" ]] && {
info "Configuring Git identity..." info "Setting Git identity..."
git config --global user.name "$DEFAULT_NAME" git config --global user.name "$DEFAULT_NAME"
git config --global user.email "$DEFAULT_EMAIL" git config --global user.email "$DEFAULT_EMAIL"
} }
info "Git identity: $(git config --global user.name) <$(git config --global user.email)>" info "Git identity: $(git config --global user.name) <$(git config --global user.email)>"
# ╭─────────────────────────────╮ # ╭───────────────────────────────
# │ Install Radicle CLI │ # │ Install Radicle CLI │
# ╰─────────────────────────────╯ # ╰───────────────────────────────
if [ ! -x "$RAD_BIN" ]; then if [ ! -x "$RAD_BIN" ]; then
info "Installing Radicle CLI from official script..." info "Installing Radicle CLI..."
sudo apt install -y curl jq unzip || error "Missing dependencies" sudo apt install -y curl jq unzip || error "Missing dependencies"
curl -sSf https://radicle.xyz/install | sh || error "Radicle CLI install failed" curl -sSf https://radicle.xyz/install | sh || error "Radicle install failed"
fi fi
# ╭───────────────────────────────────────────────────────╮ # ─ PATH Setup (Temporary + Persistent)
# │ PATH Handling: Make rad command Just Work™
# ╰───────────────────────────────────────────────────────╯
if ! command -v rad &>/dev/null; then if ! command -v rad &>/dev/null; then
if [[ ":$PATH:" != *":$HOME/.radicle/bin:"* ]]; then
export PATH="$HOME/.radicle/bin:$PATH" export PATH="$HOME/.radicle/bin:$PATH"
info "→ Temporarily patched PATH for this session" info "→ Temporarily patched PATH for this session"
fi fi
fi
if ! grep -Fxq "$RAD_PATH_LINE" "$PROFILE_FILE"; then if ! grep -Fxq "$RAD_PATH_LINE" "$PROFILE_FILE"; then
echo "$RAD_PATH_LINE" >> "$PROFILE_FILE" echo "$RAD_PATH_LINE" >> "$PROFILE_FILE"
info "→ Added PATH to $PROFILE_FILE" info "→ Added PATH to $PROFILE_FILE"
warn "→ Please run: source $PROFILE_FILE (or restart terminal) to make 'rad' globally available." warn "→ Run 'source $PROFILE_FILE' to make 'rad' persistent"
fi fi
if ! command -v rad &>/dev/null; then command -v rad >/dev/null || error "Radicle CLI still unavailable. Try restarting your terminal."
error "'rad' CLI not available. Even after PATH patch. Try opening a new terminal or sourcing ~/.bashrc"
fi
info "Radicle CLI ready: $(rad --version)" info "Radicle CLI ready: $(rad --version)"
# ╭─────────────────────────────╮ # ╭────────────────────────────────────────────────────
# │ Radicle Identity Restore # │ Restore or Create Radicle Identity & Backup
# ╰─────────────────────────────╯ # ╰────────────────────────────────────────────────────
mkdir -p "$(dirname "$RAD_BACKUP")" mkdir -p "$(dirname "$RAD_BACKUP")"
if [ ! -f "$RAD_KEYS" ]; then if [ ! -f "$RAD_KEYS" ]; then
if [ -f "$RAD_BACKUP" ]; then if [ -f "$RAD_BACKUP" ]; then
info "Injecting Radicle identity from backup..." info "Restoring Radicle identity from backup..."
cp "$RAD_BACKUP" "$RAD_KEYS" || error "Failed to restore keys" cp "$RAD_BACKUP" "$RAD_KEYS" || error "Failed to restore identity"
else else
info "Creating new Radicle identity..." info "Creating new Radicle identity..."
rad auth || error "Radicle identity creation failed" rad auth || error "Identity creation failed"
cp "$RAD_KEYS" "$RAD_BACKUP" || warn "Backup of new identity failed" cp "$RAD_KEYS" "$RAD_BACKUP" || warn "Backup of identity failed"
fi fi
else else
info "Radicle identity already present." info "Radicle identity already exists."
fi fi
# ╭─────────────────────────────╮ # ╭───────────────────────────────
# │ Radicle Node Start # │ Start Rad Node
# ╰─────────────────────────────╯ # ╰───────────────────────────────
pgrep -f "rad node start" &>/dev/null || { pgrep -f "rad node start" &>/dev/null || {
info "Starting Radicle node..." info "Starting Radicle node..."
nohup rad node start > /dev/null 2>&1 & nohup rad node start > /dev/null 2>&1 &
sleep 3 sleep 3
} }
# ╭─────────────────────────────╮ # ╭───────────────────────────────
# │ Git Repo Initialization # │ Initialize Git Repo
# ╰─────────────────────────────╯ # ╰───────────────────────────────
if [ ! -d .git ]; then if [ ! -d .git ]; then
git init git init
git add . || warn "Nothing to add" git add . || warn "Nothing to add"
@ -110,34 +105,35 @@ else
info "Git repo already initialized." info "Git repo already initialized."
fi fi
# ╭─────────────────────────────╮ # ╭───────────────────────────────
# │ Radicle Project Init # │ Register Radicle Project │
# ╰─────────────────────────────╯ # ╰───────────────────────────────
if ! rad projects | grep -q "$PROJECT_NAME"; then if ! rad projects | grep -q "$PROJECT_NAME"; then
info "Registering Radicle project '$PROJECT_NAME'..." info "Registering Radicle project '$PROJECT_NAME'..."
rad init --name "$PROJECT_NAME" --description "Radicle sovereign project for $PROJECT_NAME" || warn "Project may already exist" rad init --name "$PROJECT_NAME" --description "Radicle sovereign repo for $PROJECT_NAME" || warn "Repo may already exist"
else else
info "Project '$PROJECT_NAME' already registered." info "Project '$PROJECT_NAME' already registered."
fi fi
# ╭─────────────────────────────╮ # ╭───────────────────────────────╮
# │ Push to the Network │ # │ Push Current Branch │
# ╰─────────────────────────────╯ # ╰───────────────────────────────╯
CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
if [ ! -f "$RAD_PUSH_FILE" ]; then if [ ! -f "$RAD_PUSH_FILE" ]; then
info "Pushing project to Radicle network..." info "Pushing branch '$CURRENT_BRANCH' to Radicle..."
if rad sync; then if git push rad "$CURRENT_BRANCH"; then
touch "$RAD_PUSH_FILE" touch "$RAD_PUSH_FILE"
info "✓ Project replicated successfully." info "✓ Branch '$CURRENT_BRANCH' replicated successfully"
else else
warn "Radicle push failed or already synced." warn "Radicle push failed or already synced"
fi fi
else else
info "Push previously completed. Skipping." info "Push previously completed. Skipping."
fi fi
# ╭─────────────────────────────╮ # ╭───────────────────────────────
# │ Final Output Block # │ Final Output
# ╰─────────────────────────────╯ # ╰───────────────────────────────
PROJECT_ID=$(rad self | grep 'Project ID' | awk '{print $NF}' || true) PROJECT_ID=$(rad self | grep 'Project ID' | awk '{print $NF}' || true)
PEER_ID=$(rad self | grep 'Peer ID' | awk '{print $NF}' || true) PEER_ID=$(rad self | grep 'Peer ID' | awk '{print $NF}' || true)