Core Module (00-core.sh)¶
Version: v14.0.0
File:src/lib/00-core.sh
Dependencies:helpers.sh
Overview¶
Core infrastructure module shared across all lib modules. Provides fundamental utilities for system detection, configuration management, and service port resolution.
Functions¶
System Detection¶
_check_bash_version()¶
Checks bash version compatibility and warns if using older versions.
Service Management¶
_service_mode(service_name)¶
Gets service mode (local/external/disabled) from configuration.
_resolve_service_port(service_name, default_port)¶
Resolves service port with fallback to default.
_find_free_port(start_port)¶
Finds available port starting from given port.
_port_is_free(port)¶
Checks if port is available.
_port_listening_owner(port)¶
Gets process listening on port.
Configuration Management¶
_set_config(key, value)¶
Sets configuration value in setup.conf.
_get_config(key)¶
Gets configuration value from setup.conf.
Service Port Lookup¶
_get_service_port(service_name)¶
Gets default port for service.
Variables¶
| Variable | Description | Default |
|---|---|---|
SCRIPT_VERSION | Script version | v14.0.0 |
ARCH | System architecture | Auto-detected |
PKG_MANAGER | Package manager | Auto-detected |
SETUP_CONF | Setup configuration file | ~/.config/opencode-setup/setup.conf |
DL_CACHE | Download cache directory | ~/.cache/opencode-setup |
Usage¶
# Source the module
source src/lib/helpers.sh
source src/lib/00-core.sh
# Use functions
_core_help # Show help
port=$(_get_service_port "postgres")
_set_config "MY_VAR" "value"
Architecture Detection¶
The module automatically detects: - Architecture: amd64, arm64 - Package Manager: apt, dnf, pacman, apk, zypper, brew - OS: Ubuntu, Debian, and derivatives
Error Handling¶
All functions use set -euo pipefail for strict error handling. Errors are logged via err() and warn() functions from helpers.sh.
See Also¶
- helpers.sh - Helper functions
- 00d-parallel.sh - Parallel execution
- 00e-cache-mgr.sh - Cache management