diff --git a/.gitfield/.radicle-push-state b/.gitfield/.radicle-push-state index 0d37a24..fb877fb 100644 --- a/.gitfield/.radicle-push-state +++ b/.gitfield/.radicle-push-state @@ -1 +1 @@ -17afc86d259877d4000eb078fb7428f8da239673 +a5758991d67b10e72bb9b8da4131e59461a3bb4b diff --git a/.gitfield/pushed.log b/.gitfield/pushed.log index 7228bc8..a1490e8 100644 --- a/.gitfield/pushed.log +++ b/.gitfield/pushed.log @@ -179,3 +179,4 @@ [2025-05-31 19:12:53] Radicle: https://app.radicle.xyz/nodes/ash.radicle.garden/rad:z45QC21eWL1F43VSbnV9AZbCZrHQJ [2025-05-31 19:13:04] GitLab: https://gitlab.com/mrhavens/git-sigil [2025-05-31 19:13:18] Bitbucket: https://bitbucket.org/thefoldwithin/git-sigil +[2025-06-05 01:07:57] Radicle: https://app.radicle.xyz/nodes/ash.radicle.garden/rad:z45QC21eWL1F43VSbnV9AZbCZrHQJ diff --git a/gitfield-bitbucket b/bin/gitfield-bitbucket similarity index 100% rename from gitfield-bitbucket rename to bin/gitfield-bitbucket diff --git a/gitfield-github b/bin/gitfield-github similarity index 100% rename from gitfield-github rename to bin/gitfield-github diff --git a/gitfield-gitlab b/bin/gitfield-gitlab similarity index 100% rename from gitfield-gitlab rename to bin/gitfield-gitlab diff --git a/gitfield-radicle b/bin/gitfield-radicle similarity index 100% rename from gitfield-radicle rename to bin/gitfield-radicle diff --git a/bin/gitfield-sync b/bin/gitfield-sync new file mode 100755 index 0000000..5dbb47a --- /dev/null +++ b/bin/gitfield-sync @@ -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" diff --git a/bin/gitfield-sync-gdrive.sh b/bin/gitfield-sync-gdrive.sh new file mode 100755 index 0000000..0c87a7c --- /dev/null +++ b/bin/gitfield-sync-gdrive.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# ────────────────────────────────────────────────────────────── +# ⚙️ GitField GDrive Sync Script +# Ensures Google Drive is mounted at ~/gdrive and syncs +# the current Git repo into ~/gdrive/gitfield/ +# ────────────────────────────────────────────────────────────── + +set -e + +# ⛓ Ensure rsync is installed +if ! command -v rsync &> /dev/null; then + echo "rsync not found. Attempting to install..." + sudo apt update && sudo apt install -y rsync +fi + +# ⛓ Ensure ~/gdrive exists and is mounted +GDRIVE_PATH="$HOME/gdrive" +GITFIELD_PATH="$GDRIVE_PATH/gitfield" + +if [ ! -d "$GDRIVE_PATH" ]; then + echo "Google Drive folder not found at $GDRIVE_PATH." + echo "Create it or mount your gdrive before syncing." + exit 1 +fi + +mkdir -p "$GITFIELD_PATH" + +# ⛓ Ensure current directory is inside a Git repo +if ! git rev-parse --is-inside-work-tree &> /dev/null; then + echo "Not inside a Git repository. Aborting sync." + exit 1 +fi + +# 🏷 Determine repo name and paths +REPO_ROOT=$(git rev-parse --show-toplevel) +REPO_NAME=$(basename "$REPO_ROOT") +DEST="$GITFIELD_PATH/$REPO_NAME" + +# ♻️ Perform rsync (mirror entire repo, preserve structure, show progress) +echo "Syncing '$REPO_NAME' to $DEST..." +rsync -av --delete "$REPO_ROOT/" "$DEST/" + +echo "✅ GitField sync complete: $REPO_NAME ➝ $DEST" diff --git a/gitfield-sync b/bin/gitfield-sync-old similarity index 100% rename from gitfield-sync rename to bin/gitfield-sync-old diff --git a/bin/mount-gdrive.sh b/bin/mount-gdrive.sh new file mode 100755 index 0000000..25440e0 --- /dev/null +++ b/bin/mount-gdrive.sh @@ -0,0 +1,2 @@ +#!/bin/bash +rclone mount gdrive: ~/gdrive --vfs-cache-mode writes diff --git a/bin/sync-metadata.sh b/bin/sync-metadata.sh new file mode 100755 index 0000000..4d4022d --- /dev/null +++ b/bin/sync-metadata.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# ---------------------------- +# Gitfield Metadata Sync Tool +# ---------------------------- + +# CONFIGURATION +DRIVE_REMOTE="gdrive" +GITFIELD_ROOT="$HOME/gdrive/gitfield" +SCRIPT_NAME="sync-metadata.sh" + +# Ensure rclone is installed +if ! command -v rclone &> /dev/null; then + echo "rclone is not installed. Installing..." + sudo apt update && sudo apt install -y rclone +fi + +# Ensure jq is installed +if ! command -v jq &> /dev/null; then + echo "jq is not installed. Installing..." + sudo apt update && sudo apt install -y jq +fi + +# Get Git repo root +REPO_DIR=$(git rev-parse --show-toplevel 2>/dev/null) +if [ $? -ne 0 ]; then + echo "❌ Not inside a Git repository." + exit 1 +fi + +REPO_NAME=$(basename "$REPO_DIR") +GDRIVE_PATH="gitfield/$REPO_NAME" +SYNC_LOG="$REPO_DIR/.gitfield/sync-log.md" +README="$REPO_DIR/README.md" + +echo "🔍 Detecting Google Drive folder: $GDRIVE_PATH..." + +# Mount ~/gdrive if not mounted +MOUNTPOINT="$HOME/gdrive" +if ! mount | grep -q "$MOUNTPOINT"; then + echo "⚙️ Mounting Google Drive to $MOUNTPOINT..." + mkdir -p "$MOUNTPOINT" + rclone mount "$DRIVE_REMOTE:/" "$MOUNTPOINT" --vfs-cache-mode writes --daemon + sleep 3 +fi + +# Share link generation +SHARE_URL=$(rclone link "$DRIVE_REMOTE:$GDRIVE_PATH") +if [ -z "$SHARE_URL" ]; then + echo "❌ Could not generate Google Drive share link." + exit 1 +fi + +# Optional: Construct drv.tw link (manual fallback example) +DRV_URL="https://drv.tw/view/$(basename "$SHARE_URL")" + +# Write metadata to sync log +mkdir -p "$(dirname "$SYNC_LOG")" +cat <> "$SYNC_LOG" + +## 🔄 Sync Metadata — $(date +%F) + +- 📁 **Google Drive Folder**: [$REPO_NAME]($SHARE_URL) +- 🌐 **Published View**: [$DRV_URL]($DRV_URL) + +EOF + +# Append to README if not already present +if ! grep -q "$SHARE_URL" "$README"; then + echo "📘 Updating README..." + cat <> "$README" + +--- + +## 🔍 External Access + +- 🔗 **Google Drive Folder**: [$REPO_NAME]($SHARE_URL) +- 🌐 **Published View**: [$DRV_URL]($DRV_URL) + +EOF +else + echo "✅ README already contains sync links." +fi + +echo "✅ Metadata sync complete." diff --git a/github/1_prerequisites_github_ubuntu.md b/docs/github/1_prerequisites_github_ubuntu.md similarity index 100% rename from github/1_prerequisites_github_ubuntu.md rename to docs/github/1_prerequisites_github_ubuntu.md diff --git a/github/2_create_remote_repo_github_ubuntu.md b/docs/github/2_create_remote_repo_github_ubuntu.md similarity index 100% rename from github/2_create_remote_repo_github_ubuntu.md rename to docs/github/2_create_remote_repo_github_ubuntu.md diff --git a/github/3_commit_existing_repo_github_ubuntu.md b/docs/github/3_commit_existing_repo_github_ubuntu.md similarity index 100% rename from github/3_commit_existing_repo_github_ubuntu.md rename to docs/github/3_commit_existing_repo_github_ubuntu.md diff --git a/github/CLI-ONLY_workflow_github_ubuntu.md b/docs/github/CLI-ONLY_workflow_github_ubuntu.md similarity index 100% rename from github/CLI-ONLY_workflow_github_ubuntu.md rename to docs/github/CLI-ONLY_workflow_github_ubuntu.md diff --git a/github/gitfield-github-old b/docs/github/gitfield-github-old similarity index 100% rename from github/gitfield-github-old rename to docs/github/gitfield-github-old diff --git a/gitlab/1_prerequisites_gitlab_ubuntu.md b/docs/gitlab/1_prerequisites_gitlab_ubuntu.md similarity index 100% rename from gitlab/1_prerequisites_gitlab_ubuntu.md rename to docs/gitlab/1_prerequisites_gitlab_ubuntu.md diff --git a/gitlab/2_create_remote_repo_gitlab_ubuntu.md b/docs/gitlab/2_create_remote_repo_gitlab_ubuntu.md similarity index 100% rename from gitlab/2_create_remote_repo_gitlab_ubuntu.md rename to docs/gitlab/2_create_remote_repo_gitlab_ubuntu.md diff --git a/gitlab/3_commit_existing_repo_gitlab_ubuntu.md b/docs/gitlab/3_commit_existing_repo_gitlab_ubuntu.md similarity index 100% rename from gitlab/3_commit_existing_repo_gitlab_ubuntu.md rename to docs/gitlab/3_commit_existing_repo_gitlab_ubuntu.md diff --git a/gitlab/CLI-ONLY_workflow_gitlab_ubuntu.md b/docs/gitlab/CLI-ONLY_workflow_gitlab_ubuntu.md similarity index 100% rename from gitlab/CLI-ONLY_workflow_gitlab_ubuntu.md rename to docs/gitlab/CLI-ONLY_workflow_gitlab_ubuntu.md diff --git a/osf/new/gitfield-osf b/docs/osf/new/gitfield-osf similarity index 100% rename from osf/new/gitfield-osf rename to docs/osf/new/gitfield-osf diff --git a/osf/new/gitfield.osf.yaml b/docs/osf/new/gitfield.osf.yaml similarity index 100% rename from osf/new/gitfield.osf.yaml rename to docs/osf/new/gitfield.osf.yaml diff --git a/osf/new/test-osf-api.sh b/docs/osf/new/test-osf-api.sh similarity index 100% rename from osf/new/test-osf-api.sh rename to docs/osf/new/test-osf-api.sh diff --git a/osf/old/for_radicle.md b/docs/osf/old/for_radicle.md similarity index 100% rename from osf/old/for_radicle.md rename to docs/osf/old/for_radicle.md diff --git a/osf/old/gitfield-osf b/docs/osf/old/gitfield-osf similarity index 100% rename from osf/old/gitfield-osf rename to docs/osf/old/gitfield-osf diff --git a/osf/old/gitfield.osf.yaml b/docs/osf/old/gitfield.osf.yaml similarity index 100% rename from osf/old/gitfield.osf.yaml rename to docs/osf/old/gitfield.osf.yaml diff --git a/osf/old/test-osf-api.sh b/docs/osf/old/test-osf-api.sh similarity index 100% rename from osf/old/test-osf-api.sh rename to docs/osf/old/test-osf-api.sh diff --git a/radicle/for_radicle.md b/docs/radicle/for_radicle.md similarity index 100% rename from radicle/for_radicle.md rename to docs/radicle/for_radicle.md diff --git a/test b/test deleted file mode 100644 index e69de29..0000000