@hybridlabor-api/aos 4.7.2 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/agents.md +1 -1
- package/.agents/nodes.json +1 -1
- package/.agents/vendor-manifest.json +23 -1
- package/.claude/agents/godmode-media-eventtech.md +1 -1
- package/.claude/hooks/conventional-commits.mjs +125 -0
- package/.claude/hooks/env-file-protection.mjs +105 -0
- package/.claude/hooks/go-gate.mjs +101 -81
- package/.claude/settings.json +13 -0
- package/.opencode/agents/godmode-media-eventtech.md +1 -1
- package/.opencode/plugins/bdb-aos.js +31 -4
- package/README.de.md +1 -1
- package/README.md +1 -1
- package/README.pt.md +1 -1
- package/THIRD_PARTY_NOTICES.md +88 -0
- package/docs/skills_table.md +1 -1
- package/installer.js +309 -101
- package/package.json +6 -2
- package/packages/aos-cli/README.md +80 -0
- package/packages/aos-cli/bin/aos-cli.mjs +134 -0
- package/packages/aos-cli/core-skills.json +12 -0
- package/packages/aos-cli/extensions/aos.ts +321 -0
- package/packages/aos-cli/package-lock.json +1923 -0
- package/packages/aos-cli/package.json +29 -0
- package/packages/aos-cli/scripts/check-theme.mjs +63 -0
- package/packages/aos-cli/themes/aos.json +97 -0
- package/scripts/build-plugin-manifest.mjs +131 -0
- package/scripts/validate-skills.mjs +81 -6
- package/skills/basic/ao-orchestrator/SKILL.md +116 -0
- package/skills/global_config/agenttrail/SKILL.md +6 -1
- package/skills/global_config/ask-tim/SKILL.md +4 -4
- package/skills/global_config/bash-script-generator/SKILL.md +201 -0
- package/skills/global_config/bash-script-generator/assets/templates/standard-template.sh +96 -0
- package/skills/global_config/bash-script-generator/docs/bash-scripting-guide.md +729 -0
- package/skills/global_config/bash-script-generator/docs/generation-best-practices.md +193 -0
- package/skills/global_config/bash-script-generator/docs/script-patterns.md +566 -0
- package/skills/global_config/bash-script-generator/docs/text-processing-guide.md +437 -0
- package/skills/global_config/bash-script-generator/examples/log-analyzer.sh +92 -0
- package/skills/global_config/bash-script-generator/scripts/generate_script_template.sh +123 -0
- package/skills/global_config/bash-script-generator/scripts/run_ci_checks.sh +172 -0
- package/skills/global_config/bash-script-generator/scripts/test_generator.sh +413 -0
- package/skills/global_config/bash-script-validator/SKILL.md +249 -0
- package/skills/global_config/bash-script-validator/docs/awk-reference.md +449 -0
- package/skills/global_config/bash-script-validator/docs/bash-reference.md +468 -0
- package/skills/global_config/bash-script-validator/docs/common-mistakes.md +623 -0
- package/skills/global_config/bash-script-validator/docs/grep-reference.md +395 -0
- package/skills/global_config/bash-script-validator/docs/regex-reference.md +391 -0
- package/skills/global_config/bash-script-validator/docs/sed-reference.md +454 -0
- package/skills/global_config/bash-script-validator/docs/shell-reference.md +463 -0
- package/skills/global_config/bash-script-validator/docs/shellcheck-reference.md +399 -0
- package/skills/global_config/bash-script-validator/examples/bad-bash.sh +55 -0
- package/skills/global_config/bash-script-validator/examples/bad-shell.sh +54 -0
- package/skills/global_config/bash-script-validator/examples/good-bash.sh +71 -0
- package/skills/global_config/bash-script-validator/examples/good-shell.sh +69 -0
- package/skills/global_config/bash-script-validator/scripts/run_ci_checks.sh +23 -0
- package/skills/global_config/bash-script-validator/scripts/shellcheck_wrapper.sh +174 -0
- package/skills/global_config/bash-script-validator/scripts/test_validate.sh +446 -0
- package/skills/global_config/bash-script-validator/scripts/validate.sh +512 -0
- package/skills/global_config/ci-pipeline/SKILL.md +135 -0
- package/skills/global_config/dispatching-parallel-agents/SKILL.md +170 -0
- package/skills/global_config/dockerfile-generator/SKILL.md +1038 -0
- package/skills/global_config/dockerfile-generator/examples/example.dockerignore +95 -0
- package/skills/global_config/dockerfile-generator/examples/golang-distroless.Dockerfile +34 -0
- package/skills/global_config/dockerfile-generator/examples/java-springboot.Dockerfile +45 -0
- package/skills/global_config/dockerfile-generator/examples/nextjs-production.Dockerfile +49 -0
- package/skills/global_config/dockerfile-generator/examples/nodejs-multistage.Dockerfile +55 -0
- package/skills/global_config/dockerfile-generator/examples/python-fastapi.Dockerfile +48 -0
- package/skills/global_config/dockerfile-generator/references/language_specific_guides.md +510 -0
- package/skills/global_config/dockerfile-generator/references/multistage_builds.md +570 -0
- package/skills/global_config/dockerfile-generator/references/optimization_patterns.md +492 -0
- package/skills/global_config/dockerfile-generator/references/security_best_practices.md +375 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_dockerignore.sh +199 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_golang.sh +172 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_java.sh +185 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_nodejs.sh +279 -0
- package/skills/global_config/dockerfile-generator/scripts/generate_python.sh +218 -0
- package/skills/global_config/dockerfile-generator/scripts/test_generator.sh +210 -0
- package/skills/global_config/dockerfile-validator/SKILL.md +300 -0
- package/skills/global_config/dockerfile-validator/examples/.dockerignore.example +34 -0
- package/skills/global_config/dockerfile-validator/examples/bad-example.Dockerfile +37 -0
- package/skills/global_config/dockerfile-validator/examples/golang-distroless.Dockerfile +50 -0
- package/skills/global_config/dockerfile-validator/examples/good-example.Dockerfile +52 -0
- package/skills/global_config/dockerfile-validator/examples/python-optimized.Dockerfile +53 -0
- package/skills/global_config/dockerfile-validator/examples/security-issues.Dockerfile +42 -0
- package/skills/global_config/dockerfile-validator/references/docker_best_practices.md +348 -0
- package/skills/global_config/dockerfile-validator/references/optimization_guide.md +473 -0
- package/skills/global_config/dockerfile-validator/references/security_checklist.md +208 -0
- package/skills/global_config/dockerfile-validator/scripts/dockerfile-validate.sh +699 -0
- package/skills/global_config/dockerfile-validator/scripts/test_validate.sh +35 -0
- package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn-lock-read.Dockerfile +6 -0
- package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn.Dockerfile +6 -0
- package/skills/global_config/dockerfile-validator/tests/fixtures/from-platform-nonroot.Dockerfile +7 -0
- package/skills/global_config/dockerfile-validator/tests/test_regression.sh +164 -0
- package/skills/global_config/finishing-a-development-branch/SKILL.md +228 -0
- package/skills/global_config/github-actions-generator/SKILL.md +353 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/composite/action.yml +82 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/docker/Dockerfile +25 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/docker/action.yml +42 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/docker/entrypoint.sh +27 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/javascript/action.yml +33 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/javascript/index.js +50 -0
- package/skills/global_config/github-actions-generator/assets/templates/action/javascript/package.json +27 -0
- package/skills/global_config/github-actions-generator/assets/templates/workflow/basic_workflow.yml +242 -0
- package/skills/global_config/github-actions-generator/assets/templates/workflow/reusable_workflow.yml +106 -0
- package/skills/global_config/github-actions-generator/examples/README.md +147 -0
- package/skills/global_config/github-actions-generator/examples/actions/setup-node-cached/action.yml +93 -0
- package/skills/global_config/github-actions-generator/examples/caching/docker-buildkit.yml +256 -0
- package/skills/global_config/github-actions-generator/examples/security/dependency-review.yml +62 -0
- package/skills/global_config/github-actions-generator/examples/security/sbom-attestation.yml +119 -0
- package/skills/global_config/github-actions-generator/examples/triggers/chatops-commands.yml +475 -0
- package/skills/global_config/github-actions-generator/examples/triggers/repository-dispatch.yml +418 -0
- package/skills/global_config/github-actions-generator/examples/triggers/workflow-orchestration.yml +404 -0
- package/skills/global_config/github-actions-generator/examples/workflows/docker-build-push.yml +68 -0
- package/skills/global_config/github-actions-generator/examples/workflows/go-ci.yml +161 -0
- package/skills/global_config/github-actions-generator/examples/workflows/monorepo-ci.yml +340 -0
- package/skills/global_config/github-actions-generator/examples/workflows/multi-environment-deploy.yml +406 -0
- package/skills/global_config/github-actions-generator/examples/workflows/nodejs-ci.yml +122 -0
- package/skills/global_config/github-actions-generator/examples/workflows/python-ci.yml +157 -0
- package/skills/global_config/github-actions-generator/examples/workflows/scheduled-tasks.yml +376 -0
- package/skills/global_config/github-actions-generator/references/advanced-triggers.md +917 -0
- package/skills/global_config/github-actions-generator/references/best-practices.md +755 -0
- package/skills/global_config/github-actions-generator/references/common-actions.md +715 -0
- package/skills/global_config/github-actions-generator/references/custom-actions.md +320 -0
- package/skills/global_config/github-actions-generator/references/expressions-and-contexts.md +688 -0
- package/skills/global_config/github-actions-generator/references/modern-features.md +421 -0
- package/skills/global_config/github-actions-generator/scripts/test_generator.sh +344 -0
- package/skills/global_config/github-actions-templates/SKILL.md +7 -0
- package/skills/global_config/github-actions-validator/SKILL.md +576 -0
- package/skills/global_config/github-actions-validator/examples/README.md +88 -0
- package/skills/global_config/github-actions-validator/examples/outdated-versions.yml +76 -0
- package/skills/global_config/github-actions-validator/examples/valid-ci.yml +79 -0
- package/skills/global_config/github-actions-validator/examples/with-errors.yml +47 -0
- package/skills/global_config/github-actions-validator/references/act_usage.md +233 -0
- package/skills/global_config/github-actions-validator/references/action_versions.md +122 -0
- package/skills/global_config/github-actions-validator/references/actionlint_usage.md +343 -0
- package/skills/global_config/github-actions-validator/references/common_errors.md +512 -0
- package/skills/global_config/github-actions-validator/references/modern_features.md +384 -0
- package/skills/global_config/github-actions-validator/references/runners.md +317 -0
- package/skills/global_config/github-actions-validator/scripts/install_tools.sh +113 -0
- package/skills/global_config/github-actions-validator/scripts/validate_workflow.sh +910 -0
- package/skills/global_config/github-actions-validator/tests/test_validate_workflow.sh +237 -0
- package/skills/global_config/makefile-generator/SKILL.md +614 -0
- package/skills/global_config/makefile-generator/assets/templates/.gitkeep +1 -0
- package/skills/global_config/makefile-generator/docs/makefile-structure.md +530 -0
- package/skills/global_config/makefile-generator/docs/optimization-guide.md +784 -0
- package/skills/global_config/makefile-generator/docs/patterns-guide.md +642 -0
- package/skills/global_config/makefile-generator/docs/security-guide.md +361 -0
- package/skills/global_config/makefile-generator/docs/targets-guide.md +642 -0
- package/skills/global_config/makefile-generator/docs/variables-guide.md +596 -0
- package/skills/global_config/makefile-generator/scripts/add_standard_targets.sh +539 -0
- package/skills/global_config/makefile-generator/scripts/generate_makefile_template.sh +690 -0
- package/skills/global_config/makefile-generator/test/test_helper_scripts.sh +190 -0
- package/skills/global_config/makefile-validator/SKILL.md +244 -0
- package/skills/global_config/makefile-validator/docs/bake-tool.md +1000 -0
- package/skills/global_config/makefile-validator/docs/best-practices.md +858 -0
- package/skills/global_config/makefile-validator/docs/common-mistakes.md +944 -0
- package/skills/global_config/makefile-validator/examples/bad-makefile.mk +77 -0
- package/skills/global_config/makefile-validator/examples/good-makefile.mk +103 -0
- package/skills/global_config/makefile-validator/scripts/test_validate.sh +382 -0
- package/skills/global_config/makefile-validator/scripts/validate_makefile.sh +712 -0
- package/skills/global_config/{MCP_Manage → mcp-manage}/SKILL.md +3 -3
- package/skills/global_config/requesting-code-review/SKILL.md +98 -0
- package/skills/global_config/requesting-code-review/code-reviewer.md +198 -0
- package/skills/global_config/using-git-worktrees/SKILL.md +170 -0
- package/skills/global_config/verification-before-completion/SKILL.md +123 -0
- package/skills/global_config/writing-plans/SKILL.md +126 -46
- package/skills/global_config/writing-plans-legacy/SKILL.md +139 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bash-script-generator
|
|
3
|
+
description: Create, generate, write, or scaffold bash/shell scripts (.sh), automation, or CLI tools.
|
|
4
|
+
category: engineering-method
|
|
5
|
+
source: cc-devops-skills
|
|
6
|
+
date_added: "2026-09-25"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Bash Script Generator
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Generate production-ready Bash scripts with clear requirements capture, deterministic generation flow, and validation-first iteration.
|
|
14
|
+
|
|
15
|
+
## Trigger Phrases
|
|
16
|
+
|
|
17
|
+
Use this skill when the user asks to:
|
|
18
|
+
- Create, generate, write, or build a Bash/shell script
|
|
19
|
+
- Convert manual CLI steps into an automation script
|
|
20
|
+
- Build a text-processing script using `grep`, `awk`, or `sed`
|
|
21
|
+
- Create an operations helper script, cron script, or CI utility script
|
|
22
|
+
|
|
23
|
+
Do not use this skill for validating an existing script only. Use `bash-script-validator` for validation-only requests.
|
|
24
|
+
|
|
25
|
+
## Execution Model
|
|
26
|
+
|
|
27
|
+
Follow stages in order. Do not skip a stage; use the documented fallback when blocked.
|
|
28
|
+
|
|
29
|
+
### Stage 0: Preflight
|
|
30
|
+
|
|
31
|
+
1. Confirm scope and target output path.
|
|
32
|
+
2. Confirm shell target:
|
|
33
|
+
- Default: `bash`
|
|
34
|
+
- If portability is requested: POSIX `sh`
|
|
35
|
+
3. Check capabilities and pick fallback path:
|
|
36
|
+
|
|
37
|
+
| Capability | Default Path | Fallback Path |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| Requirement clarification | AskUserQuestion tool | Ask same questions in normal chat; mark unresolved items as assumptions |
|
|
40
|
+
| Script scaffold | `bash scripts/generate_script_template.sh ...` | Copy `assets/templates/standard-template.sh` manually or hand-craft minimal scaffold |
|
|
41
|
+
| Validation | `bash-script-validator` | Local checks: `bash -n`, `shellcheck` if available, `sh -n` for POSIX mode |
|
|
42
|
+
|
|
43
|
+
If a fallback path is used, state it explicitly in the final summary.
|
|
44
|
+
|
|
45
|
+
### Stage 1: Capture Requirements
|
|
46
|
+
|
|
47
|
+
Collect only what is needed to generate the script correctly:
|
|
48
|
+
- Input source and format
|
|
49
|
+
- Output destination and format
|
|
50
|
+
- Error handling behavior (fail-fast/retry/continue)
|
|
51
|
+
- Security constraints (sensitive data, privilege level)
|
|
52
|
+
- Performance constraints (large files, parallelism)
|
|
53
|
+
- Portability requirement (Bash-only vs POSIX)
|
|
54
|
+
|
|
55
|
+
Then create a `Captured Requirements` table with stable IDs.
|
|
56
|
+
|
|
57
|
+
```markdown
|
|
58
|
+
## Captured Requirements
|
|
59
|
+
|
|
60
|
+
| Requirement ID | Description | Source | Implementation Plan |
|
|
61
|
+
|---|---|---|---|
|
|
62
|
+
| REQ-001 | Parse nginx logs from file input | User | `parse_args()` + `validate_file()` + `awk` parser |
|
|
63
|
+
| REQ-002 | Output top 10 errors | User | `analyze_errors()` + `sort | uniq -c | head -10` |
|
|
64
|
+
| REQ-003 | Handle large files efficiently | Assumption | Single-pass `awk`; avoid multi-pass loops |
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Rules:
|
|
68
|
+
- Every major design decision maps to at least one `REQ-*`.
|
|
69
|
+
- Keep assumptions explicit and minimal.
|
|
70
|
+
|
|
71
|
+
### Stage 2: Choose Generation Path
|
|
72
|
+
|
|
73
|
+
Use this deterministic decision tree:
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
Need multi-command architecture, unusual control flow, or strict non-template conventions?
|
|
77
|
+
├─ Yes -> Custom generation
|
|
78
|
+
└─ No
|
|
79
|
+
Need standard CLI skeleton (usage/logging/arg parsing/cleanup)?
|
|
80
|
+
├─ Yes -> Template-first generation
|
|
81
|
+
└─ No -> Custom generation
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Template-first is the default for single-purpose CLI utilities.
|
|
85
|
+
|
|
86
|
+
### Stage 3: Load Only Relevant References
|
|
87
|
+
|
|
88
|
+
Use progressive disclosure. Read only docs needed for the current request.
|
|
89
|
+
|
|
90
|
+
| Need | Reference |
|
|
91
|
+
|---|---|
|
|
92
|
+
| Tool choice (`grep` vs `awk` vs `sed`) | `docs/text-processing-guide.md` |
|
|
93
|
+
| Script structure and argument patterns | `docs/script-patterns.md` |
|
|
94
|
+
| Strict mode, shell differences, safety | `docs/bash-scripting-guide.md` |
|
|
95
|
+
| Naming, organization, and quality baseline | `docs/generation-best-practices.md` |
|
|
96
|
+
|
|
97
|
+
Citation format (required):
|
|
98
|
+
- `[Ref: docs/<file>.md -> <section>]`
|
|
99
|
+
|
|
100
|
+
### Stage 4: Generate Script
|
|
101
|
+
|
|
102
|
+
#### Path A: Template-first (default)
|
|
103
|
+
|
|
104
|
+
1. Generate scaffold:
|
|
105
|
+
```bash
|
|
106
|
+
bash scripts/generate_script_template.sh standard output-script.sh
|
|
107
|
+
```
|
|
108
|
+
2. Replace placeholders and add business logic.
|
|
109
|
+
3. Keep logging to stderr and data output to stdout unless requirements say otherwise.
|
|
110
|
+
4. Add comments only where logic is non-obvious.
|
|
111
|
+
|
|
112
|
+
#### Path B: Custom generation
|
|
113
|
+
|
|
114
|
+
Build a script with at least:
|
|
115
|
+
- Shebang and strict mode
|
|
116
|
+
- `usage()`
|
|
117
|
+
- `parse_args()`
|
|
118
|
+
- Input validation and dependency checks
|
|
119
|
+
- Main workflow function(s)
|
|
120
|
+
- Predictable exit codes
|
|
121
|
+
|
|
122
|
+
### Stage 5: Validate and Iterate
|
|
123
|
+
|
|
124
|
+
Default validation path:
|
|
125
|
+
1. Invoke `bash-script-validator`
|
|
126
|
+
2. Apply fixes
|
|
127
|
+
3. Re-run validation
|
|
128
|
+
4. Repeat until checks pass or blocker is identified
|
|
129
|
+
|
|
130
|
+
Fallback validation path (when validator skill is unavailable):
|
|
131
|
+
```bash
|
|
132
|
+
# Deterministic local gate for this skill:
|
|
133
|
+
bash scripts/run_ci_checks.sh --skip-shellcheck
|
|
134
|
+
|
|
135
|
+
# CI gate (shellcheck required):
|
|
136
|
+
bash scripts/run_ci_checks.sh --require-shellcheck
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
If any check is skipped, include `Skipped check`, `Reason`, and `Risk` in the output.
|
|
140
|
+
|
|
141
|
+
### Stage 6: Final Response Contract
|
|
142
|
+
|
|
143
|
+
Always return:
|
|
144
|
+
1. Generated script path
|
|
145
|
+
2. Requirements traceability (`REQ-*` -> implementation)
|
|
146
|
+
3. Validation results with rerun status
|
|
147
|
+
4. Citations in standard format
|
|
148
|
+
5. Any assumptions/fallbacks used
|
|
149
|
+
|
|
150
|
+
## Canonical Example Flows
|
|
151
|
+
|
|
152
|
+
### Example A: Full Flow (Template-first)
|
|
153
|
+
|
|
154
|
+
1. Clarify missing data format and output expectations.
|
|
155
|
+
2. Capture `REQ-*` table.
|
|
156
|
+
3. Choose template-first path.
|
|
157
|
+
4. Generate scaffold with `scripts/generate_script_template.sh`.
|
|
158
|
+
5. Implement logic and map functions to `REQ-*`.
|
|
159
|
+
6. Validate with `bash-script-validator` and rerun until clean.
|
|
160
|
+
7. Return final summary with citations.
|
|
161
|
+
|
|
162
|
+
### Example B: Constrained Environment Flow
|
|
163
|
+
|
|
164
|
+
Use this when AskUserQuestion, validator skill, or `shellcheck` is unavailable:
|
|
165
|
+
1. Ask clarifying questions in chat.
|
|
166
|
+
2. Mark unresolved items as assumptions in `Captured Requirements`.
|
|
167
|
+
3. Generate from template script or template file copy fallback.
|
|
168
|
+
4. Run `bash -n` (and `sh -n` if relevant).
|
|
169
|
+
5. If `shellcheck` is missing, report skip with risk and mitigation.
|
|
170
|
+
|
|
171
|
+
## Done Criteria
|
|
172
|
+
|
|
173
|
+
The task is complete only when all items are true:
|
|
174
|
+
- Trigger matched and scope confirmed
|
|
175
|
+
- `Captured Requirements` table exists with `REQ-*` IDs
|
|
176
|
+
- Template-first vs custom decision is documented
|
|
177
|
+
- Script is generated with deterministic structure
|
|
178
|
+
- Validation executed and rerun policy applied
|
|
179
|
+
- Any skipped checks include explicit reason and risk
|
|
180
|
+
- Final response includes traceability, citations, and assumptions
|
|
181
|
+
|
|
182
|
+
## Helper Scripts and Assets
|
|
183
|
+
|
|
184
|
+
- Script generator: `scripts/generate_script_template.sh`
|
|
185
|
+
- Deterministic CI gate: `scripts/run_ci_checks.sh`
|
|
186
|
+
- Regression test suite: `scripts/test_generator.sh`
|
|
187
|
+
- Standard scaffold: `assets/templates/standard-template.sh`
|
|
188
|
+
- Example output style: `examples/log-analyzer.sh`
|
|
189
|
+
|
|
190
|
+
## Reference Docs
|
|
191
|
+
|
|
192
|
+
- `docs/bash-scripting-guide.md`
|
|
193
|
+
- `docs/script-patterns.md`
|
|
194
|
+
- `docs/generation-best-practices.md`
|
|
195
|
+
- `docs/text-processing-guide.md`
|
|
196
|
+
|
|
197
|
+
## External References
|
|
198
|
+
|
|
199
|
+
- [GNU Bash Manual](https://www.gnu.org/software/bash/manual/bash.html)
|
|
200
|
+
- [POSIX Shell Specification](https://pubs.opengroup.org/onlinepubs/9699919799/)
|
|
201
|
+
- [ShellCheck](https://www.shellcheck.net/)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# Script Name: SCRIPT_NAME
|
|
4
|
+
# Description: Brief description of what this script does
|
|
5
|
+
# Usage: SCRIPT_NAME [OPTIONS] ARGUMENTS
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
set -euo pipefail
|
|
9
|
+
IFS=$'\n\t'
|
|
10
|
+
|
|
11
|
+
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
12
|
+
readonly SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
|
|
13
|
+
readonly VERSION="1.0.0"
|
|
14
|
+
|
|
15
|
+
VERBOSE=false
|
|
16
|
+
DRY_RUN=false
|
|
17
|
+
LOG_LEVEL=1 # 0=DEBUG 1=INFO 2=WARN 3=ERROR
|
|
18
|
+
|
|
19
|
+
usage() {
|
|
20
|
+
cat << EOF
|
|
21
|
+
Usage: ${SCRIPT_NAME} [OPTIONS] [ARGUMENTS]
|
|
22
|
+
|
|
23
|
+
Description:
|
|
24
|
+
Brief description of what the script does
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
-h, --help Show this help message and exit
|
|
28
|
+
-v, --verbose Enable verbose output
|
|
29
|
+
-d, --debug Enable debug mode
|
|
30
|
+
-n, --dry-run Perform dry run without making changes
|
|
31
|
+
|
|
32
|
+
Examples:
|
|
33
|
+
${SCRIPT_NAME} -v file.txt
|
|
34
|
+
${SCRIPT_NAME} --dry-run input.txt output.txt
|
|
35
|
+
|
|
36
|
+
EOF
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
log() {
|
|
40
|
+
local level="$1"
|
|
41
|
+
shift
|
|
42
|
+
echo "[${level}] $(date '+%Y-%m-%d %H:%M:%S') - $*" >&2
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
log_debug() { if [[ ${LOG_LEVEL} -le 0 ]]; then log "DEBUG" "$@"; fi; }
|
|
46
|
+
log_info() { if [[ ${LOG_LEVEL} -le 1 ]]; then log "INFO" "$@"; fi; }
|
|
47
|
+
log_warn() { if [[ ${LOG_LEVEL} -le 2 ]]; then log "WARN" "$@"; fi; }
|
|
48
|
+
log_error() { log "ERROR" "$@"; }
|
|
49
|
+
|
|
50
|
+
die() {
|
|
51
|
+
log_error "$@"
|
|
52
|
+
exit 1
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
check_command() {
|
|
56
|
+
command -v "$1" &> /dev/null || die "Required command not found: $1"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
validate_file() {
|
|
60
|
+
[[ -f "$1" ]] || die "File not found: $1"
|
|
61
|
+
[[ -r "$1" ]] || die "File not readable: $1"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
cleanup() {
|
|
65
|
+
local exit_code=$?
|
|
66
|
+
log_debug "Cleaning up..."
|
|
67
|
+
exit "${exit_code}"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
parse_args() {
|
|
71
|
+
while [[ $# -gt 0 ]]; do
|
|
72
|
+
case "$1" in
|
|
73
|
+
-h|--help) usage; exit 0 ;;
|
|
74
|
+
-v|--verbose) VERBOSE=true; shift ;;
|
|
75
|
+
-d|--debug) LOG_LEVEL=0; VERBOSE=true; shift ;;
|
|
76
|
+
-n|--dry-run) DRY_RUN=true; shift ;;
|
|
77
|
+
-*) die "Unknown option: $1" ;;
|
|
78
|
+
*) break ;;
|
|
79
|
+
esac
|
|
80
|
+
done
|
|
81
|
+
ARGS=("$@")
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
main() {
|
|
85
|
+
parse_args "$@"
|
|
86
|
+
|
|
87
|
+
log_info "Starting ${SCRIPT_NAME}..."
|
|
88
|
+
|
|
89
|
+
# Main logic goes here
|
|
90
|
+
|
|
91
|
+
log_info "Completed successfully"
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
trap cleanup EXIT ERR INT TERM
|
|
95
|
+
|
|
96
|
+
main "$@"
|