From 77a32d1c744a2f07c006a408432a8bbdcbdf154c Mon Sep 17 00:00:00 2001 From: Mark Randall Havens Date: Thu, 5 Jun 2025 02:13:17 -0500 Subject: [PATCH] Post-Radicle sync at 2025-06-05 02:13:16 --- .gitfield/.radicle-push-state | 2 +- .gitfield/pushed.log | 1 + INSTALL.sh | 142 ++++++++++++++++++++++ bin/gitfield-sync | 30 +++-- bin/gitfield-sync-old2 | 218 ++++++++++++++++++++++++++++++++++ 5 files changed, 380 insertions(+), 13 deletions(-) create mode 100755 INSTALL.sh create mode 100755 bin/gitfield-sync-old2 diff --git a/.gitfield/.radicle-push-state b/.gitfield/.radicle-push-state index d5dd6b7..9da0e70 100644 --- a/.gitfield/.radicle-push-state +++ b/.gitfield/.radicle-push-state @@ -1 +1 @@ -eed9c3f4ef38c40e5793f456b368f5229f2fe790 +1ea5ad28fc753a8891b807185c55c02460764696 diff --git a/.gitfield/pushed.log b/.gitfield/pushed.log index 5cc989a..7e10c4c 100644 --- a/.gitfield/pushed.log +++ b/.gitfield/pushed.log @@ -192,3 +192,4 @@ [2025-06-05 01:10:26] GitLab: https://gitlab.com/mrhavens/git-sigil [2025-06-05 01:10:42] Bitbucket: https://bitbucket.org/thefoldwithin/git-sigil [2025-06-05 01:10:56] GitHub: https://github.com/mrhavens/git-sigil +[2025-06-05 02:13:17] Radicle: https://app.radicle.xyz/nodes/ash.radicle.garden/rad:z45QC21eWL1F43VSbnV9AZbCZrHQJ diff --git a/INSTALL.sh b/INSTALL.sh new file mode 100755 index 0000000..e6c1d94 --- /dev/null +++ b/INSTALL.sh @@ -0,0 +1,142 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + +# ╭─────────────────────────────────────╮ +# │ CONFIGURATION │ +# ╰─────────────────────────────────────╮ +REPO_PATH=$(git rev-parse --show-toplevel 2>/dev/null) || { echo -e "\e[1;31m[ERROR]\e[0m Not inside a Git repository" >&2; exit 1; } +BIN_DIR="$REPO_PATH/bin" +INSTALL_DIR="$HOME/.local/gitfieldbin" +TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S') +SCRIPT_VERSION="1.0" + +# ╭─────────────────────────────────────╮ +# │ LOGGING UTILS │ +# ╰─────────────────────────────────────╮ +info() { echo -e "\e[1;34m[INFO]\e[0m $*" >&2; } +warn() { echo -e "\e[1;33m[WARN]\e[0m $*" >&2; } +error() { echo -e "\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; } + +# ╭─────────────────────────────────────╮ +# │ DETECT SHELL CONFIG │ +# ╰─────────────────────────────────────╮ +detect_shell_config() { + local shell_name=$(basename "$SHELL") + case "$shell_name" in + bash) + if [[ -f "$HOME/.bash_profile" && "$(uname)" == "Darwin" ]]; then + echo "$HOME/.bash_profile" + else + echo "$HOME/.bashrc" + fi + ;; + zsh) + echo "$HOME/.zshrc" + ;; + *) + warn "Unsupported shell: $shell_name. Defaulting to ~/.bashrc" + echo "$HOME/.bashrc" + ;; + esac +} + +# ╭─────────────────────────────────────╮ +# │ UPDATE PATH FUNCTION │ +# ╰─────────────────────────────────────╮ +update_path() { + local config_file=$1 + local path_entry="export PATH=\$PATH:$INSTALL_DIR" + + # Check for duplicate PATH entries in the config file + if [[ -f "$config_file" ]]; then + # Remove any existing entries for INSTALL_DIR + sed -i.bak "/export PATH=.*$INSTALL_DIR/d" "$config_file" && rm -f "$config_file.bak" + info "Removed any existing $INSTALL_DIR entries from $config_file" + fi + + # Check if PATH already contains INSTALL_DIR in the current session + if [[ ":$PATH:" == *":$INSTALL_DIR:"* ]]; then + info "$INSTALL_DIR is already in PATH for the current session" + else + info "Adding $INSTALL_DIR to PATH in current session" + export PATH="$PATH:$INSTALL_DIR" + fi + + # Add new PATH entry to config file + info "Adding $INSTALL_DIR to $config_file" + echo "" >> "$config_file" + echo "# Added by git-sigil INSTALL.sh at $TIMESTAMP" >> "$config_file" + echo "$path_entry" >> "$config_file" +} + +# ╭─────────────────────────────────────╮ +# │ INSTALL SCRIPTS │ +# ╰─────────────────────────────────────╮ +install_scripts() { + info "Installing scripts from $BIN_DIR to $INSTALL_DIR..." + + # Create installation directory if it doesn't exist + mkdir -p "$INSTALL_DIR" || error "Failed to create $INSTALL_DIR" + + # Check if bin directory exists and contains scripts + if [[ ! -d "$BIN_DIR" ]]; then + error "Directory $BIN_DIR does not exist" + fi + + # Copy all executable files from BIN_DIR to INSTALL_DIR + local found_scripts=false + for script in "$BIN_DIR"/*; do + if [[ -f "$script" && -x "$script" ]]; then + found_scripts=true + local script_name=$(basename "$script") + info "Installing $script_name to $INSTALL_DIR..." + cp -f "$script" "$INSTALL_DIR/" || error "Failed to install $script_name" + chmod +x "$INSTALL_DIR/$script_name" || error "Failed to set executable permissions for $script_name" + fi + done + + if [[ "$found_scripts" == false ]]; then + warn "No executable scripts found in $BIN_DIR" + fi + + # Verify and fix permissions for all installed scripts + info "Verifying executable permissions in $INSTALL_DIR..." + for script in "$INSTALL_DIR"/*; do + if [[ -f "$script" && ! -x "$script" ]]; then + warn "Script $script is not executable, fixing permissions..." + chmod +x "$script" || error "Failed to set executable permissions for $script" + fi + done +} + +# ╭─────────────────────────────────────╮ +# │ MAIN EXECUTION │ +# ╰─────────────────────────────────────╮ +info "Starting git-sigil installation at $TIMESTAMP..." + +# Install scripts +install_scripts + +# Detect shell configuration file +CONFIG_FILE=$(detect_shell_config) +info "Detected shell configuration file: $CONFIG_FILE" + +# Create config file if it doesn't exist +if [[ ! -f "$CONFIG_FILE" ]]; then + warn "$CONFIG_FILE does not exist, creating it..." + touch "$CONFIG_FILE" || error "Failed to create $CONFIG_FILE" +fi + +# Update PATH in configuration file and current session +update_path "$CONFIG_FILE" + +# Source the configuration file to update the current session +info "Sourcing $CONFIG_FILE to update current session..." +# shellcheck disable=SC1090 +source "$CONFIG_FILE" || warn "Failed to source $CONFIG_FILE, but PATH will be updated on next login" + +info "✅ Installation completed successfully." +info "🔗 Scripts installed to: $INSTALL_DIR" +info "🔗 PATH updated in: $CONFIG_FILE" +info "🔗 You can now run the installed scripts (e.g., gitfield-sync) from anywhere." diff --git a/bin/gitfield-sync b/bin/gitfield-sync index 5dbb47a..3d39c6f 100755 --- a/bin/gitfield-sync +++ b/bin/gitfield-sync @@ -4,7 +4,7 @@ IFS=$'\n\t' # ╭─────────────────────────────────────╮ # │ CONFIGURATION │ -# ╰─────────────────────────────────────╯ +# ╰─────────────────────────────────────╮ REPO_PATH=$(git rev-parse --show-toplevel 2>/dev/null) || error "Not inside a Git repository" REPO_NAME=$(basename "$REPO_PATH") GITFIELD_DIR="$REPO_PATH/.gitfield" @@ -23,8 +23,8 @@ RADICLE_URL="https://app.radicle.xyz/nodes/ash.radicle.garden/rad:$RADICLE_PROJE # ╭─────────────────────────────────────╮ # │ LOGGING UTILS │ # ╰─────────────────────────────────────╮ -info() { echo -e "\e[1;34m[INFO]\e[0m $*"; } -warn() { echo -e "\e[1;33m[WARN]\e[0m $*"; } +info() { echo -e "\e[1;34m[INFO]\e[0m $*" >&2; } +warn() { echo -e "\e[1;33m[WARN]\e[0m $*" >&2; } error() { echo -e "\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; } # ╭─────────────────────────────────────╮ @@ -33,21 +33,27 @@ error() { echo -e "\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; } find_script() { local script_name=$1 local search_paths=( - "." - "$REPO_PATH/bin" - "$REPO_PATH/gitfield" - "$REPO_PATH/gitfieldbin" + "$HOME/.local/gitfieldbin" "$HOME/.local/bin" "$HOME/.local/gitfield" - "$HOME/.local/gitfieldbin" "$HOME/.local/bin/gitfield" "$HOME/.local/bin/gitfieldbin" ) for path in "${search_paths[@]}"; do - if [ -x "$path/$script_name" ]; then - echo "$path/$script_name" - return 0 + if [ -f "$path/$script_name" ]; then + if [ -x "$path/$script_name" ]; then + # Log to stderr to avoid capturing in command substitution + if [[ "$path" != "$HOME"* ]]; then + info "Using script: \e[1;31m$path/$script_name\e[0m (outside home directory)" + else + info "Using script: $path/$script_name" + fi + echo "$path/$script_name" + return 0 + else + warn "Found $path/$script_name but it is not executable" + fi fi done error "Script $script_name not found in any search path" @@ -157,7 +163,7 @@ execute_push() { local url=$3 local script_path script_path=$(find_script "$script_name") || error "Failed to find $script_name" - info "Running $script_path for $platform..." + info "Executing $platform push with script: $script_path" if [ -x "$script_path" ]; then # Change to repo root to ensure consistent execution context pushd "$REPO_PATH" >/dev/null diff --git a/bin/gitfield-sync-old2 b/bin/gitfield-sync-old2 new file mode 100755 index 0000000..5dbb47a --- /dev/null +++ b/bin/gitfield-sync-old2 @@ -0,0 +1,218 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + +# ╭─────────────────────────────────────╮ +# │ CONFIGURATION │ +# ╰─────────────────────────────────────╯ +REPO_PATH=$(git rev-parse --show-toplevel 2>/dev/null) || error "Not inside a Git repository" +REPO_NAME=$(basename "$REPO_PATH") +GITFIELD_DIR="$REPO_PATH/.gitfield" +LOG_FILE="$GITFIELD_DIR/pushed.log" +GITFIELD_MD="$REPO_PATH/GITFIELD.md" +TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S') +SCRIPT_VERSION="1.0" + +# URLs for each platform (derived from existing scripts) +GITHUB_URL="https://github.com/mrhavens/$REPO_NAME" +GITLAB_URL="https://gitlab.com/mrhavens/$REPO_NAME" +BITBUCKET_URL="https://bitbucket.org/thefoldwithin/$REPO_NAME" +RADICLE_PROJECT_ID="z45QC21eWL1F43VSbnV9AZbCZrHQJ" +RADICLE_URL="https://app.radicle.xyz/nodes/ash.radicle.garden/rad:$RADICLE_PROJECT_ID" + +# ╭─────────────────────────────────────╮ +# │ 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; } + +# ╭─────────────────────────────────────╮ +# │ SCRIPT LOOKUP FUNCTION │ +# ╰─────────────────────────────────────╮ +find_script() { + local script_name=$1 + local search_paths=( + "." + "$REPO_PATH/bin" + "$REPO_PATH/gitfield" + "$REPO_PATH/gitfieldbin" + "$HOME/.local/bin" + "$HOME/.local/gitfield" + "$HOME/.local/gitfieldbin" + "$HOME/.local/bin/gitfield" + "$HOME/.local/bin/gitfieldbin" + ) + + for path in "${search_paths[@]}"; do + if [ -x "$path/$script_name" ]; then + echo "$path/$script_name" + return 0 + fi + done + error "Script $script_name not found in any search path" +} + +# ╭─────────────────────────────────────╮ +# │ INITIAL SETUP │ +# ╰─────────────────────────────────────╮ +# Ensure .gitfield directory exists +mkdir -p "$GITFIELD_DIR" + +# Initialize log file if it doesn't exist +if [ ! -f "$LOG_FILE" ]; then + echo "# Push Log for $REPO_NAME" > "$LOG_FILE" + echo "# Generated by gitfield-sync" >> "$LOG_FILE" + echo "" >> "$LOG_FILE" +fi + +# ╭─────────────────────────────────────╮ +# │ GENERATE GITFIELD.MD │ +# ╰─────────────────────────────────────╮ +generate_gitfield_md() { + info "Generating $GITFIELD_MD..." + cat > "$GITFIELD_MD" <> "$LOG_FILE" + info "Logged push to $LOG_FILE: [$timestamp] $platform: $url" +} + +# ╭─────────────────────────────────────╮ +# │ EXECUTE PUSH SCRIPT │ +# ╰─────────────────────────────────────╮ +execute_push() { + local script_name=$1 + local platform=$2 + local url=$3 + local script_path + script_path=$(find_script "$script_name") || error "Failed to find $script_name" + info "Running $script_path for $platform..." + if [ -x "$script_path" ]; then + # Change to repo root to ensure consistent execution context + pushd "$REPO_PATH" >/dev/null + "$script_path" || warn "Execution of $script_path failed, continuing..." + # Log the URL after successful push + log_url "$platform" "$url" + # Add and commit any new files generated by the script + git add . || warn "Nothing to add after $script_path" + git commit -m "Post-$platform sync at $TIMESTAMP" || warn "No changes to commit after $script_path" + popd >/dev/null + else + error "Script $script_path is not executable" + fi +} + +# ╭─────────────────────────────────────╮ +# │ RECURSIVE PUSH LOOP │ +# ╰─────────────────────────────────────╮ +run_push_cycle() { + local cycle_number=$1 + info "Starting push cycle $cycle_number..." + + # Push to each platform in order + execute_push "gitfield-radicle" "Radicle" "$RADICLE_URL" + execute_push "gitfield-gitlab" "GitLab" "$GITLAB_URL" + execute_push "gitfield-bitbucket" "Bitbucket" "$BITBUCKET_URL" + execute_push "gitfield-github" "GitHub" "$GITHUB_URL" +} + +# ╭─────────────────────────────────────╮ +# │ MAIN EXECUTION │ +# ╰─────────────────────────────────────╮ +info "Starting gitfield-sync for $REPO_NAME..." + +# Ensure the repository is initialized +if [ ! -d "$REPO_PATH/.git" ]; then + pushd "$REPO_PATH" >/dev/null + git init + git add . + git commit -m "Initial commit" || warn "Nothing to commit" + popd >/dev/null +fi + +# Run the first push cycle +run_push_cycle 1 + +# Generate GITFIELD.md after the first cycle +generate_gitfield_md + +# Run the second push cycle to include GITFIELD.md +run_push_cycle 2 + +# Run the third push cycle for final metadata sync +run_push_cycle 3 + +info "✅ gitfield-sync completed successfully." +info "🔗 View logs: $LOG_FILE" +info "🔗 View multi-repo manifest: $GITFIELD_MD"