core #
Core Module
The Core module provides fundamental system-level functionality for the Hero framework. It handles platform detection, system operations, and provides essential utilities used throughout the framework.
Main Features
Platform Management
- Platform detection (OSX, Ubuntu, Alpine, Arch)
- CPU architecture detection (Intel, ARM)
- System information retrieval (hostname, init system)
- Cross-platform compatibility utilities
Memory Database
- Thread-safe in-memory key-value store
- Global state management
- Caching for system information
Sudo Operations
- Permission management and verification
- Sudo requirement detection
- Path access rights checking
- Command elevation handling
Submodules
- base: Context and session management
- httpconnection: HTTP client functionality
- logger: Logging infrastructure
- pathlib: Path manipulation and handling
- playbook: Execution playbooks
- redisclient: Redis database client
- rootpath: Root path management
- smartid: Identifier management
- texttools: Text manipulation utilities
- vexecutor: Command execution
Platform Support
The module supports multiple platforms:- macOS (Intel and ARM)
- Ubuntu
- Alpine Linux
- Arch Linux
And CPU architectures:- x86_64 (Intel)
- ARM64/AArch64
Usage
The core module provides essential functionality used by other Hero framework components. Key features include:
Interactivity Check & Influence on delete
import freeflowuniverse.herolib.installers.lang.golang
import freeflowuniverse.herolib.core
core.interactive_set()! //make sure the sudo works so we can do things even if it requires those rights
//this will allow files which are in sudo area to still get them removed but its important interactive is set on the context.
golang.install(reset:false)!
Platform Detection
// Check platform type
if core.is_linux()! {
// Linux-specific code
}
// Check CPU architecture
if core.is_linux_arm()! {
// ARM-specific code
}
Memory Database
// Store values
core.memdb_set('key', 'value')
// Retrieve values
value := core.memdb_get('key')
Sudo Operations
The sudo operations module provides comprehensive permission management and command elevation handling:
// Check if sudo is required for the current user
if core.sudo_required()! {
// Handle sudo requirements
// Returns false if user is root or on macOS
// Returns true if user has sudo privileges
}
// Verify path permissions and accessibility
path := core.sudo_path_check('/path/to/check')! {
// Returns the path if accessible
// Errors if path requires sudo rights
}
// Check if a path is accessible without sudo
if core.sudo_path_ok('/usr/local/bin')! {
// Returns false for protected directories like:
// /usr/, /boot, /etc, /root/
// Returns true if path is accessible
}
// Check and modify commands that require sudo
cmd := core.sudo_cmd_check('ufw enable')! {
// Automatically adds 'sudo' prefix if:
// 1. Command requires elevated privileges
// 2. User doesn't have sudo rights
// 3. Running in interactive mode
}
// Check if current process has sudo rights
if core.sudo_rights_check()! {
// Returns true if:
// - Running as root user
// - Has necessary sudo privileges
}
fn cmd_exists #
fn cmd_exists(cmd string) bool
fn cputype #
fn cputype() !CPUType
fn cputype_enum_from_string #
fn cputype_enum_from_string(cputype string) CPUType
Returns the enum value that matches the provided string for CPUType
fn hostname #
fn hostname() !string
fn initname #
fn initname() !string
e.g. systemd, bash, zinit
fn interactive #
fn interactive() !bool
check if we are interactive in current context
fn interactive_set #
fn interactive_set() !
fn is_linux #
fn is_linux() !bool
fn is_linux_arm #
fn is_linux_arm() !bool
fn is_linux_intel #
fn is_linux_intel() !bool
fn is_osx #
fn is_osx() !bool
fn is_osx_arm #
fn is_osx_arm() !bool
fn is_osx_intel #
fn is_osx_intel() !bool
fn is_ubuntu #
fn is_ubuntu() !bool
fn memdb_exists #
fn memdb_exists(key string) bool
fn memdb_get #
fn memdb_get(key string) string
fn memdb_set #
fn memdb_set(key string, val string)
fn platform #
fn platform() !PlatformType
fn platform_enum_from_string #
fn platform_enum_from_string(platform string) PlatformType
fn sudo_cmd #
fn sudo_cmd(cmd string) !bool
if we know cmd requires sudo rights
fn sudo_cmd_check #
fn sudo_cmd_check(cmd string) !string
if sudo required and we are interactive then we will put sudo in front of returned cmd
fn sudo_path_check #
fn sudo_path_check(path string) !string
check path is accessible, e.g. do we need sudo and are we sudo if ok then will just return the same path string as output
fn sudo_path_ok #
fn sudo_path_ok(path string) !bool
return false if we can't work on the path
fn sudo_required #
fn sudo_required() !bool
Method to check if sudo is required (i.e., if the user is root or has sudo privileges)
fn sudo_rights_check #
fn sudo_rights_check() !bool
check of we have sudo rights, if yes return true
enum CPUType #
enum CPUType {
unknown
intel
arm
intel32
arm32
}
enum PlatformType #
enum PlatformType {
unknown
osx
ubuntu
alpine
arch
suse
}
import freeflowuniverse.herolib.ui.console Returns the enum value that matches the provided string for PlatformType
- README
- fn cmd_exists
- fn cputype
- fn cputype_enum_from_string
- fn hostname
- fn initname
- fn interactive
- fn interactive_set
- fn is_linux
- fn is_linux_arm
- fn is_linux_intel
- fn is_osx
- fn is_osx_arm
- fn is_osx_intel
- fn is_ubuntu
- fn memdb_exists
- fn memdb_get
- fn memdb_set
- fn platform
- fn platform_enum_from_string
- fn sudo_cmd
- fn sudo_cmd_check
- fn sudo_path_check
- fn sudo_path_ok
- fn sudo_required
- fn sudo_rights_check
- enum CPUType
- enum PlatformType