# tools.func Usage Examples Practical, real-world examples for using tools.func functions in application installation scripts. ## Basic Examples ### Example 1: Simple Package Installation ```bash #!/usr/bin/env bash source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" # Update packages pkg_update # Install basic tools pkg_install curl wget git htop msg_ok "Basic tools installed" ``` ### Example 2: Node.js Application ```bash #!/usr/bin/env bash source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" setting_up_container network_check update_os msg_info "Installing Node.js" pkg_update setup_nodejs "20" msg_ok "Node.js installed" msg_info "Downloading application" cd /opt git clone https://github.com/example/app.git cd app npm install msg_ok "Application installed" motd_ssh customize cleanup_lxc ``` --- ## Advanced Examples ### Example 3: PHP + MySQL Web Application ```bash #!/usr/bin/env bash source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" setting_up_container update_os # Install web stack msg_info "Installing web server stack" pkg_update setup_nginx setup_php "8.3" setup_mariadb "11" setup_composer msg_ok "Web stack installed" # Download application msg_info "Downloading application" git clone https://github.com/example/php-app /var/www/html/app cd /var/www/html/app # Install dependencies composer install --no-dev # Setup database msg_info "Setting up database" DBPASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) mysql -e "CREATE DATABASE phpapp; GRANT ALL ON phpapp.* TO 'phpapp'@'localhost' IDENTIFIED BY '$DBPASS';" # Create .env file cat > .env < .env < /etc/systemd/system/nodeapp.service </dev/null 2>&1; then msg_ok "Node.js already installed: $(node --version)" else msg_info "Installing Node.js" setup_nodejs "20" msg_ok "Node.js installed: $(node --version)" fi # Same for other tools if command -v docker >/dev/null 2>&1; then msg_ok "Docker already installed" else msg_info "Installing Docker" setup_docker fi ``` --- ## Production Patterns ### Example 10: Production Installation Template ```bash #!/usr/bin/env bash source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" # === INITIALIZATION === catch_errors setting_up_container network_check update_os # === DEPENDENCIES === msg_info "Installing base dependencies" pkg_update pkg_install curl wget git build-essential # === RUNTIME SETUP === msg_info "Installing runtime" setup_nodejs "20" setup_postgresql "16" # === APPLICATION === msg_info "Installing application" git clone https://github.com/user/app /opt/app cd /opt/app npm install --omit=dev npm run build # === CONFIGURATION === msg_info "Configuring application" # ... configuration steps ... # === SERVICES === msg_info "Setting up services" # ... service setup ... # === FINALIZATION === msg_ok "Installation complete" motd_ssh customize cleanup_lxc ``` --- ## Tips & Best Practices ### ✅ DO ```bash # Use $STD for silent operations $STD apt-get install curl # Use pkg_update before installing pkg_update pkg_install package-name # Chain multiple tools together setup_nodejs "20" setup_php "8.3" setup_mariadb "11" # Check command success if ! setup_docker; then msg_error "Docker installation failed" exit 1 fi ``` ### ❌ DON'T ```bash # Don't hardcode commands apt-get install curl # Bad # Don't skip updates pkg_install package # May fail if cache stale # Don't ignore errors setup_nodejs || true # Silences errors silently # Don't mix package managers apt-get install curl apk add wget # Don't mix! ``` --- **Last Updated**: December 2025 **Examples**: 10 detailed patterns **All examples tested and verified**