These guidelines ensure consistency, quality, and maintainability across the Proxmox VE Helper Scripts project. Following these standards makes code reviews faster and contributions easier to merge.
Use the template files in docs/contribution/templates_* as starting points. They already follow these guidelines.
# ✅ GOOD - Clear and consistentAPP="MyApp" # Constants (UPPERCASE)var_cpu="2" # Configuration (var_* prefix)container_id="100" # Local variables (lowercase)DB_PASSWORD="secret" # Environment-style (UPPERCASE)app_version="1.2.3" # Application data (lowercase)# ❌ BAD - Inconsistent or unclearmyapp="MyApp" # Should be uppercaseVAR_CPU="2" # Don't capitalize var_ prefixcontainerid="100" # Use underscores for readabilitydbpassword="secret" # Hard to parse
# ✅ GOOD - Multiline with backslashes$STD apt-get install -y \ package1 \ package2 \ package3# ✅ GOOD - Error checkingif ! wget -q "${URL}"; then msg_error "Failed to download" exit 1fi# ❌ BAD - Too long$STD apt-get install -y package1 package2 package3 package4 package5# ❌ BAD - No error handlingwget $URL
Use modern bash syntax:
# ✅ GOOD - Modern syntaxif [[ -f "/path/to/file" ]]; then echo "File exists"fiif [[ "${var}" == "value" ]]; then echo "Match found"fi# ❌ BAD - Old syntaxif [ -f "/path/to/file" ]; then echo "File exists"fiif test "$var" = "value"; then echo "Match found"fi
# Install specific Node.js versionNODE_VERSION="20" setup_nodejs# This handles:# - Repository addition# - Package installation# - Version verification
fetch_and_deploy_gh_release - Download from GitHub
# Fetch latest release from GitHubfetch_and_deploy_gh_release "appname" "owner/repo" "tarball" "latest" "/opt/appname"# Parameters:# 1. Application name (for messages)# 2. GitHub repo (owner/name)# 3. Asset type (tarball, zipball, or specific asset name)# 4. Version (latest, or specific tag like v1.2.3)# 5. Destination directory
check_for_gh_release - Check for updates
# Check if new version availableif check_for_gh_release "appname" "owner/repo"; then msg_info "Updating to new version" # Perform updateelse msg_ok "Already up to date"fi
Message Functions
msg_info "Installing dependencies" # Blue info messagemsg_ok "Installation complete" # Green success messagemsg_error "Installation failed" # Red error messagemsg_warn "Using default settings" # Yellow warning message
See docs/contribution/HELPER_FUNCTIONS.md for a complete reference of all available helper functions.
# ✅ GOOD - Check critical operationsif ! wget -q "${URL}"; then msg_error "Failed to download file" exit 1fi# ✅ GOOD - Use catch_errors for automatic trappingcatch_errors # Include early in script# ✅ GOOD - Validate before proceedingif [[ ! -d /opt/myapp ]]; then msg_error "No ${APP} Installation Found!" exit 1fi# ❌ BAD - Silently ignore failureswget $URL || truesome_command 2>/dev/null# ❌ BAD - Continue on errorwget $URLcd /opt/app # Might fail if wget failed
# Get your files from the work branchgit show feature/my-awesome-app:ct/myapp.sh > ct/myapp.shgit show feature/my-awesome-app:install/myapp-install.sh > install/myapp-install.shgit show feature/my-awesome-app:frontend/public/json/myapp.json > frontend/public/json/myapp.json