Skip to content

Commit 67e2ef4

Browse files
Copilotdaedalus
andcommitted
Add baseline tooling (bootstrap/doctor/lint/CI)
Co-authored-by: daedalus <115175+daedalus@users.noreply.github.com>
1 parent ea98000 commit 67e2ef4

File tree

10 files changed

+399
-1
lines changed

10 files changed

+399
-1
lines changed

.editorconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# EditorConfig: https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.{py,sh,bash}]
11+
indent_style = space
12+
indent_size = 4
13+
14+
[Makefile]
15+
indent_style = tab
16+
17+
[*.{yml,yaml,json,toml}]
18+
indent_style = space
19+
indent_size = 2
20+
21+
[*.md]
22+
trim_trailing_whitespace = false

.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copy this file to .env and fill in values as needed.
2+
# .env is ignored by git (see .gitignore).
3+
4+
# Example: set a custom Python interpreter
5+
# PYTHON=python3
6+
7+
# Example: disable pre-commit hooks in CI environments
8+
# PRE_COMMIT_ALLOW_NO_CONFIG=1

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
if: ${{ hashFiles('.pre-commit-config.yaml') != '' }}
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.x"
22+
23+
- name: Install pre-commit
24+
if: ${{ hashFiles('.pre-commit-config.yaml') != '' }}
25+
run: pip install pre-commit
26+
27+
- name: Install shellcheck
28+
run: sudo apt-get install -y shellcheck
29+
30+
- name: Make scripts executable
31+
run: chmod +x scripts/* bin/* 2>/dev/null || true
32+
33+
- name: Run lint
34+
run: make lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ __pycache__/
66
*.egg-info/
77
dist/
88
build/
9+
.env

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.PHONY: bootstrap doctor lint format test ci
2+
3+
# Run all first-time setup steps
4+
bootstrap:
5+
@scripts/bootstrap
6+
7+
# Print environment diagnostic info
8+
doctor:
9+
@scripts/doctor
10+
11+
# Run linters on shell scripts (and pre-commit if configured)
12+
lint:
13+
@scripts/lint
14+
15+
# Auto-format shell scripts (and pre-commit if configured)
16+
format:
17+
@scripts/format
18+
19+
# Run tests (placeholder — add test commands here as the repo grows)
20+
test:
21+
@echo "No automated tests configured yet."
22+
@echo "Add test commands to this target as needed."
23+
24+
# Run lint — suitable as a CI check
25+
ci: lint

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,25 @@ A collection of miscellaneous scripts, tools, and experiments.
44

55
Topics covered include cryptography, Bitcoin/blockchain tooling, security research, networking utilities, system administration, mathematics, and general utilities.
66

7+
## Quickstart
8+
9+
```bash
10+
# First-time setup (checks tools, makes scripts executable, creates .env)
11+
make bootstrap
12+
13+
# Check your environment
14+
make doctor
15+
16+
# Run linters
17+
make lint
18+
```
19+
720
## Directory Layout
821

922
```
1023
misc/
24+
├── bin/ User-facing commands (added to PATH)
25+
├── scripts/ Internal helper scripts (bootstrap, doctor, lint, format)
1126
├── crypto/ Cryptographic algorithms, primitives, and tests
1227
│ (AES, RSA, ECDSA, DH, TOTP, PRNG, hashes, encoding)
1328
├── bitcoin/ Bitcoin and blockchain tools
@@ -25,7 +40,27 @@ misc/
2540
└── examples/ Example images used in demonstrations
2641
```
2742

28-
## Usage
43+
### Conventions
44+
45+
| Directory | Purpose |
46+
|------------|---------|
47+
| `bin/` | User-facing commands intended to be on `PATH` |
48+
| `scripts/` | Internal repo helpers (bootstrap, doctor, lint, format) |
49+
50+
## Tooling
51+
52+
All common tasks are driven by the `Makefile`. The scripts live in `scripts/`.
53+
54+
| Target | Description |
55+
|-------------------|-------------|
56+
| `make bootstrap` | Verify required tools, make scripts executable, create `.env` |
57+
| `make doctor` | Print versions and warn about missing tools |
58+
| `make lint` | Run shellcheck / shfmt (or pre-commit if configured) |
59+
| `make format` | Auto-format shell scripts with shfmt (or pre-commit) |
60+
| `make test` | Run tests (placeholder — add commands as repo grows) |
61+
| `make ci` | Alias for `make lint` — used in CI |
62+
63+
## Running Scripts
2964

3065
Most scripts are standalone and can be run directly:
3166

scripts/bootstrap

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
# scripts/bootstrap — first-time setup for this repository.
3+
#
4+
# Usage: scripts/bootstrap
5+
# or: make bootstrap
6+
#
7+
# What it does:
8+
# 1. Verifies required tools are present (git).
9+
# 2. Ensures all scripts in scripts/ and bin/ are executable.
10+
# 3. Creates .env from .env.example if .env does not already exist.
11+
# 4. Optionally installs / checks pre-commit if Python is available.
12+
13+
set -euo pipefail
14+
15+
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
16+
cd "$REPO_ROOT"
17+
18+
# ── helpers ──────────────────────────────────────────────────────────────────
19+
info() { printf '\033[1;34m==> %s\033[0m\n' "$*"; }
20+
ok() { printf '\033[1;32m ✓ %s\033[0m\n' "$*"; }
21+
warn() { printf '\033[1;33mwarn: %s\033[0m\n' "$*"; }
22+
die() { printf '\033[1;31merror: %s\033[0m\n' "$*" >&2; exit 1; }
23+
24+
# ── 1. required tools ─────────────────────────────────────────────────────────
25+
info "Checking required tools…"
26+
command -v git >/dev/null 2>&1 || die "git is required but not found. Install git and re-run."
27+
ok "git found: $(git --version)"
28+
29+
# ── 2. make scripts executable ───────────────────────────────────────────────
30+
info "Ensuring scripts are executable…"
31+
for dir in scripts bin; do
32+
if [ -d "$dir" ]; then
33+
find "$dir" -type f ! -name "*.*" -exec chmod +x {} \;
34+
ok "$dir/ scripts marked executable"
35+
fi
36+
done
37+
38+
# ── 3. create .env if missing ─────────────────────────────────────────────────
39+
if [ -f ".env.example" ] && [ ! -f ".env" ]; then
40+
info "Creating .env from .env.example…"
41+
cp ".env.example" ".env"
42+
ok ".env created (review and customise as needed)"
43+
elif [ -f ".env" ]; then
44+
ok ".env already exists"
45+
fi
46+
47+
# ── 4. pre-commit (optional) ──────────────────────────────────────────────────
48+
if command -v python3 >/dev/null 2>&1; then
49+
info "Python found — checking pre-commit…"
50+
if ! command -v pre-commit >/dev/null 2>&1; then
51+
warn "pre-commit not found. Install it with: pip install pre-commit"
52+
warn "Then run: pre-commit install"
53+
else
54+
ok "pre-commit found: $(pre-commit --version)"
55+
if [ -f ".pre-commit-config.yaml" ]; then
56+
info "Installing pre-commit hooks…"
57+
pre-commit install
58+
ok "pre-commit hooks installed"
59+
else
60+
warn "No .pre-commit-config.yaml found — skipping hook install."
61+
fi
62+
fi
63+
else
64+
warn "python3 not found — skipping pre-commit setup."
65+
warn "Install Python 3 and run: pip install pre-commit && pre-commit install"
66+
fi
67+
68+
info "Bootstrap complete."

scripts/doctor

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
# scripts/doctor — print diagnostic info and check for common tools.
3+
#
4+
# Usage: scripts/doctor
5+
# or: make doctor
6+
#
7+
# Exit codes:
8+
# 0 all critical tools present
9+
# 1 one or more critical tools missing
10+
11+
set -euo pipefail
12+
13+
# ── helpers ──────────────────────────────────────────────────────────────────
14+
ok() { printf '\033[1;32m ✓ %-12s %s\033[0m\n' "$1" "$2"; }
15+
warn() { printf '\033[1;33m ✗ %-12s %s\033[0m\n' "$1" "$2"; }
16+
hdr() { printf '\n\033[1m%s\033[0m\n' "$*"; }
17+
18+
MISSING_CRITICAL=0
19+
20+
check() {
21+
local name="$1"
22+
local critical="${2:-false}"
23+
if command -v "$name" >/dev/null 2>&1; then
24+
local ver
25+
# Some tools use 'version' sub-command rather than --version
26+
case "$name" in
27+
go) ver=$(go version 2>&1 | head -1) || true ;;
28+
*) ver=$("$name" --version 2>&1 | head -1) || true ;;
29+
esac
30+
ok "$name" "$ver"
31+
else
32+
if [ "$critical" = "true" ]; then
33+
warn "$name" "NOT FOUND (required)"
34+
MISSING_CRITICAL=1
35+
else
36+
warn "$name" "not found (optional)"
37+
fi
38+
fi
39+
}
40+
41+
# ── environment info ──────────────────────────────────────────────────────────
42+
hdr "Environment"
43+
printf ' OS: %s\n' "$(uname -sr)"
44+
printf ' Host: %s\n' "$(uname -n)"
45+
printf ' User: %s\n' "${USER:-unknown}"
46+
printf ' PWD: %s\n' "$(pwd)"
47+
48+
# ── critical tools ────────────────────────────────────────────────────────────
49+
hdr "Critical tools"
50+
check git true
51+
check bash true
52+
53+
# ── optional tools ────────────────────────────────────────────────────────────
54+
hdr "Optional tools"
55+
check python3
56+
check node
57+
check go
58+
check pre-commit
59+
check shellcheck
60+
check shfmt
61+
62+
printf '\n'
63+
if [ "$MISSING_CRITICAL" -ne 0 ]; then
64+
printf '\033[1;31mDoctor found missing critical tools. Please install them.\033[0m\n' >&2
65+
exit 1
66+
fi
67+
printf '\033[1;32mAll critical tools present.\033[0m\n'

scripts/format

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
# scripts/format — auto-format shell scripts (and pre-commit if configured).
3+
#
4+
# Usage: scripts/format
5+
# or: make format
6+
#
7+
# Priority:
8+
# 1. pre-commit run --all-files (if pre-commit and config are present)
9+
# 2. shfmt -w (write) on scripts/* and bin/*
10+
# If none of the above tools are present, the script exits 0 with a notice.
11+
12+
set -euo pipefail
13+
14+
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
15+
cd "$REPO_ROOT" || exit 1
16+
17+
# ── helpers ──────────────────────────────────────────────────────────────────
18+
info() { printf '\033[1;34m==> %s\033[0m\n' "$*"; }
19+
ok() { printf '\033[1;32m ✓ %s\033[0m\n' "$*"; }
20+
warn() { printf '\033[1;33mwarn: %s\033[0m\n' "$*"; }
21+
22+
# ── collect shell scripts ─────────────────────────────────────────────────────
23+
shell_scripts=()
24+
for dir in scripts bin; do
25+
if [ -d "$dir" ]; then
26+
while IFS= read -r -d '' f; do
27+
shell_scripts+=("$f")
28+
done < <(find "$dir" -type f ! -name "*.*" -print0 2>/dev/null)
29+
fi
30+
done
31+
32+
# ── 1. pre-commit ─────────────────────────────────────────────────────────────
33+
if command -v pre-commit >/dev/null 2>&1 && [ -f ".pre-commit-config.yaml" ]; then
34+
info "Running pre-commit run --all-files…"
35+
if pre-commit run --all-files; then
36+
ok "pre-commit passed"
37+
else
38+
exit 1
39+
fi
40+
exit 0
41+
fi
42+
43+
# ── 2. shfmt (write mode) ─────────────────────────────────────────────────────
44+
if command -v shfmt >/dev/null 2>&1; then
45+
if [ "${#shell_scripts[@]}" -gt 0 ]; then
46+
info "Running shfmt -w on shell scripts…"
47+
shfmt -w "${shell_scripts[@]}"
48+
ok "shfmt: formatting applied"
49+
else
50+
warn "No shell scripts found to format with shfmt."
51+
fi
52+
else
53+
warn "shfmt not found — skipping. See https://github.com/mvdan/sh for install instructions."
54+
fi

0 commit comments

Comments
 (0)