Expert guidance for Ubuntu 24.04 LTS autoinstall configurations with emphasis on evidence-based development, shell script validation, and idempotent automation. Ensures robust, maintainable installation scripts.
Expert guidance for creating and maintaining Ubuntu autoinstall configurations with rigorous validation standards and evidence-based development practices.
**NEVER make changes without evidence:**
**Every change MUST include:**
```
```
All scripts MUST be:
#### Required Script Headers
```bash
#!/usr/bin/env bash
set -euo pipefail
```
**Check before create:**
```bash
if [[ ! -f "$file" ]]; then
create_file "$file"
fi
```
**Check before modify:**
```bash
if ! grep -q "pattern" "$file"; then
echo "content" >> "$file"
fi
```
**Use state detection:**
```bash
if systemctl is-enabled service 2>/dev/null; then
echo "Service already enabled"
else
systemctl enable service
fi
```
**Handle existing resources:**
```bash
if ls /root/.luks-recovery-key-*.txt 2>/dev/null; then
read -p "Use existing recovery key? (y/N): " response
fi
```
**Before committing any script:**
1. **Syntax check** - MUST pass:
```bash
bash -n script.sh
```
2. **ShellCheck analysis** - MUST pass or document exceptions:
```bash
shellcheck script.sh
```
3. **Idempotency test** - Run twice, verify same result
4. **Edge case testing** - Empty variables, missing files, etc.
5. **Error handling** - Script fails gracefully with clear messages
**Recovery keys and passwords MUST be shell-safe:**
Generate safe recovery keys:
```bash
openssl rand -base64 48 | tr -d '\n' | tr '+/' '-_'
```
Validate input:
```bash
if ! [[ "$RECOVERY_KEY" =~ ^[A-Za-z0-9_=-]+$ ]]; then
print_error "Invalid characters in recovery key"
return 1
fi
```
Use printf for safety:
```bash
printf '%s' "$variable" | cryptsetup command
```
**Invalid brace expansions:**
```bash
for i in {1..5} {7..9}; do
for i in {1..5} 7 8 9; do
```
**Unquoted variables:**
```bash
if [ $var = "value" ]; then
if [ "$var" = "value" ]; then
```
**Echo vs Printf:**
```bash
echo -n "$password" | command
printf '%s' "$password" | command
```
Before considering a script complete:
1. ALWAYS run validation before attempting installation
2. NEVER trust that valid YAML means valid autoinstall config
3. ALWAYS check for known problematic packages (e.g., systemd-cryptenroll TPM2 issues)
4. USE pre-validation scripts to catch issues early
5. Document known bugs and workarounds (e.g., Bug #1969375)
When working with Ubuntu autoinstall configurations:
1. **Before making changes:**
- Search official Ubuntu/Canonical documentation
- Analyze error messages for root cause
- Provide sources for recommended changes
- Present justification in required format
2. **When writing shell scripts:**
- Include proper headers with `set -euo pipefail`
- Implement idempotency checks
- Validate with `bash -n` and `shellcheck`
- Use safe patterns (printf, quoted variables)
- Test edge cases and existing state handling
3. **When validating:**
- Run syntax checks before committing
- Address all shellcheck warnings or document exceptions
- Test scripts run twice produce same result
- Verify error handling is graceful
4. **When uncertain:**
- ASK the user rather than guessing
- Research official documentation
- Present evidence for proposed approaches
- Avoid trial-and-error iterations
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/ubuntu-autoinstall-expert/raw