Skip to content

Commit fdd2e4f

Browse files
author
neil
committed
add copilot
1 parent 89c86ef commit fdd2e4f

File tree

10 files changed

+83
-16
lines changed

10 files changed

+83
-16
lines changed

.github/copilot-instructions.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# GitHub Copilot Shell Scripting (sh) Review Instructions
2+
3+
## 🎯 Overall Goal
4+
5+
Your role is to act as a rigorous yet helpful senior engineer, reviewing Shell script code (`.sh` files). Ensure the code exhibits the highest levels of robustness, security, and portability.
6+
The review must focus on risks unique to Shell scripting, such as proper quoting, robust error handling, and the secure execution of external commands.
7+
8+
## 📝 Required Output Format
9+
10+
Please adhere to the previous format: organize the feedback into a single, structured report, using the three-level marking system:
11+
12+
1. **🔴 Critical Issues (Must Fix Before Merge)**
13+
2. **🟡 Suggestions (Improvements to Consider)**
14+
3. **✅ Good Practices (Points to Commend)**
15+
16+
---
17+
18+
## 🔍 Focus Areas and Rules for Shell
19+
20+
### 1. Robustness and Error Handling
21+
22+
* **Shebang:** Check that the script starts with the correct Shebang, must be "#!/usr/bin/env sh".
23+
* **Startup Options:** **(🔴 Critical)** Enforce the use of the following combination at the start of the script for safety and robustness:
24+
* `set -e`: Exit immediately if a command exits with a non-zero status.
25+
* `set -u`: Treat unset variables as an error and exit.
26+
* `set -o pipefail`: Ensure the whole pipeline fails if any command in the pipe fails.
27+
* **Exit Codes:** Ensure functions and the main script use `exit 0` for success and a non-zero exit code upon failure.
28+
* **Temporary Files:** Check for the use of `mktemp` when creating temporary files to prevent race conditions and security risks.
29+
30+
### 2. Security and Quoting
31+
32+
* **Variable Quoting:** **(🔴 Critical)** Check that all variable expansions (like `$VAR` and `$(COMMAND)`) are properly enclosed in **double quotes** (i.e., `"$VAR"` and `"$(COMMAND)"`) to prevent **Word Splitting** and **Globbing**.
33+
* **Hardcoded Secrets:** **(🔴 Critical)** Find and flag any hardcoded passwords, keys, tokens, or authentication details.
34+
* **Untrusted Input:** Verify that all user input, command-line arguments (`$1`, `$2`, etc.), or environment variables are rigorously validated and sanitized before use.
35+
* **Avoid `eval`:** Warn against and suggest alternatives to using `eval`, as it can lead to arbitrary code execution.
36+
37+
### 3. Readability and Maintainability
38+
39+
* **Function Usage:** Recommend wrapping complex or reusable logic within clearly named functions.
40+
* **Local Variables:** Check that variables inside functions are declared using the `local` keyword to avoid unintentionally modifying global state.
41+
* **Naming Convention:** Variable names should use uppercase letters and underscores (e.g., `MY_VARIABLE`), or follow established project conventions.
42+
* **Test Conditions:** Encourage the use of Bash's **double brackets `[[ ... ]]`** for conditional tests, as it is generally safer and more powerful (e.g., supports pattern matching and avoids Word Splitting) than single brackets `[ ... ]`.
43+
* **Command Substitution:** Encourage using `$(command)` over backticks `` `command` `` for command substitution, as it is easier to nest and improves readability.
44+
45+
### 4. External Commands and Environment
46+
47+
* **`for` Loops:** Warn against patterns like `for i in $(cat file)` or `for i in $(ls)` and recommend the more robust `while IFS= read -r line` pattern for safely processing file contents or filenames that might contain spaces.
48+
* **Use existing acme.sh functions whenever possible.** For example: do not use `tr '[:upper:]' '[:lower:]'`, use `_lower_case` instead.
49+
* **Do not use `head -n`.** Use the `_head_n()` function instead.
50+
* **Do not use `curl` or `wget`.** Use the `_post()` and `_get()` functions instead.
51+
52+
---
53+
54+
### 5. Review Rules for Files Under `dnsapi/`:
55+
56+
* **Each file must contain a `{filename}_add` function** for adding DNS TXT records. It should use `_readaccountconf_mutable` to read the API key and `_saveaccountconf_mutable` to save it. Do not use `_saveaccountconf` or `_readaccountconf`.
57+
58+
59+
## ❌ Things to Avoid
60+
61+
* Do not comment on purely stylistic issues like spacing or indentation, which should be handled by tools like ShellCheck or Prettier.
62+
* Do not be overly verbose unless a significant issue is found. Keep feedback concise and actionable.
63+
64+
65+
66+
67+

