From 18fd4ecdc9c29aa9a14e565b15fdc82f5c2c3bd7 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:21:39 +0100 Subject: [PATCH] Updated tools.func (markdown) --- tools.func.md | 1310 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 942 insertions(+), 368 deletions(-) diff --git a/tools.func.md b/tools.func.md index a0df213..f47bc41 100644 --- a/tools.func.md +++ b/tools.func.md @@ -1,417 +1,991 @@ -# This page describes all helper functions defined in `misc/tools.func` +# `tools.func` – Function Reference -The tools.func file is automatically sourced and can be used in all **$APP-install.sh** files. +_Auto-generated from comments in `tools.func`. Each entry shows the purpose and usage of the function, where available._ -## fetch_and_deploy_gh_release +## `cache_installed_version` -### Description +**Description** -`fetch_and_deploy_gh_release()` -- Checking the current installed version. -- Fetching the latest release info from GitHub API with retries. -- Detecting system architecture to download the appropriate release asset. -- Falling back to generic or source tarball if no matching asset found. -- Downloading, extracting, and copying the release files to `/opt/`. -- Saving the installed version for future checks. -- Automatic installation of `jq` if missing. -- Handles GitHub API rate limits and errors gracefully. -- Uses `$STD` for command prefixing and `$APP` or `$APPLICATION` for app naming. +- !/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 +**Usage / Examples** ```bash -fetch_and_deploy_gh_release +Usage in install scripts: +``` -fetch_and_deploy_gh_release "owner/repository" + +## `get_cached_version` + + +## `cleanup_tool_keyrings` + +**Description** + +- ------------------------------------------------------------------------------ +- Clean up ALL keyring locations for a tool (unified helper) +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash +cleanup_tool_keyrings "mariadb" "mysql" "postgresql" +``` + + +## `stop_all_services` + +**Description** + +- ------------------------------------------------------------------------------ +- Stop and disable all service instances matching a pattern +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash +stop_all_services "php*-fpm" "mysql" "mariadb" +``` + + +## `verify_tool_version` + +**Description** + +- ------------------------------------------------------------------------------ +- Verify installed tool version matches expected version +- Returns: 0 if match, 1 if mismatch (with warning) +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash +verify_tool_version "nodejs" "22" "$(node -v | grep -oP '^v\K[0-9]+')" +``` + + +## `cleanup_legacy_install` + +**Description** + +- ------------------------------------------------------------------------------ +- Clean up legacy installation methods (nvm, rbenv, rustup, etc.) +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash +cleanup_legacy_install "nodejs" -> removes nvm +``` + + +## `prepare_repository_setup` + +**Description** + +- ------------------------------------------------------------------------------ +- Unified repository preparation before setup +- Cleans up old repos, keyrings, and ensures APT is working +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash +prepare_repository_setup "mariadb" "mysql" +``` + + +## `install_packages_with_retry` + +**Description** + +- ------------------------------------------------------------------------------ +- Install packages with retry logic +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash +install_packages_with_retry "mysql-server" "mysql-client" +``` + + +## `upgrade_packages_with_retry` + +**Description** + +- ------------------------------------------------------------------------------ +- Upgrade specific packages with retry logic +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash +upgrade_packages_with_retry "mariadb-server" "mariadb-client" +``` + + +## `is_tool_installed` + +**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** + +```bash +is_tool_installed "mariadb" "11.4" || echo "Not installed" +``` + + +## `remove_old_tool_version` + +**Description** + +- ------------------------------------------------------------------------------ +- Remove old tool version completely (purge + cleanup repos) +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash +remove_old_tool_version "mariadb" "repository-name" +``` + + +## `should_update_tool` + +**Description** + +- ------------------------------------------------------------------------------ +- Determine if tool update/upgrade is needed +- Returns: 0 (update needed), 1 (already up-to-date) +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash +if should_update_tool "mariadb" "11.4"; then ... fi +``` + + +## `manage_tool_repository` + +**Description** + +- ---------------------–---------------------------------------------------------- +- Unified repository management for tools +- Handles adding, updating, and verifying tool repositories +- Supports: mariadb, mongodb, nodejs, postgresql, php, mysql +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash +manage_tool_repository "mariadb" "11.4" "https://repo..." "GPG_key_url" +``` + + +## `upgrade_package` + +**Description** + +- ------–---------------------------------------------------------------------- +- Unified package upgrade function (with apt update caching) +- ------------------------------------------------------------------------------ + + +## `verify_repo_available` + +**Description** + +- ------------------------------------------------------------------------------ +- Repository availability check +- ------------------------------------------------------------------------------ + + +## `ensure_dependencies` + +**Description** + +- ------------------------------------------------------------------------------ +- Ensure dependencies are installed (with apt update caching) +- ------------------------------------------------------------------------------ + + +## `version_gt` + +**Description** + +- ------------------------------------------------------------------------------ +- Smart version comparison +- ------------------------------------------------------------------------------ + + +## `get_system_arch` + +**Description** + +- ------------------------------------------------------------------------------ +- Get system architecture (normalized) +- ------------------------------------------------------------------------------ + + +## `create_temp_dir` + +**Description** + +- ------------------------------------------------------------------------------ +- Create temporary directory with automatic cleanup +- ------------------------------------------------------------------------------ + + +## `is_package_installed` + +**Description** + +- ------------------------------------------------------------------------------ +- Check if package is installed (faster than dpkg -l | grep) +- ------------------------------------------------------------------------------ + + +## `github_api_call` + +**Description** + +- ------------------------------------------------------------------------------ +- GitHub API call with authentication and rate limit handling +- ------------------------------------------------------------------------------ + + +## `should_upgrade` + + +## `get_os_info` + +**Description** + +- ------------------------------------------------------------------------------ +- Get OS information (cached for performance) +- ------------------------------------------------------------------------------ + + +## `is_debian` + +**Description** + +- ------------------------------------------------------------------------------ +- Check if running on specific OS +- ------------------------------------------------------------------------------ + + +## `is_ubuntu` + + +## `is_alpine` + + +## `get_os_version_major` + +**Description** + +- ------------------------------------------------------------------------------ +- Get Debian/Ubuntu major version +- ------------------------------------------------------------------------------ + + +## `download_file` + +**Description** + +- ------------------------------------------------------------------------------ +- Download file with retry logic and progress +- ------------------------------------------------------------------------------ + + +## `get_fallback_suite` + +**Description** + +- ------------------------------------------------------------------------------ +- Get fallback suite for repository (comprehensive mapping) +- ------------------------------------------------------------------------------ + + +## `verify_package_source` + +**Description** + +- ------------------------------------------------------------------------------ +- Verify package source and version +- ------------------------------------------------------------------------------ + + +## `is_lts_version` + +**Description** + +- ------------------------------------------------------------------------------ +- Check if running on LTS version +- ------------------------------------------------------------------------------ + + +## `get_parallel_jobs` + +**Description** + +- ------------------------------------------------------------------------------ +- Get optimal number of parallel jobs (cached) +- ------------------------------------------------------------------------------ + + +## `get_default_php_version` + +**Description** + +- ------------------------------------------------------------------------------ +- Get default PHP version for OS +- ------------------------------------------------------------------------------ + + +## `get_default_python_version` + +**Description** + +- ------------------------------------------------------------------------------ +- Get default Python version for OS +- ------------------------------------------------------------------------------ + + +## `get_default_nodejs_version` + +**Description** + +- ------------------------------------------------------------------------------ +- Get default Node.js LTS version +- ------------------------------------------------------------------------------ + + +## `is_apt_locked` + +**Description** + +- ------------------------------------------------------------------------------ +- Check if package manager is locked +- ------------------------------------------------------------------------------ + + +## `wait_for_apt` + +**Description** + +- ------------------------------------------------------------------------------ +- Wait for apt to be available +- ------------------------------------------------------------------------------ + + +## `cleanup_old_repo_files` + +**Description** + +- ------------------------------------------------------------------------------ +- Cleanup old repository files (migration helper) +- ------------------------------------------------------------------------------ + + +## `cleanup_orphaned_sources` + +**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 +- ------------------------------------------------------------------------------ + + +## `ensure_apt_working` + +**Description** + +- ------------------------------------------------------------------------------ +- Ensure APT is in a working state before installing packages +- This should be called at the start of any setup function +- ------------------------------------------------------------------------------ + + +## `setup_deb822_repo` + +**Description** + +- ------------------------------------------------------------------------------ +- Standardized deb822 repository setup (with optional Architectures) +- Always runs apt update after repo creation to ensure package availability +- ------------------------------------------------------------------------------ + + +## `hold_package_version` + +**Description** + +- ------------------------------------------------------------------------------ +- Package version hold/unhold helpers +- ------------------------------------------------------------------------------ + + +## `unhold_package_version` + + +## `safe_service_restart` + +**Description** + +- ------------------------------------------------------------------------------ +- Safe service restart with verification +- ------------------------------------------------------------------------------ + + +## `enable_and_start_service` + +**Description** + +- ------------------------------------------------------------------------------ +- Enable and start service (with error handling) +- ------------------------------------------------------------------------------ + + +## `is_service_enabled` + +**Description** + +- ------------------------------------------------------------------------------ +- Check if service is enabled +- ------------------------------------------------------------------------------ + + +## `is_service_running` + +**Description** + +- ------------------------------------------------------------------------------ +- Check if service is running +- ------------------------------------------------------------------------------ + + +## `extract_version_from_json` + +**Description** + +- ------------------------------------------------------------------------------ +- Extract version from JSON (GitHub releases) +- ------------------------------------------------------------------------------ + + +## `get_latest_github_release` + +**Description** + +- ------------------------------------------------------------------------------ +- Get latest GitHub release version +- ------------------------------------------------------------------------------ + + +## `debug_log` + +**Description** + +- ------------------------------------------------------------------------------ +- Debug logging (only if DEBUG=1) +- ------------------------------------------------------------------------------ + + +## `start_timer` + +**Description** + +- ------------------------------------------------------------------------------ +- Performance timing helper +- ------------------------------------------------------------------------------ + + +## `end_timer` + + +## `verify_gpg_fingerprint` + +**Description** + +- ------------------------------------------------------------------------------ +- GPG key fingerprint verification +- ------------------------------------------------------------------------------ + + +## `check_for_gh_release` + +**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 +- # trigger update... +- fi +- exit 0 +- } (end of update_script not from the function) +- Notes: +- - Requires `jq` (auto-installed if missing) +- - Does not modify anything, only checks version state +- - Does not support pre-releases +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash ``` ---- + + +## `create_self_signed_cert` + +**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) +- ------------------------------------------------------------------------------ + + +## `download_with_progress` + +**Description** + +- ------------------------------------------------------------------------------ +- Downloads file with optional progress indicator using pv. +- Arguments: +- $1 - URL +- $2 - Destination path +- ------------------------------------------------------------------------------ + + +## `ensure_usr_local_bin_persist` + +**Description** + +- ------------------------------------------------------------------------------ +- Ensures /usr/local/bin is permanently in system PATH. +- Description: +- - Adds to /etc/profile.d if not present +- ------------------------------------------------------------------------------ + + +## `fetch_and_deploy_gh_release` + +**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). +- # 1. Minimal: Fetch and deploy source tarball +- fetch_and_deploy_gh_release "myapp" "myuser/myapp" +- # 2. Binary install via .deb asset (architecture auto-detected) +- fetch_and_deploy_gh_release "myapp" "myuser/myapp" "binary" +- # 3. Prebuilt archive (.tar.gz) with asset filename match +- fetch_and_deploy_gh_release "hanko" "teamhanko/hanko" "prebuild" "latest" "/opt/hanko" "hanko_Linux_x86_64.tar.gz" +- # 4. Single binary (chmod +x) like Argus, Promtail etc. +- fetch_and_deploy_gh_release "argus" "release-argus/Argus" "singlefile" "0.26.3" "/opt/argus" "Argus-.*linux-amd64" +- ------------------------------------------------------------------------------ + +**Usage / Examples** + +```bash + +``` + + +## `import_local_ip` + +**Description** + +- ------------------------------------------------------------------------------ +- Loads LOCAL_IP from persistent store or detects if missing. +- Description: +- - Loads from /run/local-ip.env or performs runtime lookup +- ------------------------------------------------------------------------------ + + +## `get_current_ip` + + +## `setup_adminer` + +**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 +- ------------------------------------------------------------------------------ + + +## `setup_composer` + +**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 +- ------------------------------------------------------------------------------ + + +## `setup_ffmpeg` + +**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 +- ------------------------------------------------------------------------------ + + +## `setup_go` + +**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) +- ------------------------------------------------------------------------------ + + +## `setup_gs` + +**Description** + +- ------------------------------------------------------------------------------ +- Installs or updates Ghostscript (gs) from source. +- Description: +- - Fetches latest release +- - Builds and installs system-wide +- ------------------------------------------------------------------------------ + + +## `setup_hwaccel` + +**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. +- ------------------------------------------------------------------------------ + + +## `setup_imagemagick` + +**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. +- ------------------------------------------------------------------------------ + + +## `setup_java` + +**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) +- ------------------------------------------------------------------------------ + + +## `setup_local_ip_helper` + +**Description** + +- ------------------------------------------------------------------------------ +- Installs a local IP updater script using networkd-dispatcher. +- Description: +- - Stores current IP in /run/local-ip.env +- - Automatically runs on network changes +- ------------------------------------------------------------------------------ + + +## `get_current_ip` + + +## `setup_mariadb` + +**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) +- ------------------------------------------------------------------------------ + + +## `setup_mongodb` + +**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) +- ------------------------------------------------------------------------------ + + +## `setup_mysql` + +**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) +- ------------------------------------------------------------------------------ ## `setup_nodejs` -This function automates the installation of a specified version of Node.js and a list of global Node modules on a Debian-based system. It ensures the desired Node.js version is installed (replacing any existing version if necessary) and installs or updates specified Node.js global modules. +**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 -`setup_nodejs()`: +## `setup_php` -- Checks if Node.js is installed. -- If Node.js is installed but not the desired version, it replaces it. -- If Node.js is not installed, it installs the specified version using the NodeSource APT repository. -- It can also install or update a list of global Node modules. +**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) +- ------------------------------------------------------------------------------ -### Usage - -```bash -setup_nodejs -``` -to install the latest version of Node.js with no additional Modules. -If you want to define a specified Version and install Modules use something like this: - -```bash -NODE_VERSION=20 NODE_MODULE="yarn@latest,@vue/cli-service@5.0.0" setup_nodejs -``` - -### User-Configurable Variables - -| Variable | Description | Default Value | -|----------------|----------------------------------------------------------------------------------------------------------------|---------------| -| `NODE_VERSION` | Specifies the major version of Node.js to install (e.g., `20`, `22`). | `22` | -| `NODE_MODULE` | Comma-separated list of global npm modules to install or update.
Examples:
• `yarn@latest`
• `@vue/cli-service@5.0.0`
• `typescript` | *(empty)* | - ---- ## `setup_postgresql` -### Description -`setup_postgresql()`: +**Description** -- Checks if Postgressql is installed. -- If Postgressql is installed but not the desired version, it replaces it. -- If Postgressql is not installed, it installs the specified version. +- ------------------------------------------------------------------------------ +- 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) -### Usage -```bash -setup_postgresql -``` +## `setup_ruby` -Specifie a Version: -```bash -PG_VERSION=15 setup_postgresql -``` +**Description** -### User-Configurable Variables +- ------------------------------------------------------------------------------ +- 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) +- ------------------------------------------------------------------------------ -| Variable | Description | Default Value | -|--------------|-----------------------------------------------------------------------------|---------------| -| `PG_VERSION` | Specifies the major version of PostgreSQL to install or upgrade to (e.g., `14`, `15`, `16`). | `16` | +## `setup_clickhouse` ---- -## setup_mariadb +**Description** -### Description - -`setup_mariadb()`: - -- Detecting the current version of MariaDB (if installed) -- Upgrading to the latest version if needed -- Replacing older versions while preserving data -- Configuring the appropriate MariaDB APT repository -- Installing the MariaDB packages - - -### Usage - -```bash -setup_mariadb -``` -You can optionally set the `MARIADB_VERSION` environment variable before calling the function to specify a particular version to install. - -Example: -```bash -MARIADB_VERSION="10.11.6" setup_mariadb -``` -If no version is specified, the script will automatically fetch and install the latest GA (Generally Available) version of MariaDB. - -### User-Configurable Variables - -| Variable | Description | Default Value | -|--------------|-----------------------------------------------------------------------------|---------------| -| `MARIADB_VERSION` | Specifies the version of MariaDB to install. If set to `latest`, the script will detect the most recent GA version from the MariaDB mirror site. | `latest`| - ---- - -## setup_mysql - -### Description - -`setup_mysql()`: - -- Detecting if MySQL is already installed -- Replacing it with the specified version if it differs -- Removing conflicting packages and cleaning up old sources -- Setting up the official MySQL APT repository -- Installing the MySQL server package - - -### Usage - -```bash -setup_mysql -``` -To install a specific version of MySQL, export the `MYSQL_VERSION` variable before calling the function: - -```bash -MYSQL_VERSION="5.7" setup_mysql -``` - -### User-Configurable Variables - -| Variable | Description | Default Value | -|--------------|-----------------------------------------------------------------------------|---------------| -| `MYSQL_VERSION` | Specifies the version of MySQL to install.. | `8.0`| - ---- - -## setup_php - -### Description - -`setup_php()`: -- Detects the current PHP version and upgrades or switches if necessary. -- Adds the `sury.org` repository if not already configured. -- Installs the specified PHP version along with default and user-defined modules. -- Patches `php.ini` files with custom configuration values. -- Optionally enables PHP for Apache or PHP-FPM. - -### Usage - -```bash -setup_php -``` -You can set any of the environment variables below to customize the behavior: - -```bash -PHP_VERSION="8.3" PHP_APACHE="YES" PHP_FPM="NO" PHP_MEMORY_LIMIT="1G" setup_php -``` - -#### PHP Modules -These modules are installed by default: -```bash -bcmath, cli, curl, gd, intl, mbstring, opcache, readline, xml, zip -``` -You can add custom modules with this command: -```bash -PHP_MODULE="mysql,redis" setup_php -``` -### User-Configurable Variables - -| Variable | Description | Default Value | -|---------------------------|------------------------------------------------------------------------|---------------| -| `PHP_VERSION` | PHP version to install (e.g., `8.2`, `8.3`, `8.4`) | `8.4` | -| `PHP_MODULE` | Comma-separated list of additional PHP modules (e.g., `mysql,redis`) | *(empty)* | -| `PHP_APACHE` | Set to `YES` to enable PHP module for Apache | `NO` | -| `PHP_FPM` | Set to `YES` to install and configure PHP-FPM | `NO` | -| `PHP_MEMORY_LIMIT` | Sets `memory_limit` in relevant `php.ini` files | `512M` | -| `PHP_UPLOAD_MAX_FILESIZE` | Sets `upload_max_filesize` in relevant `php.ini` files | `128M` | -| `PHP_POST_MAX_SIZE` | Sets `post_max_size` in relevant `php.ini` files | `128M` | -| `PHP_MAX_EXECUTION_TIME` | Sets `max_execution_time` in relevant `php.ini` files | `300` | - ---- - -## setup_composer - -### Description - -`setup_composer()`: -- Detects existing Composer installation and updates if necessary. -- Installs the latest version using the official installer. -- Ensures the Composer binary is executable system-wide. -- Allows installation as root by setting `COMPOSER_ALLOW_SUPERUSER=1`. - -### Usage - -Simply call the function: - -```bash -setup_composer -``` - ---- - -## setup_go - -### Description - -`setup_go()`: -- Detects system architecture (supports `x86_64` and `aarch64`). -- Automatically fetches the latest Go version (if `GO_VERSION` is unset or set to `latest`). -- Installs Go system-wide to `/usr/local/go`, and symlinks the binary to `/usr/local/bin/go`. -- Replaces any existing Go installation if the version differs. - - -### Usage - -Simply call the function: - -```bash -setup_go -``` - ---- - -## setup_java - -### Description - -`setup_java()`: -- Automatically adds the Adoptium APT repository if missing. -- Detects the currently installed version of the Temurin JDK (if any). -- Installs the desired JDK version (defaults to 21) or upgrades it if already present. -- Removes any existing Temurin JDK versions if they differ from the target version. - - -### Usage - -```bash -setup_java -``` -This will install the default version of Temurin JDK. -You can set the JAVA_VERSION environment variable before calling the function: -```bash -JAVA_VERSION=17 setup_java -``` -### User-Configurable Variables -| Variable | Description | Default Value | -|----------------|----------------------------------------------------------|----------------| -| `JAVA_VERSION` | The version of Temurin JDK to install (e.g., 17, 21) | `21` | - ---- - -## - -### Description - -`setup_mongodb()`: -- Detects the currently installed version of MongoDB. -- Removes older versions (packages only; **data is preserved**). -- Adds the correct MongoDB APT repository and GPG key. -- Installs the specified version of MongoDB. -- Starts and enables the MongoDB service. - - -### Usage - -```bash -setup_mongodb -``` -Installs the default MongoDB version. -To install a different version (e.g., 7.0): - -```bash -MONGO_VERSION=7.0 setup_mongodb -``` - -### User-Configurable Variables -| Variable | Description | Default Value | -|----------------|----------------------------------------------|---------------| -| `MONGO_VERSION` | Target MongoDB major version (e.g., 6.0, 7.0, 8.0) | `8.0` | ---- - -## setup_uv - -### Description - -`setup_uv()`: -- Detects system architecture (`x86_64` or `aarch64`). -- Fetches the latest release version from GitHub. -- Checks if `uv` is already installed and at the latest version. -- Downloads and installs or updates `uv` from the official GitHub releases. -- Ensures `/usr/local/bin` is in the `PATH`. - - -### Usage - -```bash -setup_uv -``` -Installs or updates uv to the latest version. - ---- -## setup_gs - -### Description - -`setup_gs()`: -- Checks the currently installed Ghostscript version. -- Fetches the latest Ghostscript release version from GitHub. -- Compares the installed version with the latest available. -- Downloads, compiles, and installs Ghostscript from source if an update or installation is needed. -- Installs required build dependencies automatically. - - - -### Usage - -```bash -setup_gs -``` -Checks and installs/updates Ghostscript. ---- - -## setup_rbenv_stack - -### Description - -`setup_rbenv_stack()`: -- Fetches and installs the latest stable `rbenv` release. -- Fetches and installs the latest stable `ruby-build` plugin release. -- Adds necessary initialization commands to the user's profile (`~/.profile`) if missing. -- Installs a specified Ruby version (default 3.4.4) via rbenv. -- Optionally installs the latest Rails gem (`true` by default). -- Cleans up temporary files. - -### Usage - -```bash -setup_ruby -``` -Optionally, you can override defaults by setting environment variables: -```bash -RUBY_VERSION=3.3.2 RUBY_INSTALL_RAILS=false setup_ruby -``` -### User-Configurable Variables -| Variable | Description | Default Value | -|---------------------|--------------------------------|---------------| -| `RUBY_VERSION` | Ruby version to install | `3.4.4` | -| `RUBY_INSTALL_RAILS` | Whether to install Rails gem (true/false) | `true` | ---- - -## download_with_progress - -### Description - -`download_with_progress()`: -- Installs `pv` if not already present. -- Attempts to retrieve the file size (`Content-Length`) from the HTTP headers. -- If `Content-Length` is available, it uses `pv` to show a progress bar during the download. -- If `Content-Length` is unavailable, it falls back to a basic download with curl’s built-in progress. -- Handles any existing spinner process cleanup. -- Provides error messages on failure. - -### Usage - -```bash -download_with_progress -download_with_progress "https://example.com/file.zip" "/tmp/file.zip" -``` -###Paramters -| Parameter | Description | -|-----------|-------------------------------| -| `url` | URL of the file to download | -| `output` | Local file path to save the download | ---- +- ------------------------------------------------------------------------------ +- 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) +- ------------------------------------------------------------------------------ +## `setup_rust` +**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` +- 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") +- ------------------------------------------------------------------------------ +## `setup_uv` +**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 +- ------------------------------------------------------------------------------ +## `_install_uvx_wrapper` +**Description** +- Helper function to install uvx wrapper +## `setup_yq` +**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 +- ------------------------------------------------------------------------------