refactor: Improve project scaffolding

This commit is contained in:
2026-06-20 19:33:52 +05:30
parent 4318cd8536
commit fce177a0df
10 changed files with 25 additions and 22 deletions

View File

@@ -16,12 +16,15 @@ Bootstrap CLI (`b`) is a bash-based tool installer and system bootstrapper. User
```
bootstrap/
├── installers/ # Individual installer scripts (install_<name>.sh)
├── lib/ # Shared libraries sourced by all installers
├── lib/ # Shared libraries and router sourced by all installers
│ ├── common.sh # Logging, confirm(), has_command(), make_temp_dir()
│ ├── platform.sh # detect_distro(), detect_arch(), pkg_install()
── shell_config.sh # get_shell_configs(), inject_block(), remove_block(), add_alias_if_missing(), add_env_if_missing()
── shell_config.sh # get_shell_configs(), inject_block(), remove_block(), add_alias_if_missing(), add_env_if_missing()
│ ├── registry.sh # Dynamically generated installer registry
│ └── routes.sh # Central router script
├── commands/ # Non-installer commands (help, con, uninstall)
├── routes.sh # Central router + installer registry
├── assets/ # Assets (logo art, etc.)
│ └── pixel_art.ansi
├── bootstrap.sh # Metascript for environment setup + library loading
├── b.sh # The `b` shell function and autocompletion
└── VERSION
@@ -44,7 +47,7 @@ At the top of your new installer script, right below `#!/usr/bin/env bash`, add
# Description: <description>
```
The central router `routes.sh` and autocomplete function in `b.sh` will dynamically parse this metadata from all `install_*.sh` scripts to register the installer and keys automatically! No manual edits to `routes.sh` or `b.sh` are required.
The central router `lib/routes.sh` and autocomplete function in `b.sh` will dynamically parse this metadata from all `install_*.sh` scripts to register the installer and keys automatically! No manual edits to `lib/routes.sh` or `b.sh` are required.
### Step 3: Verify (optional)
@@ -252,7 +255,7 @@ inject_block "$config_file" "<tool> init" 'eval "$(tool init bash)"'
## Rules & Conventions
1. **File naming**: Always `install_<name>.sh` in the `installers/` directory.
2. **Alphabetical order**: Keep `INSTALLERS` entries and `INSTALLER_KEYS` in alphabetical order in `routes.sh`.
2. **Registry generation**: The registry in `lib/registry.sh` is automatically generated by `scripts/generate_registry.sh` (run automatically on commit by the git pre-commit hook).
3. **Confirmation prompts**: Always ask before installing. Check if already installed first.
4. **Idempotent**: Installers must be safe to re-run. Use `inject_block` (not append) for shell configs.
5. **No hardcoded paths**: Use `$HOME`, library functions, and `detect_*` helpers.

View File

@@ -1 +1 @@
1.1.3
1.1.4

2
b.sh
View File

@@ -7,7 +7,7 @@ b() {
fi
local routes_dir="$HOME/.config/bootstrap"
local routes_file="$routes_dir/routes.sh"
local routes_file="$routes_dir/lib/routes.sh"
local last_update_file="$routes_dir/.last_b_update"
local current_time

View File

@@ -89,8 +89,8 @@ install_bootstrap() {
local files=(
"VERSION"
"b.sh"
"routes.sh"
"registry.sh"
"lib/routes.sh"
"lib/registry.sh"
"lib/common.sh"
"lib/platform.sh"
"lib/shell_config.sh"
@@ -100,7 +100,7 @@ install_bootstrap() {
"commands/up.sh"
)
if [ -f "$_SCRIPT_DIR/b.sh" ] && [ -f "$_SCRIPT_DIR/routes.sh" ]; then
if [ -f "$_SCRIPT_DIR/b.sh" ] && [ -f "$_SCRIPT_DIR/lib/routes.sh" ]; then
log_info "Using local files from repository..."
for file in "${files[@]}"; do
mkdir -p "$(dirname "$routes_dir/$file")"
@@ -221,7 +221,7 @@ if [ "$is_sourced" = false ]; then
clear 2>/dev/null || true
# Locate or download pixel_art.ansi and VERSION
_art_file="$_SCRIPT_DIR/pixel_art.ansi"
_art_file="$_SCRIPT_DIR/assets/pixel_art.ansi"
_version_file="$_SCRIPT_DIR/VERSION"
if [ ! -f "$_art_file" ]; then
@@ -231,10 +231,10 @@ if [ "$is_sourced" = false ]; then
_base_url="${_BASE_URL:-https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master}"
if [ ! -f "$_art_file" ]; then
if command -v curl >/dev/null 2>&1; then
curl -fsSL -o "$_art_file" "$_base_url/pixel_art.ansi" 2>/dev/null
curl -fsSL -o "$_art_file" "$_base_url/assets/pixel_art.ansi" 2>/dev/null
curl -fsSL -o "$_version_file" "$_base_url/VERSION" 2>/dev/null
elif command -v wget >/dev/null 2>&1; then
wget -qO "$_art_file" "$_base_url/pixel_art.ansi" 2>/dev/null
wget -qO "$_art_file" "$_base_url/assets/pixel_art.ansi" 2>/dev/null
wget -qO "$_version_file" "$_base_url/VERSION" 2>/dev/null
fi
fi

View File

@@ -20,19 +20,19 @@ _SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd 2>/dev/null || pwd)"
# Source registry
if [ -f "$_SCRIPT_DIR/registry.sh" ]; then
. "$_SCRIPT_DIR/registry.sh"
elif [ -f "$BOOTSTRAP_DIR/registry.sh" ]; then
. "$BOOTSTRAP_DIR/registry.sh"
elif [ -f "$BOOTSTRAP_DIR/lib/registry.sh" ]; then
. "$BOOTSTRAP_DIR/lib/registry.sh"
else
# Standalone/remote fallback: download registry
_tmp_registry=$(mktemp)
BOOTSTRAP_BASE_URL="${BOOTSTRAP_BASE_URL:-https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master}"
BOOTSTRAP_FALLBACK_URL="${BOOTSTRAP_FALLBACK_URL:-https://raw.githubusercontent.com/sortedcord/bootstrap/refs/heads/master}"
if has_command curl; then
curl -fsSL "${BOOTSTRAP_BASE_URL}/registry.sh" -o "$_tmp_registry" 2>/dev/null || \
curl -fsSL "${BOOTSTRAP_FALLBACK_URL}/registry.sh" -o "$_tmp_registry" 2>/dev/null
curl -fsSL "${BOOTSTRAP_BASE_URL}/lib/registry.sh" -o "$_tmp_registry" 2>/dev/null || \
curl -fsSL "${BOOTSTRAP_FALLBACK_URL}/lib/registry.sh" -o "$_tmp_registry" 2>/dev/null
elif has_command wget; then
wget -qO "$_tmp_registry" "${BOOTSTRAP_BASE_URL}/registry.sh" 2>/dev/null || \
wget -qO "$_tmp_registry" "${BOOTSTRAP_FALLBACK_URL}/registry.sh" 2>/dev/null
wget -qO "$_tmp_registry" "${BOOTSTRAP_BASE_URL}/lib/registry.sh" 2>/dev/null || \
wget -qO "$_tmp_registry" "${BOOTSTRAP_FALLBACK_URL}/lib/registry.sh" 2>/dev/null
fi
if [ -s "$_tmp_registry" ]; then
. "$_tmp_registry"

View File

@@ -137,7 +137,7 @@ If you want to audit the core Bootstrap CLI itself before running it:
```bash
curl -fsSL https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/bootstrap.sh
curl -fsSL https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/routes.sh
curl -fsSL https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/lib/routes.sh
```
and review the contents before piping it into a shell.

View File

@@ -6,7 +6,7 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(dirname "$SCRIPT_DIR")"
INSTALLERS_DIR="$REPO_DIR/installers"
REGISTRY_FILE="$REPO_DIR/registry.sh"
REGISTRY_FILE="$REPO_DIR/lib/registry.sh"
echo "==> Generating registry.sh..."

View File

@@ -7,7 +7,7 @@ set -euo pipefail
# Generate the registry dynamically and stage it
if [ -f "./scripts/generate_registry.sh" ]; then
./scripts/generate_registry.sh
git add registry.sh
git add lib/registry.sh
fi
VERSION_FILE="VERSION"