.github/workflows/DNS.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ jobs:
251251
fi
252252
cd ../acmetest
253253
./letest.sh
254-
- name: onError
254+
- name: DebugOnError
255255
if: ${{ failure() }}
256256
run: |
257257
echo "See how to debug in VM:"
@@ -306,7 +306,7 @@ jobs:
306306
fi
307307
cd ../acmetest
308308
./letest.sh
309-
- name: onError
309+
- name: DebugOnError
310310
if: ${{ failure() }}
311311
run: |
312312
echo "See how to debug in VM:"
@@ -362,7 +362,7 @@ jobs:
362362
fi
363363
cd ../acmetest
364364
./letest.sh
365-
- name: onError
365+
- name: DebugOnError
366366
if: ${{ failure() }}
367367
run: |
368368
echo "See how to debug in VM:"
@@ -418,7 +418,7 @@ jobs:
418418
fi
419419
cd ../acmetest
420420
./letest.sh
421-
- name: onError
421+
- name: DebugOnError
422422
if: ${{ failure() }}
423423
run: |
424424
echo "See how to debug in VM:"
@@ -480,7 +480,7 @@ jobs:
480480
fi
481481
cd ../acmetest
482482
./letest.sh
483-
- name: onError
483+
- name: DebugOnError
484484
if: ${{ failure() }}
485485
run: |
486486
echo "See how to debug in VM:"
@@ -534,7 +534,7 @@ jobs:
534534
fi
535535
cd ../acmetest
536536
./letest.sh
537-
- name: onError
537+
- name: DebugOnError
538538
if: ${{ failure() }}
539539
run: |
540540
echo "See how to debug in VM:"
@@ -589,7 +589,7 @@ jobs:
589589
fi
590590
cd ../acmetest
591591
./letest.sh
592-
- name: onError
592+
- name: DebugOnError
593593
if: ${{ failure() }}
594594
run: |
595595
echo "See how to debug in VM:"
@@ -648,7 +648,7 @@ jobs:
648648
fi
649649
cd ../acmetest
650650
./letest.sh
651-
- name: onError
651+
- name: DebugOnError
652652
if: ${{ failure() }}
653653
run: |
654654
echo "See how to debug in VM:"

.github/workflows/DragonFlyBSD.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
run: |
6868
cd ../acmetest \
6969
&& ./letest.sh
70-
- name: onError
70+
- name: DebugOnError
7171
if: ${{ failure() }}
7272
run: |
7373
echo "See how to debug in VM:"

.github/workflows/FreeBSD.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
run: |
7373
cd ../acmetest \
7474
&& ./letest.sh
75-
- name: onError
75+
- name: DebugOnError
7676
if: ${{ failure() }}
7777
run: |
7878
echo "See how to debug in VM:"

.github/workflows/Haiku.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
run: |
7676
cd ../acmetest \
7777
&& ./letest.sh
78-
- name: onError
78+
- name: DebugOnError
7979
if: ${{ failure() }}
8080
run: |
8181
echo "See how to debug in VM:"

.github/workflows/NetBSD.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
run: |
6868
cd ../acmetest \
6969
&& ./letest.sh
70-
- name: onError
70+
- name: DebugOnError
7171
if: ${{ failure() }}
7272
run: |
7373
echo "See how to debug in VM:"

.github/workflows/Omnios.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
run: |
7272
cd ../acmetest \
7373
&& ./letest.sh
74-
- name: onError
74+
- name: DebugOnError
7575
if: ${{ failure() }}
7676
run: |
7777
echo "See how to debug in VM:"

.github/workflows/OpenBSD.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
run: |
7373
cd ../acmetest \
7474
&& ./letest.sh
75-
- name: onError
75+
- name: DebugOnError
7676
if: ${{ failure() }}
7777
run: |
7878
echo "See how to debug in VM:"

.github/workflows/OpenIndiana.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
run: |
7272
cd ../acmetest \
7373
&& ./letest.sh
74-
- name: onError
74+
- name: DebugOnError
7575
if: ${{ failure() }}
7676
run: |
7777
echo "See how to debug in VM:"

.github/workflows/Solaris.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
run: |
7474
cd ../acmetest \
7575
&& ./letest.sh
76-
- name: onError
76+
- name: DebugOnError
7777
if: ${{ failure() }}
7878
run: |
7979
echo "See how to debug in VM:"

0 commit comments

Comments
 (0)