Install Script Generator
Generate robust, cross-platform installation scripts that users can run with a single bash command via GitHub raw URLs.
Repo Sync Before Edits (mandatory)
Before creating/updating/deleting files in an existing repository, sync the current branch with remote:
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin
git pull --rebase origin "$branch"
If the working tree is not clean, stash first, sync, then restore:
git stash push -u -m "pre-sync"
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin && git pull --rebase origin "$branch"
git stash pop
If origin is missing, pull is unavailable, or rebase/stash conflicts occur, stop and ask the user before continuing.
Primary Goal
Generate a self-contained install.sh script that:
- Detects the user's OS, architecture, and package manager automatically
- Installs all dependencies and the target software
- Verifies the installation
- Can be executed via a one-liner using GitHub raw user content:
curl -sSL https://raw.githubusercontent.com/<owner>/<repo>/<branch>/install.sh | bash
or with wget:
wget -qO- https://raw.githubusercontent.com/<owner>/<repo>/<branch>/install.sh | bash
Workflow
Phase 1: Environment Exploration
Before generating the script, understand the project context:
- Identify the target — What software/module/tool is being installed?
- Check the repository — Look for existing build files,
Makefile,package.json,setup.py,Cargo.toml,go.mod, etc. - Identify dependencies — What does the software need to build/run?
- Determine the GitHub repo — The
<owner>/<repo>for the raw URL (check git remote or ask user)
Run the environment explorer for local testing:
python3 scripts/env_explorer.py
The script detects:
- Operating system (Windows/Linux/macOS) and version
- CPU architecture (x86_64, ARM64, etc.)
- Package managers available (apt, yum, brew, choco, winget)
- Shell environment (bash, zsh, powershell, cmd)
- Existing dependencies and versions
- User permissions (admin/sudo availability)
Phase 2: Installation Planning
Based on the environment analysis and target software:
- Identify dependencies — List all required packages/libraries
- Check existing installations — Avoid reinstalling what exists
- Order operations — Resolve dependency graph
- Add verification steps — Each step must be verifiable
- Plan rollback — Define cleanup on failure
Use the plan generator for structured planning:
python3 scripts/plan_generator.py --target "<software_name>" --env-file env_info.json
Phase 3: Script Generation (Primary Output)
Generate a self-contained install.sh script at the project root. The script MUST follow this structure:
#!/usr/bin/env bash
set -euo pipefail
# ============================================================================
# <Software Name> Installer
# Usage: curl -sSL https://raw.githubusercontent.com/<owner>/<repo>/<branch>/install.sh | bash
# ============================================================================
# --- Configuration ---
TOOL_NAME="<software_name>"
REPO_OWNER="<owner>"
REPO_NAME="<repo>"
DEFAULT_BRANCH="<branch>"
INSTALL_PREFIX="${INSTALL_PREFIX:-/usr/local}"
# --- Color Output ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
info() { printf "${BLUE}[INFO]${NC} %s\n" "$*"; }
ok() { printf "${GREEN}[ OK ]${NC} %s\n" "$*"; }
warn() { printf "${YELLOW}[WARN]${NC} %s\n" "$*"; }
err() { printf "${RED}[ERR ]${NC} %s\n" "$*" >&2; }
die() { err "$@"; exit 1; }
# --- OS / Arch Detection ---
detect_os() {
local os
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
case "$os" in
linux*) echo "linux" ;;
darwin*) echo "macos" ;;
mingw*|msys*|cygwin*) echo "windows" ;;
*) die "Unsupported operating system: $os" ;;
esac
}
detect_arch() {
local arch
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) echo "x86_64" ;;
aarch64|arm64) echo "arm64" ;;
armv7l) echo "armv7" ;;
*) die "Unsupported architecture: $arch" ;;
esac
}
detect_package_manager() {
if command -v apt-get &>/dev/null; then echo "apt"
elif command -v dnf &>/dev/null; then echo "dnf"
elif command -v yum &>/dev/null; then echo "yum"
elif command -v pacman &>/dev/null; then echo "pacman"
elif command -v brew &>/dev/null; then echo "brew"
elif command -v zypper &>/dev/null; then echo "zypper"
else echo "unknown"
fi
}
need_sudo() {
if [ "$(id -u)" -ne 0 ]; then
if command -v sudo &>/dev/null; then
echo "sudo"
else
die "This script requires root privileges. Please run as root or install sudo."
fi
else
echo ""
fi
}
# --- Dependency Installation ---
install_deps() {
local pm="$1"
local sudo_cmd="$2"
shift 2
local deps=("$@")
[ ${#deps[@]} -eq 0 ] && return 0
info "Installing dependencies: ${deps[*]}"
case "$pm" in
apt) $sudo_cmd apt-get update -qq && $sudo_cmd apt-get install -y -qq "${deps[@]}" ;;
dnf) $sudo_cmd dnf install -y -q "${deps[@]}" ;;
yum) $sudo_cmd yum install -y -q "${deps[@]}" ;;
pacman) $sudo_cmd pacman -Sy --noconfirm "${deps[@]}" ;;
brew) brew install "${deps[@]}" ;;
zypper) $sudo_cmd zypper install -y "${deps[@]}" ;;
*) die "Cannot install dependencies: unsupported package manager '$pm'" ;;
esac
ok "Dependencies installed"
}
# --- Main Installation Logic ---
install_<tool>() {
# ... tool-specific installation steps ...
# This section is customized per target software
:
}
# --- Verification ---
verify_installation() {
info "Verifying installation..."
if command -v "$TOOL_NAME" &>/dev/null; then
ok "$TOOL_NAME $(${TOOL_NAME} --version 2>/dev/null || echo '') installed successfully"
else
die "$TOOL_NAME installation could not be verified"
fi
}
# --- Entry Point ---
main() {
info "Installing $TOOL_NAME"
info "============================================"
local os arch pm sudo_cmd
os="$(detect_os)"
arch="$(detect_arch)"
pm="$(detect_package_manager)"
sudo_cmd="$(need_sudo)"
info "OS: $os | Arch: $arch | Package Manager: $pm"
# Install dependencies (customize per target)
# install_deps "$pm" "$sudo_cmd" dep1 dep2 dep3
# Install the tool
install_<tool>
# Verify
verify_installation
info "============================================"
ok "Installation complete!"
info "Run '$TOOL_NAME --help' to get started."
}
main "$@"
Script Requirements
The generated install.sh MUST:
- Start with
#!/usr/bin/env bashandset -euo pipefail - Be fully self-contained (no external script dependencies)
- Auto-detect OS (Linux, macOS, Windows/MSYS), architecture, and package manager
- Handle
sudogracefully (detect if needed, fail with clear message if unavailable) - Use colored output for readability
- Verify the installation at the end
- Exit with non-zero code on any failure
- Include the one-liner command in the header comment
- Support
INSTALL_PREFIXenvironment variable override where applicable
Optional: Windows Support
If Windows support is needed, also generate install.ps1:
# Usage: irm https://raw.githubusercontent.com/<owner>/<repo>/<branch>/install.ps1 | iex
Phase 4: Documentation Generation
After generating the install script, update the project's README (or generate a section) with the one-liner:
Example output for README:
## Installation
### Quick Install (one command)
```bash
curl -sSL https://raw.githubusercontent.com/<owner>/<repo>/main/install.sh | bash
```
Or with wget:
```bash
wget -qO- https://raw.githubusercontent.com/<owner>/<repo>/main/install.sh | bash
```
### Advanced Options
```bash
# Install to a custom prefix
INSTALL_PREFIX=~/.local curl -sSL https://raw.githubusercontent.com/<owner>/<repo>/main/install.sh | bash
# Download and inspect before running
curl -sSL https://raw.githubusercontent.com/<owner>/<repo>/main/install.sh -o install.sh
less install.sh # review the script
bash install.sh
```
Also generate the full usage documentation:
python3 scripts/doc_generator.py --target "<software_name>" --plan installation_plan.yaml
Output Files
The skill generates these files:
| File | Description |
|---|---|
install.sh | Primary output — standalone install script for curl | bash |
install.ps1 | (Optional) Windows PowerShell installer |
env_info.json | System environment analysis (local testing) |
installation_plan.yaml | Detailed installation steps |
USAGE_GUIDE.md | User documentation |
Determining the GitHub Raw URL
To construct the one-liner URL, the skill needs:
- Repository owner and name — Check
git remote -vfor origin URL, or ask the user - Branch — Default to
main, check withgit branch --show-current - File path —
install.shat the repo root
The raw URL format is:
https://raw.githubusercontent.com/<owner>/<repo>/<branch>/install.sh
If the repo uses a non-standard structure (e.g., the script is in a subdirectory), adjust the path:
https://raw.githubusercontent.com/<owner>/<repo>/<branch>/path/to/install.sh
Platform-Specific Notes
Windows
- Prefer
wingetoverchocowhen available - Use PowerShell for script execution (
install.ps1) - Handle UAC elevation requirements
- One-liner:
irm https://raw.githubusercontent.com/<owner>/<repo>/main/install.ps1 | iex
Linux
- Detect distro family (Debian/RedHat/Arch)
- Use appropriate package manager
- Handle sudo requirements gracefully
- Support both
curlandwgetfor the one-liner
macOS
- Use Homebrew as primary package manager
- Handle Apple Silicon vs Intel differences
- Respect Gatekeeper and notarization
Example Usage
Example 1: "Create an install script for this project"
- Detect the project type (e.g., Python package, Go binary, Node module)
- Check
git remote -vto get<owner>/<repo> - Generate
install.shwith proper dependency installation and build steps - Output the one-liner command for the README
Example 2: "Generate a curl install command for my CLI tool"
- Analyze the project's build system
- Generate
install.shthat downloads the latest release binary or builds from source - Include architecture detection for pre-built binaries
- Output:
curl -sSL https://raw.githubusercontent.com/user/tool/main/install.sh | bash
Example 3: "Make my module installable with a single command"
- Check for existing
Makefile,setup.py,package.json, etc. - Generate
install.shthat wraps the build/install process - Add dependency installation (compilers, libraries, runtimes)
- Verify the module is available after install
Error Handling
- All scripts exit with non-zero codes on failure (
set -e) - Each step logs what it's doing before execution
- Failed dependency installs show the exact missing package and package manager
- Verification failure at the end gives clear remediation steps
- Colored output makes errors easy to spot in terminal