-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
tools.func
Auto-generated from comments in tools.func. Each entry shows the purpose and usage of the function, where available.
Description
- !/bin/bash
- ==============================================================================
- HELPER FUNCTIONS FOR PACKAGE MANAGEMENT
- ==============================================================================
- This file provides unified helper functions for robust package installation
- and repository management across Debian/Ubuntu OS upgrades.
- Key Features:
-
- Automatic retry logic for transient APT/network failures
-
- Unified keyring cleanup from all 3 locations
-
- Legacy installation cleanup (nvm, rbenv, rustup)
-
- OS-upgrade-safe repository preparation
-
- Service pattern matching for multi-version tools
- source /dev/stdin <<< "$FUNCTIONS" # Load from build.func
- prepare_repository_setup "mysql"
- install_packages_with_retry "mysql-server" "mysql-client"
- Quick Reference (Core Helpers):
- cleanup_tool_keyrings() - Remove keyrings from all 3 locations
- stop_all_services() - Stop services by pattern (e.g. "php*-fpm")
- verify_tool_version() - Validate installed version matches expected
- cleanup_legacy_install() - Remove nvm, rbenv, rustup, etc.
- prepare_repository_setup() - Cleanup repos + keyrings + validate APT
- install_packages_with_retry() - Install with 3 retries and APT refresh
- upgrade_packages_with_retry() - Upgrade with 3 retries and APT refresh
- ==============================================================================
- Cache installed version to avoid repeated checks
Usage / Examples
Usage in install scripts:Description
- Clean up ALL keyring locations for a tool (unified helper)
Usage / Examples
cleanup_tool_keyrings "mariadb" "mysql" "postgresql"Description
- Stop and disable all service instances matching a pattern
Usage / Examples
stop_all_services "php*-fpm" "mysql" "mariadb"Description
- Verify installed tool version matches expected version
- Returns: 0 if match, 1 if mismatch (with warning)
Usage / Examples
verify_tool_version "nodejs" "22" "$(node -v | grep -oP '^v\K[0-9]+')"Description
- Clean up legacy installation methods (nvm, rbenv, rustup, etc.)
Usage / Examples
cleanup_legacy_install "nodejs" -> removes nvmDescription
- Unified repository preparation before setup
- Cleans up old repos, keyrings, and ensures APT is working
Usage / Examples
prepare_repository_setup "mariadb" "mysql"Description
- Install packages with retry logic
Usage / Examples
install_packages_with_retry "mysql-server" "mysql-client"Description
- Upgrade specific packages with retry logic
Usage / Examples
upgrade_packages_with_retry "mariadb-server" "mariadb-client"Description
- Check if tool is already installed and optionally verify exact version
- Returns: 0 if installed (with optional version match), 1 if not installed
Usage / Examples
is_tool_installed "mariadb" "11.4" || echo "Not installed"Description
- Remove old tool version completely (purge + cleanup repos)
Usage / Examples
remove_old_tool_version "mariadb" "repository-name"Description
- Determine if tool update/upgrade is needed
- Returns: 0 (update needed), 1 (already up-to-date)
Usage / Examples
if should_update_tool "mariadb" "11.4"; then ... fiDescription
- ---------------------–----------------------------------------------------------
- Unified repository management for tools
- Handles adding, updating, and verifying tool repositories
- Supports: mariadb, mongodb, nodejs, postgresql, php, mysql
Usage / Examples
manage_tool_repository "mariadb" "11.4" "https://repo..." "GPG_key_url"Description
- ------–----------------------------------------------------------------------
- Unified package upgrade function (with apt update caching)
Description
- Repository availability check
Description
- Ensure dependencies are installed (with apt update caching)
Description
- Smart version comparison
Description
- Get system architecture (normalized)
Description
- Create temporary directory with automatic cleanup
Description
- Check if package is installed (faster than dpkg -l | grep)
Description
- GitHub API call with authentication and rate limit handling
Description
- Get OS information (cached for performance)
Description
- Check if running on specific OS
Description
- Get Debian/Ubuntu major version
Description
- Download file with retry logic and progress
Description
- Get fallback suite for repository (comprehensive mapping)
Description
- Verify package source and version
Description
- Check if running on LTS version
Description
- Get optimal number of parallel jobs (cached)
Description
- Get default PHP version for OS
Description
- Get default Python version for OS
Description
- Get default Node.js LTS version
Description
- Check if package manager is locked
Description
- Wait for apt to be available
Description
- Cleanup old repository files (migration helper)
Description
- Cleanup orphaned .sources files that reference missing keyrings
- This prevents APT signature verification errors
- Call this at the start of any setup function to ensure APT is in a clean state
Description
- Ensure APT is in a working state before installing packages
- This should be called at the start of any setup function
Description
- Standardized deb822 repository setup (with optional Architectures)
- Always runs apt update after repo creation to ensure package availability
Description
- Package version hold/unhold helpers
Description
- Safe service restart with verification
Description
- Enable and start service (with error handling)
Description
- Check if service is enabled
Description
- Check if service is running
Description
- Extract version from JSON (GitHub releases)
Description
- Get latest GitHub release version
Description
- Debug logging (only if DEBUG=1)
Description
- Performance timing helper
Description
- GPG key fingerprint verification
Description
- ==============================================================================
- EXISTING FUNCTIONS
- ==============================================================================
- Checks for new GitHub release (latest tag).
- Description:
-
- Queries the GitHub API for the latest release tag
-
- Compares it to a local cached version (~/.)
-
- If newer, sets global CHECK_UPDATE_RELEASE and returns 0
- if check_for_gh_release "flaresolverr" "FlareSolverr/FlareSolverr" [optional] "v1.1.1"; then
- fi
- exit 0
- } (end of update_script not from the function)
- Notes:
-
- Requires
jq(auto-installed if missing)
- Requires
-
- Does not modify anything, only checks version state
-
- Does not support pre-releases
Usage / Examples
Description
- Creates and installs self-signed certificates.
- Description:
-
- Create a self-signed certificate with option to override application name
- Variables:
- APP - Application name (default: $APPLICATION variable)
Description
- Downloads file with optional progress indicator using pv.
- Arguments:
- $1 - URL
- $2 - Destination path
Description
- Ensures /usr/local/bin is permanently in system PATH.
- Description:
-
- Adds to /etc/profile.d if not present
Description
- Downloads and deploys latest GitHub release (source, binary, tarball, asset).
- Description:
-
- Fetches latest release metadata from GitHub API
-
- Supports the following modes:
-
- tarball: Source code tarball (default if omitted)
-
- source: Alias for tarball (same behavior)
-
- binary: .deb package install (arch-dependent)
-
- prebuild: Prebuilt .tar.gz archive (e.g. Go binaries)
-
- singlefile: Standalone binary (no archive, direct chmod +x install)
-
- Handles download, extraction/installation and version tracking in ~/.
- Parameters:
- $1 APP - Application name (used for install path and version file)
- $2 REPO - GitHub repository in form user/repo
- $3 MODE - Release type:
- tarball → source tarball (.tar.gz)
- binary → .deb file (auto-arch matched)
- prebuild → prebuilt archive (e.g. tar.gz)
- singlefile→ standalone binary (chmod +x)
- $4 VERSION - Optional release tag (default: latest)
- $5 TARGET_DIR - Optional install path (default: /opt/)
- $6 ASSET_FILENAME - Required for:
-
- prebuild → archive filename or pattern
-
- singlefile→ binary filename or pattern
- Optional:
-
- Set GITHUB_TOKEN env var to increase API rate limit (recommended for CI/CD).
- fetch_and_deploy_gh_release "myapp" "myuser/myapp"
- fetch_and_deploy_gh_release "myapp" "myuser/myapp" "binary"
- fetch_and_deploy_gh_release "hanko" "teamhanko/hanko" "prebuild" "latest" "/opt/hanko" "hanko_Linux_x86_64.tar.gz"
- fetch_and_deploy_gh_release "argus" "release-argus/Argus" "singlefile" "0.26.3" "/opt/argus" "Argus-.*linux-amd64"
Usage / Examples
Description
- Loads LOCAL_IP from persistent store or detects if missing.
- Description:
-
- Loads from /run/local-ip.env or performs runtime lookup
Description
- Installs Adminer (Debian/Ubuntu via APT, Alpine via direct download).
- Description:
-
- Adds Adminer to Apache or web root
-
- Supports Alpine and Debian-based systems
Description
- Installs or updates Composer globally (robust, idempotent).
-
- Installs to /usr/local/bin/composer
-
- Removes old binaries/symlinks in /usr/bin, /bin, /root/.composer, etc.
-
- Ensures /usr/local/bin is in PATH (permanent)
-
- Auto-updates to latest version
Description
- Installs FFmpeg from source or prebuilt binary (Debian/Ubuntu only).
- Description:
-
- Downloads and builds FFmpeg from GitHub (https://github.com/FFmpeg/FFmpeg)
-
- Supports specific version override via FFMPEG_VERSION (e.g. n7.1.1)
-
- Supports build profile via FFMPEG_TYPE:
-
- minimal : x264, vpx, mp3 only
-
- medium : adds subtitles, fonts, opus, vorbis
-
- full : adds dav1d, svt-av1, zlib, numa
-
- binary : downloads static build (johnvansickle.com)
-
- Defaults to latest stable version and full feature set
- Notes:
-
- Requires: curl, jq, build-essential, and matching codec libraries
-
- Result is installed to /usr/local/bin/ffmpeg
Description
- Installs Go (Golang) from official tarball.
- Description:
-
- Determines system architecture
-
- Downloads latest version if GO_VERSION not set
- Variables:
- GO_VERSION - Version to install (e.g. 1.22.2 or latest)
Description
- Installs or updates Ghostscript (gs) from source.
- Description:
-
- Fetches latest release
-
- Builds and installs system-wide
Description
- Sets up Hardware Acceleration on debian or ubuntu.
- Description:
-
- Determites CPU/GPU/APU Vendor
-
- Installs the correct libraries and packages
-
- Sets up Hardware Acceleration
- Notes:
-
- Some things are fetched from intel repositories due to not being in debian repositories.
Description
- Installs ImageMagick 7 from source (Debian/Ubuntu only).
- Description:
-
- Downloads the latest ImageMagick source tarball
-
- Builds and installs ImageMagick to /usr/local
-
- Configures dynamic linker (ldconfig)
- Notes:
-
- Requires: build-essential, libtool, libjpeg-dev, libpng-dev, etc.
Description
- Installs Temurin JDK via Adoptium APT repository.
- Description:
-
- Removes previous JDK if version mismatch
-
- Installs or upgrades to specified JAVA_VERSION
- Variables:
- JAVA_VERSION - Temurin JDK version to install (e.g. 17, 21)
Description
- Installs a local IP updater script using networkd-dispatcher.
- Description:
-
- Stores current IP in /run/local-ip.env
-
- Automatically runs on network changes
Description
- Installs or updates MariaDB from official repo.
- Description:
-
- Detects current MariaDB version and replaces it if necessary
-
- Preserves existing database data
-
- Dynamically determines latest GA version if "latest" is given
- Variables:
- MARIADB_VERSION - MariaDB version to install (e.g. 10.11, latest) (default: latest)
Description
- Installs or updates MongoDB to specified major version.
- Description:
-
- Preserves data across installations
-
- Adds official MongoDB repo
- Variables:
- MONGO_VERSION - MongoDB major version to install (e.g. 7.0, 8.0)
Description
- Installs or upgrades MySQL and configures APT repo.
- Description:
-
- Detects existing MySQL installation
-
- Purges conflicting packages before installation
-
- Supports clean upgrade
-
- Handles Debian Trixie libaio1t64 transition
- Variables:
- MYSQL_VERSION - MySQL version to install (e.g. 5.7, 8.0) (default: 8.0)
Description
- Installs Node.js and optional global modules.
- Description:
-
- Installs specified Node.js version using NodeSource APT repo
-
- Optionally installs or updates global npm modules
- Variables:
- NODE_VERSION - Node.js version to install (default: 22)
- NODE_MODULE - Comma-separated list of global modules (e.g. "yarn,@vue/cli@5.0.0")
Description
- Installs PHP with selected modules and configures Apache/FPM support.
- Description:
-
- Adds Sury PHP repo if needed
-
- Installs default and user-defined modules
-
- Patches php.ini for CLI, Apache, and FPM as needed
- Variables:
- PHP_VERSION - PHP version to install (default: 8.4)
- PHP_MODULE - Additional comma-separated modules
- PHP_APACHE - Set YES to enable PHP with Apache
- PHP_FPM - Set YES to enable PHP-FPM
- PHP_MEMORY_LIMIT - (default: 512M)
- PHP_UPLOAD_MAX_FILESIZE - (default: 128M)
- PHP_POST_MAX_SIZE - (default: 128M)
- PHP_MAX_EXECUTION_TIME - (default: 300)
Description
- Installs or upgrades PostgreSQL and optional extensions/modules.
- Description:
-
- Detects existing PostgreSQL version
-
- Dumps all databases before upgrade
-
- Adds PGDG repo and installs specified version
-
- Installs optional PG_MODULES (e.g. postgis, contrib)
-
- Restores dumped data post-upgrade
- Variables:
- PG_VERSION - Major PostgreSQL version (e.g. 15, 16) (default: 16)
Description
- Installs rbenv and ruby-build, installs Ruby and optionally Rails.
- Description:
-
- Downloads rbenv and ruby-build from GitHub
-
- Compiles and installs target Ruby version
-
- Optionally installs Rails via gem
- Variables:
- RUBY_VERSION - Ruby version to install (default: 3.4.4)
- RUBY_INSTALL_RAILS - true/false to install Rails (default: true)
Description
- Installs or upgrades ClickHouse database server.
- Description:
-
- Adds ClickHouse official repository
-
- Installs specified version
-
- Configures systemd service
-
- Supports Debian/Ubuntu with fallback mechanism
- Variables:
- CLICKHOUSE_VERSION - ClickHouse version to install (default: latest)
Description
- Installs Rust toolchain and optional global crates via cargo.
- Description:
-
- Installs rustup (if missing)
-
- Installs or updates desired Rust toolchain (stable, nightly, or versioned)
-
- Installs or updates specified global crates using
cargo install
- Installs or updates specified global crates using
- Notes:
-
- Skips crate install if exact version is already present
-
- Updates crate if newer version or different version is requested
- Variables:
- RUST_TOOLCHAIN - Rust toolchain to install (default: stable)
- RUST_CRATES - Comma-separated list of crates (e.g. "cargo-edit,wasm-pack@0.12.1")
Description
- Installs or upgrades uv (Python package manager) from GitHub releases.
-
- Downloads platform-specific tarball (no install.sh!)
-
- Extracts uv binary
-
- Places it in /usr/local/bin
-
- Optionally installs a specific Python version via uv
Description
- Helper function to install uvx wrapper
Description
- Installs or updates yq (mikefarah/yq - Go version).
- Description:
-
- Checks if yq is installed and from correct source
-
- Compares with latest release on GitHub
-
- Updates if outdated or wrong implementation