Skip to content

Commit ae60d8f

Browse files
committed
qi.bash
1 parent 13cb4e7 commit ae60d8f

File tree

9 files changed

+862
-83
lines changed

9 files changed

+862
-83
lines changed

.github/copilot-instructions.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Bash Scripting - All repos
2+
3+
- avoid set -euo pipefail - instead focus on thorough testing, validation and error handling.
4+
- ideally error handling should be considered holistically but per function is acceptable.
5+
- changes and recommendations should be simple, modular, focused on the requirement of the prompt.
6+
- never make generalized changes that are not specifically required for the prompt.
7+
- don't over complicated the solution or pollute it with noisy or complex solutions.
8+
- Always makes changes in stages, a modular approach.
9+
- use Google style guide for formatting of bash scripts - https://google.github.io/styleguide/shellguide.html
10+
- Always use `#!/bin/bash` as the shebang.
11+
- Use `printf '%s'` for printing strings and `printf '%b'` for escape sequences. **Avoid using `echo`.**
12+
- Comment code to explain changes and logic.
13+
- always prefer readability of code over complex one lines. Unless that foramt is promoted by the style guide.
14+
- For Bash/shell questions, consult [mywiki.wooledge.org](https://mywiki.wooledge.org) or [BashFAQ](https://mywiki.wooledge.org/BashFAQ) first. **Provide a source link when possible.**
15+
16+
# GitHub Workflows - All repos
17+
18+
- In reusable workflows, jobs that use outputs from other jobs **must** include those jobs in their `needs` section to avoid null variables.
19+
- Do not use outdated GitHub Actions in workflow code. Always check the version recommended is the current version
20+
- The `gh` CLI cannot get the ID of a workflow it started with `gh run workflow`; you must list runs after and extract the ID.
21+
22+
# If repo = *-musl-cross-make
23+
GCC / Binutils
24+
- Use both `-static` and `--static` to create static toolchain binaries. Using `-static` alone can cause errors (e.g., missing POSIX threads).
25+
- When working with `../config.mak`, always load options from both `../gcc-configure-options.md` and `../gcc-configure-options-recursive.md`.
26+
- The binutils gold linker is deprecated. Use `ld=default` and `--disable-gold`.
27+
- For fully static toolchains linked to musl:
28+
- Do **not** use `-flto` or `-fuse-linker-plugin` (LTO is not supported; plugins require dynamic loading).
29+
- Do **not** add any LTO settings.
30+
- Only set linker options like `LDFLAGS` when linking, **not** when building libraries.
31+
- GNU libtool redefines `-static`; to ensure static linking, use `--static` or `-Wl,-static` in `LDFLAGS` (possibly with `-static`).
32+
- When building OpenSSL statically, do **not** use `openssl -static` (it disables threads, PIE, PIC). For `-static-pie` binaries with musl/Alpine, use the correct flags.
33+
- Do **not** suggest glibc-only flags or glibcisms for musl toolchains.
34+
35+
# Debugging with qemu
36+
37+
- To debug with QEMU:
38+
Run `qemu -g <port> <binary>` (e.g., `qemu -g 1234 ./qbt-nox-static`), then connect with `gdb ./qbt-nox-static` in another terminal.
39+
40+
# If repo = * qbittorrent-nox-static
41+
42+
## qi.bash script
43+
44+
General features
45+
- Always use `#!/bin/bash` as the shebang.
46+
- this script is focused on being a simple installer that verifies installation and binaries.
47+
48+
basic check for supported os
49+
- use source /etc/os-release
50+
- if ID = alpine of debian or if the or if ID_LIKE=debian is debian like we can proceed.
51+
- if not supported os exit with reason.
52+
53+
basic check for wget or curl, default to curl if present.
54+
- if no tools exit with reason.
55+
- wget or curl must have, curl default if present but use wget if there.
56+
- check if gh cli is available to use but no required.
57+
58+
basic check of which arch using
59+
- alpine use apk --print-arch
60+
- debian like use dpkg --print-architecture
61+
- all arches are the same except armhf. on debian this is armv7 and alpine armv6
62+
- if not valid arch exit with reason.
63+
64+
create download function based on arch checks.
65+
- configure download url based on arch.
66+
- creates sha256 of download.
67+
68+
gh cli function
69+
- if gh cli exists and is usable use it to very the binaries downloaded
70+
- if gh attestation verify <INSTALL_PATH> --repo <REPO> 2> /dev/null; then ...
71+
72+
error handling
73+
- there should be a error handling function to test commands exit the script with helpful explanations when a command or function fails.
74+
75+
ouputs
76+
- there should be a function to handle printing outputs.
77+
- It should handle [INFO] (blue) [WARNING] (yellow) [ERROR] (red) [SUCCESS] (Green) [FAILURE] (magenta)
78+
- Use `printf '%s'` for printing strings and `printf '%b'` for escape sequences. **Avoid using `echo`.**
79+
- this function will provide end user information understanding or troubleshooting script outcomes.
80+
- it should be succinct unless there is an error or failure, then it should be verbose enough to help.

.github/workflows/qi-bash.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: qi.bash tests
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- 'qi.bash'
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
test:
14+
runs-on: ${{ matrix.runs-on }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
runs-on: ["ubuntu-24.04"]
19+
arch: ["amd64", "arm32v6", "arm32v7", "arm64v8", "i386", "riscv64"]
20+
container_image: [
21+
"ubuntu:latest",
22+
"debian:latest",
23+
"alpine:edge"
24+
]
25+
include:
26+
- arch: amd64
27+
platform: linux/amd64
28+
- arch: arm32v6
29+
platform: linux/arm/v6
30+
- arch: arm32v7
31+
platform: linux/arm/v7
32+
- arch: arm64v8
33+
platform: linux/arm64
34+
- arch: i386
35+
platform: linux/i386
36+
- arch: riscv64
37+
platform: linux/riscv64
38+
exclude:
39+
- arch: i386
40+
container_image: ubuntu:latest
41+
- arch: arm32v6
42+
container_image: ubuntu:latest
43+
- arch: riscv64
44+
container_image: debian:latest
45+
- arch: arm32v6
46+
container_image: debian:latest
47+
48+
env:
49+
container_name: "build"
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
with:
54+
persist-credentials: false
55+
56+
- name: Set up QEMU
57+
uses: docker/setup-qemu-action@v3
58+
59+
- name: Create docker ${{ env.container_name }} ${{ matrix.container_image }} ${{ matrix.platform }} container
60+
run: >
61+
docker run --name ${container_name} -it -d
62+
-w /root
63+
-v ${{ github.workspace }}:/root
64+
-e "GH_TOKEN=${{ github.token }}"
65+
--platform ${{ matrix.platform }}
66+
${{ matrix.arch }}/${{ matrix.container_image }}
67+
68+
- name: Run apk update
69+
if: matrix.container_image == 'alpine:edge'
70+
run: |
71+
docker exec ${container_name} apk update
72+
docker exec ${container_name} apk add bash github-cli
73+
74+
- name: Run apk update
75+
if: matrix.container_image == 'alpine:edge'
76+
run: docker exec ${container_name} gh --version
77+
78+
- name: Run alpine apk --print-arch
79+
if: matrix.container_image == 'alpine:edge'
80+
run: |
81+
printf '\n%b\n' "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
82+
docker exec ${container_name} apk --print-arch | tee -a $GITHUB_STEP_SUMMARY
83+
printf '\n%b\n' "\`\`\`" >> $GITHUB_STEP_SUMMARY
84+
85+
- name: Run debian dpkg --print-architecture
86+
if: matrix.container_image == 'debian:latest' || matrix.container_image == 'ubuntu:latest'
87+
run: |
88+
printf '\n%b\n' "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
89+
docker exec ${container_name} dpkg --print-architecture | tee -a $GITHUB_STEP_SUMMARY
90+
printf '\n%b\n' "\`\`\`" >> $GITHUB_STEP_SUMMARY
91+
92+
- name: Run apt-get update
93+
if: matrix.container_image == 'debian:latest' || matrix.container_image == 'ubuntu:latest'
94+
run: |
95+
docker exec ${container_name} apt-get update
96+
docker exec ${container_name} apt-get install -y wget
97+
98+
- run: |
99+
chmod +x qi.bash
100+
printf '\n%b\n' "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
101+
docker exec ${container_name} bash -l qi.bash | sed 's/\x1b\[[0-9;]*m//g' | tee -a $GITHUB_STEP_SUMMARY
102+
printf '\n%b\n' "\`\`\`" >> $GITHUB_STEP_SUMMARY

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ repos:
33
hooks:
44
- id: make-scripts-executable
55
name: Make script files executable
6-
entry: bash -c 'git add --chmod=+x qbt-nox-static.bash qbittorrent-nox-static.sh'
6+
entry: bash -c 'git add --chmod=+x qi.bash qbt-nox-static.bash qbittorrent-nox-static.sh'
77
language: system
8-
files: '(qbt-nox-static\.bash|qbittorrent-nox-static\.sh)$'
8+
files: '(qi\.bash|qbt-nox-static\.bash|qbittorrent-nox-static\.sh)$'
99
pass_filenames: false
1010

1111
- repo: https://github.com/pre-commit/pre-commit-hooks

0 commit comments

Comments
 (0)