Skip to content

Commit e51408e

Browse files
committed
feat(setup/local): add install-cli-tools, setup-shell, setup-ssh, setup-gpg, configure-git, configure-kubectl, configure-terraform, and verify-workstation with docs
1 parent 298ca8b commit e51408e

17 files changed

Lines changed: 1970 additions & 0 deletions
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# configure-git.sh
2+
3+
## Purpose
4+
Apply consistent global Git configuration for identity, workflow defaults, and optional signing.
5+
6+
## Location
7+
`setup/local/configure-git.sh`
8+
9+
## Preconditions
10+
- Required tools: `bash`, `git`
11+
- Required permissions: write access to global git config
12+
- Required environment variables: none
13+
14+
## Arguments
15+
| Flag | Required | Default | Description |
16+
|------|----------|---------|-------------|
17+
| `--name VALUE` | No | unchanged | Set `user.name` |
18+
| `--email VALUE` | No | unchanged | Set `user.email` |
19+
| `--default-branch NAME` | No | `main` | Set `init.defaultBranch` |
20+
| `--editor VALUE` | No | unchanged | Set `core.editor` |
21+
| `--credential-helper V` | No | platform auto | Set `credential.helper` |
22+
| `--rebase-pull BOOL` | No | `false` | Set `pull.rebase` |
23+
| `--signing-key KEYID` | No | unchanged | Set `user.signingkey` |
24+
| `--gpg-sign BOOL` | No | auto/unchanged | Set `commit.gpgsign` |
25+
| `--dry-run` | No | `false` | Print planned changes |
26+
27+
## Scenarios
28+
- Happy path: apply baseline global Git settings.
29+
- Common operational path: bootstrap new workstation developer identity + defaults.
30+
- Failure path: git unavailable or invalid boolean values.
31+
- Recovery/rollback path: rerun with corrected values or reset keys via `git config --global --unset`.
32+
33+
## Usage
34+
```bash
35+
setup/local/configure-git.sh --name "Jane Doe" --email jane@example.com
36+
setup/local/configure-git.sh --rebase-pull true --editor "code --wait"
37+
setup/local/configure-git.sh --signing-key ABCD1234 --gpg-sign true --dry-run
38+
```
39+
40+
## Behavior
41+
- Main execution flow: validate options, set global git keys, optionally configure signing.
42+
- Idempotency notes: idempotent; sets target values repeatedly.
43+
- Side effects: modifies `~/.gitconfig`.
44+
45+
## Output
46+
- Standard output format: timestamped status logs and dry-run command output.
47+
- Exit codes:
48+
- `0` success
49+
- `2` invalid arguments
50+
51+
## Failure Modes
52+
- Common errors and likely causes:
53+
- git not installed
54+
- invalid boolean input
55+
- Recovery and rollback steps:
56+
- install git
57+
- pass boolean as true/false
58+
59+
## Security Notes
60+
- Secret handling: no secret storage; consider secure credential helper backend.
61+
- Least-privilege requirements: user-level git config operations.
62+
- Audit/logging expectations: safe for bootstrap logs.
63+
64+
## Testing
65+
- Unit tests:
66+
- boolean normalization and option parsing
67+
- Integration tests:
68+
- dry-run vs apply behavior on test HOME
69+
- Manual verification:
70+
- `git config --global --list` inspection
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# configure-kubectl.sh
2+
3+
## Purpose
4+
Set local kubectl defaults (kubeconfig path, context, namespace) for safer and repeatable cluster operations.
5+
6+
## Location
7+
`setup/local/configure-kubectl.sh`
8+
9+
## Preconditions
10+
- Required tools: `bash`, `kubectl`
11+
- Required permissions: write access to kubeconfig file/path
12+
- Required environment variables: none
13+
14+
## Arguments
15+
| Flag | Required | Default | Description |
16+
|------|----------|---------|-------------|
17+
| `--kubeconfig PATH` | No | `~/.kube/config` | Target kubeconfig file |
18+
| `--context NAME` | No | unchanged | Context to select |
19+
| `--namespace NAME` | No | unchanged | Namespace to set |
20+
| `--dry-run` | No | `false` | Print commands without execution |
21+
22+
## Scenarios
23+
- Happy path: context and namespace are configured successfully.
24+
- Common operational path: enforce default namespace to avoid accidental cross-namespace actions.
25+
- Failure path: missing kubectl or invalid context.
26+
- Recovery/rollback path: run with valid context/namespace values and verify config.
27+
28+
## Usage
29+
```bash
30+
setup/local/configure-kubectl.sh --context prod-cluster --namespace platform
31+
setup/local/configure-kubectl.sh --kubeconfig "$HOME/.kube/prod-config" --context prod
32+
setup/local/configure-kubectl.sh --namespace default --dry-run
33+
```
34+
35+
## Behavior
36+
- Main execution flow: ensure kubeconfig path exists, apply context and namespace updates.
37+
- Idempotency notes: idempotent for identical target settings.
38+
- Side effects: modifies kubeconfig.
39+
40+
## Output
41+
- Standard output format: timestamped logs and optional dry-run commands.
42+
- Exit codes:
43+
- `0` success
44+
- `2` invalid arguments
45+
- non-zero from kubectl on command failure
46+
47+
## Failure Modes
48+
- Common errors and likely causes:
49+
- kubectl missing
50+
- invalid context name
51+
- kubeconfig write permission issues
52+
- Recovery and rollback steps:
53+
- validate context list (`kubectl config get-contexts`)
54+
- fix file permissions/path
55+
- rerun with corrected inputs
56+
57+
## Security Notes
58+
- Secret handling: kubeconfig may contain credentials; keep file permissions strict.
59+
- Least-privilege requirements: user-level config modifications only.
60+
- Audit/logging expectations: avoid printing sensitive kubeconfig content.
61+
62+
## Testing
63+
- Unit tests:
64+
- argument parsing and dry-run behavior
65+
- Integration tests:
66+
- context/namespace changes on test kubeconfig
67+
- Manual verification:
68+
- `kubectl config view --minify` output check
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# configure-terraform.sh
2+
3+
## Purpose
4+
Apply managed Terraform CLI configuration for plugin caching, checkpoint behavior, and optional registry credentials.
5+
6+
## Location
7+
`setup/local/configure-terraform.sh`
8+
9+
## Preconditions
10+
- Required tools: `bash`
11+
- Required permissions: write access to Terraform config and cache directories
12+
- Required environment variables: optional `TF_TOKEN`
13+
14+
## Arguments
15+
| Flag | Required | Default | Description |
16+
|------|----------|---------|-------------|
17+
| `--config-file PATH` | No | `~/.terraformrc` | Terraform CLI config path |
18+
| `--plugin-cache-dir PATH` | No | `~/.terraform.d/plugin-cache` | Plugin cache directory |
19+
| `--disable-checkpoint B` | No | `true` | `true\|false` checkpoint behavior |
20+
| `--registry-host HOST` | No | `app.terraform.io` | Credentials host |
21+
| `--token TOKEN` | No | from `TF_TOKEN` | Registry token |
22+
| `--dry-run` | No | `false` | Show resulting managed config |
23+
24+
## Scenarios
25+
- Happy path: managed Terraform block applied with plugin cache and defaults.
26+
- Common operational path: set team-wide Terraform behavior on onboarding.
27+
- Failure path: invalid boolean value or inaccessible config path.
28+
- Recovery/rollback path: correct options and rerun, or remove managed block markers manually.
29+
30+
## Usage
31+
```bash
32+
setup/local/configure-terraform.sh
33+
setup/local/configure-terraform.sh --plugin-cache-dir "$HOME/.cache/terraform/plugins"
34+
setup/local/configure-terraform.sh --token "$TF_TOKEN" --registry-host app.terraform.io --dry-run
35+
```
36+
37+
## Behavior
38+
- Main execution flow: create config/cache paths, replace managed block in config file.
39+
- Idempotency notes: managed block replacement is idempotent.
40+
- Side effects: updates config file and creates plugin cache directory.
41+
42+
## Output
43+
- Standard output format: timestamped status logs and config preview in dry-run mode.
44+
- Exit codes:
45+
- `0` success
46+
- `2` invalid arguments
47+
48+
## Failure Modes
49+
- Common errors and likely causes:
50+
- invalid `--disable-checkpoint` value
51+
- filesystem permission issues for config/cache paths
52+
- Recovery and rollback steps:
53+
- fix option values
54+
- ensure directory ownership/permissions
55+
56+
## Security Notes
57+
- Secret handling: token may be written in plaintext to Terraform config; restrict file permissions.
58+
- Least-privilege requirements: user-level config writes.
59+
- Audit/logging expectations: do not print token values in shared logs.
60+
61+
## Testing
62+
- Unit tests:
63+
- boolean parsing and argument validation
64+
- Integration tests:
65+
- managed block merge behavior with pre-existing config
66+
- Manual verification:
67+
- run `terraform init` and confirm plugin cache usage
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# install-cli-tools.sh
2+
3+
## Purpose
4+
Install common DevOps CLI tooling using the host package manager with repeatable, scriptable behavior.
5+
6+
## Location
7+
`setup/local/install-cli-tools.sh`
8+
9+
## Preconditions
10+
- Required tools: `bash`, selected package manager (`brew`, `apt-get`, `dnf`, or `yum`), optional `sudo`
11+
- Required permissions: package-install privileges on workstation
12+
- Required environment variables: none
13+
14+
## Arguments
15+
| Flag | Required | Default | Description |
16+
|------|----------|---------|-------------|
17+
| `--tools CSV` | No | built-in tool set | Comma-separated tool list |
18+
| `--tool NAME` | No | none | Add one tool (repeatable) |
19+
| `--manager NAME` | No | `auto` | `auto\|brew\|apt\|dnf\|yum` |
20+
| `--yes` | No | `false` | Non-interactive package install |
21+
| `--dry-run` | No | `false` | Print commands only |
22+
| `--update-cache` | No | `false` | Refresh package metadata before install |
23+
24+
## Scenarios
25+
- Happy path: missing tools are installed, existing tools are skipped.
26+
- Common operational path: bootstrap a fresh developer workstation.
27+
- Failure path: unsupported manager/tool mapping or package install failure.
28+
- Recovery/rollback path: rerun with explicit manager/tool list and fixed package sources.
29+
30+
## Usage
31+
```bash
32+
setup/local/install-cli-tools.sh --update-cache --yes
33+
setup/local/install-cli-tools.sh --manager brew --tools git,jq,shellcheck,shfmt
34+
setup/local/install-cli-tools.sh --tool kubectl --tool terraform --dry-run
35+
```
36+
37+
## Behavior
38+
- Main execution flow: detect manager, optionally update cache, install requested/missing tools.
39+
- Idempotency notes: idempotent for already-installed tools.
40+
- Side effects: system package installation and updates.
41+
42+
## Output
43+
- Standard output format: timestamped installation logs on stderr.
44+
- Exit codes:
45+
- `0` all requested tools available/installed
46+
- `1` one or more tools failed/unsupported
47+
- `2` invalid arguments
48+
49+
## Failure Modes
50+
- Common errors and likely causes:
51+
- no supported package manager found
52+
- package unavailable in configured repositories
53+
- insufficient privileges for system install
54+
- Recovery and rollback steps:
55+
- verify repository configuration and credentials
56+
- rerun with explicit `--manager`
57+
- install failed tools manually and rerun verification
58+
59+
## Security Notes
60+
- Secret handling: no secret input expected.
61+
- Least-privilege requirements: use elevated privileges only for package operations.
62+
- Audit/logging expectations: installation logs should be retained during bootstrap.
63+
64+
## Testing
65+
- Unit tests:
66+
- manager/tool mapping logic
67+
- argument parsing
68+
- Integration tests:
69+
- dry-run/install behavior on supported OS images
70+
- Manual verification:
71+
- run then confirm each tool in `PATH`
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# setup-gpg.sh
2+
3+
## Purpose
4+
Apply baseline GPG workstation setup and optional key/ownertrust imports for signing workflows.
5+
6+
## Location
7+
`setup/local/setup-gpg.sh`
8+
9+
## Preconditions
10+
- Required tools: `bash`, `gpg`, `gpgconf`, `awk`
11+
- Required permissions: write access to `~/.gnupg`
12+
- Required environment variables: none
13+
14+
## Arguments
15+
| Flag | Required | Default | Description |
16+
|------|----------|---------|-------------|
17+
| `--public-key FILE` | No | none | Import public key (repeatable) |
18+
| `--private-key FILE` | No | none | Import private key (repeatable) |
19+
| `--ownertrust FILE` | No | none | Import ownertrust data |
20+
| `--default-key KEYID` | No | unset | Set default signing key |
21+
| `--pinentry-program PATH` | No | unset | Set pinentry executable |
22+
| `--dry-run` | No | `false` | Print planned actions/config |
23+
24+
## Scenarios
25+
- Happy path: GPG home is secured and managed config applied.
26+
- Common operational path: import team signing keys on new machine.
27+
- Failure path: unreadable key files or missing `gpg` binary.
28+
- Recovery/rollback path: correct inputs, re-import keys, reapply managed config.
29+
30+
## Usage
31+
```bash
32+
setup/local/setup-gpg.sh --default-key ABCD1234
33+
setup/local/setup-gpg.sh --public-key ./pub.asc --private-key ./secret.asc
34+
setup/local/setup-gpg.sh --pinentry-program /opt/homebrew/bin/pinentry-mac --dry-run
35+
```
36+
37+
## Behavior
38+
- Main execution flow: ensure `~/.gnupg` permissions, import inputs, update managed `gpg.conf`, launch agent.
39+
- Idempotency notes: safe to rerun; imports may be no-op for existing keys.
40+
- Side effects: updates keyring/ownertrust and gpg configuration files.
41+
42+
## Output
43+
- Standard output format: timestamped setup logs and optional dry-run config output.
44+
- Exit codes:
45+
- `0` success
46+
- `2` invalid arguments or unreadable inputs
47+
48+
## Failure Modes
49+
- Common errors and likely causes:
50+
- missing `gpg` installation
51+
- unreadable key/ownertrust file
52+
- invalid config options
53+
- Recovery and rollback steps:
54+
- verify file paths and permissions
55+
- reinstall/repair GPG tooling
56+
- rerun import/config commands
57+
58+
## Security Notes
59+
- Secret handling: private key imports are sensitive; use secure local storage and cleanup.
60+
- Least-privilege requirements: user-level keyring writes.
61+
- Audit/logging expectations: avoid verbose logs that expose key metadata unnecessarily.
62+
63+
## Testing
64+
- Unit tests:
65+
- option parsing and file validation
66+
- Integration tests:
67+
- import behavior with test keyring
68+
- Manual verification:
69+
- `gpg --list-secret-keys` and signing test

0 commit comments

Comments
 (0)