Sets the hostname and IPv4 network configuration for a VM
Source: target-root/usr/local/libexec/solidgroundux/manage-identity.sh
Sets the hostname and IPv4 network configuration for a VM
Public functions
Internal functions
| Function | Purpose | Arguments | Output |
|---|---|---|---|
_set_defaults | Initialize missing identity and network settings with the wizard defaults. | — | — |
_load_current_values | Load current values. | — | — |
_get_usr_input | Collect identity and network values using the shared prompt functions. | — | — |
_set_hostname | Apply the selected hostname to the current machine. | — | — |
_detect_primary_iface | Detect primary iface. | — | — |
_remove_other_netplan_files | Remove other netplan files. | — | — |
_static_ip_conflict_check | Static ip conflict check. | — | — |
_network_config | Configure the selected network interface using the chosen network settings. | — | — |
_set_static_ip | Write network configuration for the selected static IPv4 address. | — | — |
_set_dhcp | Switch the selected network interface to DHCP addressing. | — | — |
_write_netplan_static | Write a networkd Netplan YAML file using the chosen interface, address, | - $1: Optional output path; defaults to NETPLAN_FILE. | — |
_write_netplan_dhcp | Write a Netplan configuration that enables DHCP for the chosen interface. | - $1: Optional: output file path. | — |
_netplan_has_other_files | Test whether additional Netplan YAML configuration files are present. | — | — |
_backup_netplan_files | Copy all existing /etc/netplan/*.yaml files into the specified backup directory. | - $1: Required directory path for the backup. | — |
_restore_netplan_files | Remove current /etc/netplan/*.yaml files and restore the YAML files from | - $1: Required directory path containing the previous YAML files. | — |
_apply_netplan_config | Render and compare a static or DHCP network configuration, back up existing | - $1: Required configuration mode, static or dhcp. | — |
_dryrun_complete | Confirm explicitly that the preview completed without persistent changes. | — | — |
Description
This script sets the hostname and IPv4 network configuration for a VM.
Usage
Run the executable from its shell command (or installed wrapper):
manage-identity --dryrun
manage-identity --verbose
Script-specific options:
--Ipv4 VALUE,-i: Target static IPv4 address with CIDR.--dhcp NAME: Use DHCP for IPv4 configuration (choices:yes,no).--DNS VALUE,-d: Target DNS server IP address.--DNS-search VALUE: Target DNS search domain.--dns-only: Update only the configured DNS server and search domain.--Gateway VALUE,-g: Target gateway IP address.--Hostname VALUE,-n: Target hostname for the VM.--Netplan VALUE,-p: Path to the netplan configuration file.--Auto,-a: Run in non-interactive mode, using defaults or provided values.
Script identity
Absolute path to the currently executing script
var: SGND_SCRIPT_FILE
Directory containing the currently executing script
var: SGND_SCRIPT_DIR
Filename of the currently executing script
var: SGND_SCRIPT_BASE
Script basename without the .sh extension
var: SGND_SCRIPT_NAME
Framework integration
Optional framework libraries to source after core bootstrap
var: SGND_USING
Libraries to source from SGND_COMMON_LIB. These are loaded automatically by sgnd_bootstrap AFTER core libraries.
Example: SGND_USING=( net.sh fs.sh )
Leave empty if no extra libs are needed.
Script-specific command-line argument specification
var: SGND_ARGS_SPEC
Optional: script-specific arguments
Example: Arguments
Each entry: "name|short|type|var|help|default|choices"
name = long option name WITHOUT leading -- short - short option name WITHOUT leading - type = flag | value | enum var = shell variable that will be set help = help string for auto-generated --help output choices = for enum: comma-separated values (e.g. fast,slow,auto) for flag/value: leave empty
Notes:
- -h / --help is built in, you don't need to define it here.
- After parsing you can use: FLAG_VERBOSE, VAL_CONFIG, ENUM_MODE, ...
Optional help examples for this script
var: SGND_SCRIPT_EXAMPLES
Optional: examples for --help output. Each entry is a string that will be printed verbatim.
Example: SGND_SCRIPT_EXAMPLES=( "Example usage:" " script.sh --verbose --mode fast" " script.sh -v -m slow" )
Leave empty if no examples are needed.
Script globals participating in configuration loading# var: SGND_SCRIPT_GLOBALS - Script globals participating in configuration loading
var: SGND_SCRIPT_GLOBALS
Explicit declaration of global variables intentionally used by this script.
Purpose
- Declares which globals are part of the script’s public/config contract.
- Enables optional configuration loading when non-empty.
Behavior
- If this array is non-empty, sgnd_bootstrap enables config integration.
- Variables listed here may be populated from configuration files.
- Unlisted globals will NOT be auto-populated.
Use this to:
- Document intentional globals
- Prevent accidental namespace leakage
- Make configuration behavior explicit and predictable
Only list:
- Variables that must be globally accessible
- Variables that may be defined in config files
Leave empty if:
- The script does not use configuration-driven globals
Script variables participating in persistent state
var: SGND_STATE_VARIABLES
List of variables participating in persistent state.
Purpose
- Declares which variables should be saved/restored when state is enabled.
Behavior
- Only used when sgnd_bootstrap is invoked with --state.
- Variables listed here are serialized on exit (if SGND_STATE_SAVE=1).
- On startup, previously saved values are restored before main logic runs.
Contract:
- Variables must be simple scalars (no arrays/associatives unless explicitly supported).
- Script remains fully functional when state is disabled.
Leave empty if:
- The script does not use persistent state.
Script-specific exit handler list
var: SGND_ON_EXIT_HANDLERS
List of functions to be invoked on script termination.
Purpose
- Allows scripts to register cleanup or finalization hooks.
Behavior
- Functions listed here are executed during framework exit handling.
- Execution order follows array order.
- Handlers run regardless of normal exit or controlled termination.
Contract:
- Functions must exist before exit occurs.
- Handlers must not call exit directly.
- Handlers should be idempotent (safe if executed once).
Typical uses:
- Cleanup temporary files
- Persist additional state
- Release locks
Leave empty if:
- No custom exit behavior is required.
SGND_STATE_SAVE
var$: SGND_STATE_SAVE
State persistence toggle used by sgnd_bootstrap when state support is enabled.
Scripts that want persistent state must:
- set SGND_STATE_SAVE=1
- call sgnd_bootstrap --state or --autostate
Local script declarations
doc$ Local script declarations Put script-local constants and defaults here, not framework configuration. Prefer local variables inside functions unless a value must be shared.
