Manage Samba shares
Source: target-root/usr/local/libexec/solidgroundux/manage-samba-shares.sh
Manage Samba shares
Public functions
Internal functions
| Function | Purpose | Arguments | Output |
|---|---|---|---|
_dryrun_complete | Report the dry-run result without executing the requested host change. | — | — |
_refresh_storage_paths | Resolve the configured SolidGroundUX share root. | — | — |
_smb_ask_selection | Keep selection mechanics local while the manager owns the surrounding UI layout. | - --label TEXT | — |
_share_path | Resolve the configured path for a Samba share. | — | — |
_share_root_traversable | Ensure authenticated share users can traverse the SolidGroundUX share container | — | — |
_list_managed_shares | Discover shares beneath the SolidGroundUX share root. | — | (globals) |
_select_shares | Select one or more managed shares. | — | (globals) |
_acl_groups_for_share | Return named group ACL entries for one share. | - $1 SHARE | Writes GROUP\ |
_validate_share_name | Validate a managed Samba share name. | — | — |
_validate_relative_path | Validate a relative path beneath the share root. | - $1 Relative directory path. | — |
_share_exists | Test whether a Samba share exists. | - $1: Optional: name of the selected item. | — |
_share_path_in_use | Test whether a backing directory is already used by a managed share. | - $1 PATH | — |
_reload_samba | Validate and reload Samba configuration. | — | — |
_resolve_access_group_input | Normalize and validate a persisted/default group without guessing across authentication modes. | - $1 User-entered group name; empty means no default access group. | — |
_apply_group_access_to_groups | Share the ACL/Samba synchronization implementation between interactive access changes | - $1 MODE - read or write. | — |
_create_share | Create a Samba share and optionally apply a stateful default access group/access level. | — | — |
_remove_share | Remove a managed share and optionally its directory. | — | — |
_ensure_kerberos_ticket | Require an existing Kerberos TGT before querying Active Directory through LDAP/GSSAPI. | — | — |
_discover_ad_groups | Query Active Directory directly for group names and include groups already | — | (globals): |
_select_groups | Allow one or more Active Directory groups to be selected in a single operation. | - $1 OUTPUT_ARRAY_VAR | — |
_samba_principal | Format an NSS group for a Samba user-list parameter. | - $1: Group name. | Writes a quoted Samba group principal. |
_sync_share_samba_access | Synchronize Samba access lists from POSIX ACLs. | - $1 SHARE | — |
_apply_group_access | Apply read or write ACLs to selected shares. | - $1 MODE - read or write. | — |
_select_assigned_group | Select a group currently assigned to the selected shares. | - $1 OUTPUT_VAR | — |
_remove_group_access | Remove one AD/NSS group's access from selected shares. | — | — |
_validate_selected | Validate selected share paths, traversal, ACLs, and Samba configuration. | — | — |
_smb_runtime_auth_mode | Return the configured Samba authentication mode. | — | — |
_list_local_groups_raw | Return local groups suitable for explicit Samba access management without | — | Writes one local access-group name per line. |
_local_group_display | Label deliberate standalone access groups consistently in selectors. | - $1 Local group name. | Writes a display label. |
_select_local_groups | Select one or more local groups. | - $1 Output array variable name. | — |
_pause_return_to_share_manager | Keep terminal action results visible. | - $1 Optional message. | — |
_select_access_groups | Return multiple AD groups in AD mode while retaining single-group selection for | - $1 OUTPUT_ARRAY_VAR | — |
_select_access_group | Reuse the authentication-aware access-group selector while enforcing the single | - $1 OUTPUT_VAR | — |
_show_shares_overview | Display comprehensive managed-share access information. | — | — |
_reconcile_access_group | Reconcile share ACL identities after changing Samba authentication mode without guessing mappings. | — | — |
_smb_menu_require_selection | Require at least one Samba share before performing a selection-based action. | — | — |
_smb_menu_create_share | Open the create-share action in the Samba share manager. | — | — |
_smb_menu_show_shares | Show the overview of configured Samba shares. | — | — |
_smb_menu_reconcile | Reconcile Samba access groups and return to the share menu. | — | — |
_smb_menu_remove_share | Open the Samba share-removal workflow. | — | — |
_smb_menu_select_shares | Prompt for the Samba shares to operate on. | — | — |
_smb_menu_grant_read | Start the interactive Samba share read-access grant workflow. | — | — |
_smb_menu_grant_write | Start the interactive Samba share write-access grant workflow. | — | — |
_smb_menu_remove_access | Remove group access from the selected shares and return to the menu. | — | — |
_smb_menu_validate | Run Samba share configuration checks from the share-management menu. | — | — |
_smb_menu_build | Register and display the Samba share-management menu actions. | — | — |
Description
Provides interactive management of SolidGroundUX Samba shares, including share lifecycle, validation, and AD/NSS or standalone group access synchronized through POSIX ACLs and Samba valid-users/write-list settings. Standalone Samba user/group lifecycle is implemented by manage-samba-users.sh; directory lifecycle and directory-level ACL management are implemented by manage-samba-directories.sh.
Design principles
- Executables are explicit: resolve, bootstrap, then run
- Libraries never auto-execute (composition over inheritance)
- Framework integration is opt-in and declarative
- UI and input must be TTY-safe
Role in framework
- Entry point pattern for all SolidGroundUX-based scripts
- Defines how scripts integrate with sgnd-bootstrap and common libraries
Non-goals
- Business logic implementation (provided by the script author)
- Library behavior (handled in /common modules)
Usage
Run the executable from its shell command (or installed wrapper):
manage-samba-shares --dryrun
manage-samba-shares --verbose
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|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
