From 8184b69dd749224a8c5a9a84c87a49e3ffc5590a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E7=BF=94=E5=AE=87?= Date: Tue, 17 Feb 2026 18:53:11 +0800 Subject: [PATCH 1/6] refactor: build pipeline with template + lang pack + GPU ID automation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Separate language packs and GPU ID database from script business logic. Scripts are now templates in src/ with placeholders, built into self-contained dist/ scripts via scripts/build.py. - src/: template scripts with {{LANG_PACKS}} and {{GPU_IDS}} placeholders - lang/: per-script language packs (ZH_CN, EN_US) - data/gpu-ids.sh: auto-generated GPU PCI ID database (857 IDs, up from 294) - scripts/build.py: template + lang + data → dist/ merger with validation - scripts/extract_keys.py: gettext key analysis and translation coverage - scripts/update_gpu_ids.py: fetch pci-ids.ucw.cz and generate GPU ID mapping - .github/workflows/: CI (build+validate), release (build+upload), GPU ID auto-update - Remove root-level scripts, old language_packs/, language_pack_generate.py Co-Authored-By: Claude Opus 4.6 --- .github/workflows/ci.yml | 30 + .github/workflows/release.yml | 34 + .github/workflows/update-gpu-ids.yml | 51 + .gitignore | 4 +- PLAN.md | 546 +++ cuda-install.sh | 587 --- data/gpu-ids-overrides.sh | 37 + data/gpu-ids.sh | 175 + lang/cuda-install/EN_US.sh | 102 + lang/cuda-install/ZH_CN.sh | 102 + lang/nvidia-install/EN_US.sh | 350 ++ lang/nvidia-install/ZH_CN.sh | 350 ++ language_pack_generate.py | 132 - language_packs/EN_US.pot | 1051 ----- language_packs/ZH_CN.pot | 1046 ----- nvidia-install.sh | 3527 ----------------- scripts/build.py | 265 ++ scripts/extract_keys.py | 164 + scripts/update_gpu_ids.py | 328 ++ src/cuda-install.sh | 995 +++++ .../nvidia-container-installer.sh | 0 .../nvidia-container-uninstall.sh | 47 +- src/nvidia-install.sh | 2647 +++++++++++++ .../nvidia-uninstall.sh | 4 +- 24 files changed, 6221 insertions(+), 6353 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/update-gpu-ids.yml create mode 100644 PLAN.md delete mode 100755 cuda-install.sh create mode 100644 data/gpu-ids-overrides.sh create mode 100644 data/gpu-ids.sh create mode 100644 lang/cuda-install/EN_US.sh create mode 100644 lang/cuda-install/ZH_CN.sh create mode 100644 lang/nvidia-install/EN_US.sh create mode 100644 lang/nvidia-install/ZH_CN.sh delete mode 100644 language_pack_generate.py delete mode 100644 language_packs/EN_US.pot delete mode 100644 language_packs/ZH_CN.pot delete mode 100644 nvidia-install.sh create mode 100755 scripts/build.py create mode 100755 scripts/extract_keys.py create mode 100755 scripts/update_gpu_ids.py create mode 100644 src/cuda-install.sh rename nvidia-container-installer.sh => src/nvidia-container-installer.sh (100%) rename nvidia-container-uninstall.sh => src/nvidia-container-uninstall.sh (85%) create mode 100644 src/nvidia-install.sh rename nvidia-uninstall.sh => src/nvidia-uninstall.sh (99%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9c10079 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Build scripts + run: python3 scripts/build.py --outdir ./dist + + - name: Syntax check + run: | + for f in dist/*.sh; do + bash -n "$f" + echo "OK: $f" + done + + - name: Verify translation completeness + run: python3 scripts/build.py --check-keys diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..17b4ccb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Build and Release + +on: + release: + types: [created] + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Build scripts + run: python3 scripts/build.py --outdir ./dist + + - name: Verify syntax + run: | + for f in dist/*.sh; do + bash -n "$f" + echo "OK: $f" + done + + - name: Upload release assets + uses: softprops/action-gh-release@v2 + with: + files: dist/*.sh diff --git a/.github/workflows/update-gpu-ids.yml b/.github/workflows/update-gpu-ids.yml new file mode 100644 index 0000000..3b96a0e --- /dev/null +++ b/.github/workflows/update-gpu-ids.yml @@ -0,0 +1,51 @@ +name: Update GPU ID Database + +on: + schedule: + - cron: '0 0 * * 1' # Weekly on Monday + workflow_dispatch: # Manual trigger + +permissions: + contents: write + pull-requests: write + +jobs: + update: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Generate GPU ID database + run: python3 scripts/update_gpu_ids.py + + - name: Check for changes + id: diff + run: | + if git diff --quiet data/gpu-ids.sh; then + echo "changed=false" >> $GITHUB_OUTPUT + else + echo "changed=true" >> $GITHUB_OUTPUT + echo "## GPU ID Database Changes" >> $GITHUB_STEP_SUMMARY + git diff --stat data/gpu-ids.sh >> $GITHUB_STEP_SUMMARY + fi + + - name: Create PR if changed + if: steps.diff.outputs.changed == 'true' + uses: peter-evans/create-pull-request@v7 + with: + title: "chore: update GPU PCI device ID database" + body: | + Auto-generated from [pci-ids.ucw.cz](https://pci-ids.ucw.cz/). + + This PR updates the NVIDIA GPU PCI device ID database used for + architecture detection and open/proprietary kernel module selection. + + Please review the diff for new GPU architecture entries. + branch: auto/update-gpu-ids + commit-message: "chore: update GPU PCI device ID database" + labels: automated diff --git a/.gitignore b/.gitignore index 0f00bf7..381ce39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .vscode +__pycache__/ -language_packs/*.sh +# Build output +dist/ diff --git a/PLAN.md b/PLAN.md new file mode 100644 index 0000000..47a5749 --- /dev/null +++ b/PLAN.md @@ -0,0 +1,546 @@ +# Build Pipeline Plan: Template + CI/CD Language Pack Embedding + +## Background + +Each script in this repo is designed as a standalone single-file download. Users run: + +```bash +curl -sSL https://raw.githubusercontent.com/.../nvidia-install.sh | sudo bash +``` + +This means every script must be self-contained — no `source`, no external dependencies. Language packs (~700 lines per script) are currently copy-pasted into each script manually, leading to: + +- Duplicated translations across scripts +- Manual sync errors when updating translations +- Business logic buried under hundreds of lines of language pack data +- Painful workflow: edit `.pot` → run `language_pack_generate.py` → manually copy output into script + +## Goal + +Separate language packs from business logic at **development time**, automatically merge them at **build time**. + +--- + +## Repository Structure + +### Current + +``` +├── cuda-install.sh # Final script with embedded lang packs +├── nvidia-install.sh # Final script with embedded lang packs +├── nvidia-container-installer.sh +├── nvidia-container-uninstall.sh +├── nvidia-uninstall.sh +├── language_packs/ +│ ├── ZH_CN.pot # nvidia-install.sh translations (source) +│ ├── ZH_CN.sh # nvidia-install.sh translations (generated) +│ ├── EN_US.pot +│ └── EN_US.sh +└── language_pack_generate.py # .pot → .sh converter +``` + +### Proposed + +``` +├── src/ # Template scripts (no embedded lang packs) +│ ├── nvidia-install.sh +│ ├── cuda-install.sh +│ ├── nvidia-container-installer.sh +│ ├── nvidia-container-uninstall.sh +│ └── nvidia-uninstall.sh +│ +├── lang/ # Language packs, organized by script +│ ├── nvidia-install/ +│ │ ├── ZH_CN.sh +│ │ └── EN_US.sh +│ ├── cuda-install/ +│ │ ├── ZH_CN.sh +│ │ └── EN_US.sh +│ ├── nvidia-container-installer/ +│ │ ├── ZH_CN.sh +│ │ └── EN_US.sh +│ ├── nvidia-container-uninstall/ +│ │ ├── ZH_CN.sh +│ │ └── EN_US.sh +│ └── nvidia-uninstall/ +│ ├── ZH_CN.sh +│ └── EN_US.sh +│ +├── scripts/ +│ ├── build.py # Template + lang packs → final scripts +│ └── extract_keys.py # Extract gettext keys from src/ for translation +│ +├── dist/ # Build output (gitignored) +│ ├── nvidia-install.sh +│ ├── cuda-install.sh +│ └── ... +│ +├── .github/workflows/ +│ └── release.yml # Auto-build on release +│ +├── language_packs/ # Deprecated, migrated to lang/ +├── language_pack_generate.py # Deprecated, replaced by scripts/build.py +└── PLAN.md +``` + +--- + +## Template Format + +### Placeholder in `src/*.sh` + +Each template script contains a single placeholder where language packs will be injected: + +```bash +#!/bin/bash + +set -eo pipefail + +readonly SCRIPT_VERSION="2.2" + +# Color definitions... +# Exit code definitions... +# Global variables... + +# ================ Language Packs ================== +# {{LANG_PACKS}} +# ================ Language Packs End ============== + +gettext() { + local msgid="$1" + local translation="" + case "$LANG_CURRENT" in + "zh-cn"|"zh"|"zh_CN") translation="${LANG_PACK_ZH_CN[$msgid]:-}" ;; + "en-us"|"en"|"en_US") translation="${LANG_PACK_EN_US[$msgid]:-}" ;; + *) translation="${LANG_PACK_ZH_CN[$msgid]:-}" ;; + esac + if [[ -z "$translation" ]]; then + translation="$msgid" # Fallback: return key itself + fi + printf '%s' "$translation" +} + +# ... rest of business logic ... +``` + +### Language Pack Files (`lang/