13
tools.func
Slaviša Arežina edited this page 2025-06-27 22:30:41 +02:00
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This page describes all helper functions defined in misc/tools.func

The tools.func file is automatically sourced and can be used in all $APP-install.sh files.

fetch_and_deploy_gh_release

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/<app>.
  • 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.

Usage

fetch_and_deploy_gh_release <github_repo>

fetch_and_deploy_gh_release "owner/repository"


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

setup_nodejs():

  • 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.

Usage

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:

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():

  • 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.

Usage

setup_postgresql

Specifie a Version:

PG_VERSION=15 setup_postgresql

User-Configurable Variables

Variable Description Default Value
PG_VERSION Specifies the major version of PostgreSQL to install or upgrade to (e.g., 14, 15, 16). 16

setup_mariadb

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

setup_mariadb

You can optionally set the MARIADB_VERSION environment variable before calling the function to specify a particular version to install.

Example:

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

setup_mysql

To install a specific version of MySQL, export the MYSQL_VERSION variable before calling the function:

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

setup_php

You can set any of the environment variables below to customize the behavior:

PHP_VERSION="8.3" PHP_APACHE="YES" PHP_FPM="NO" PHP_MEMORY_LIMIT="1G" setup_php

PHP Modules

These modules are installed by default:

bcmath, cli, curl, gd, intl, mbstring, opcache, readline, xml, zip

You can add custom modules with this command:

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:

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:

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

setup_java

This will install the default version of Temurin JDK. You can set the JAVA_VERSION environment variable before calling the function:

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

setup_mongodb

Installs the default MongoDB version. To install a different version (e.g., 7.0):

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

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

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

setup_ruby

Optionally, you can override defaults by setting environment variables:

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 curls built-in progress.
  • Handles any existing spinner process cleanup.
  • Provides error messages on failure.

Usage

download_with_progress <url> <output_path>
download_with_progress "https://example.com/file.zip" "/tmp/file.zip"
Parameter Description
url URL of the file to download
output Local file path to save the download

###Paramters