Documentation
¶
Overview ¶
Package uci contains utility functions to wrap around the uci program.
The UCI (United Configuration Interface) system is used to centralize the configuration of OpenWrt services.
See https://openwrt.org/docs/guide-user/base-system/uci for documentation on the UCI system and https://openwrt.org/docs/guide-user/base-system/uci#command-line_utility for documentation on the uci CLI which this package uses.
Index ¶
- Constants
- func BackupConfig(ctx context.Context, uci *Runner, config, backupFilePath string) (string, error)
- func CommitAndReloadConfig(ctx context.Context, uci *Runner, config string) error
- func ReloadConfigServices(ctx context.Context, uci *Runner, configs ...string) error
- func ReloadNetwork(ctx context.Context, uci *Runner) error
- func ReloadWifi(ctx context.Context, uci *Runner) error
- func ResetConfigs(ctx context.Context, uci *Runner, expectBackupsToExist bool, configs ...string) error
- func RestartDnsmasq(ctx context.Context, uci *Runner) error
- func RestoreConfig(ctx context.Context, uci *Runner, config, backupFilePath string, ...) (bool, error)
- type CLIFlag
- func CLIFlagConfigPath(path string) CLIFlag
- func CLIFlagDelimiter() CLIFlag
- func CLIFlagDisableStrictMode() CLIFlag
- func CLIFlagDoNotNameUnnamedSections() CLIFlag
- func CLIFlagDoNotUseShowExtendedSyntax() CLIFlag
- func CLIFlagFileInput(file string) CLIFlag
- func CLIFlagForceStrictMode() CLIFlag
- func CLIFlagMerge() CLIFlag
- func CLIFlagNameUnnamedSections() CLIFlag
- func CLIFlagQuietMode() CLIFlag
- func CLIFlagSearchPath(path string) CLIFlag
- func CLIFlagSearchPathDefault(path string) CLIFlag
- type Runner
- func (r *Runner) Add(ctx context.Context, config, sectionType string, flags ...CLIFlag) error
- func (r *Runner) AddList(ctx context.Context, config, section, option, str string, flags ...CLIFlag) error
- func (r *Runner) Batch() error
- func (r *Runner) Changes(ctx context.Context, config string, flags ...CLIFlag) ([]string, error)
- func (r *Runner) Commit(ctx context.Context, config string, flags ...CLIFlag) error
- func (r *Runner) DelList(ctx context.Context, config, section, option, str string, flags ...CLIFlag) error
- func (r *Runner) Delete(ctx context.Context, config, section, option string, flags ...CLIFlag) ([]string, error)
- func (r *Runner) Export(ctx context.Context, config string, flags ...CLIFlag) ([]string, error)
- func (r *Runner) Get(ctx context.Context, config, section, option string, flags ...CLIFlag) ([]string, error)
- func (r *Runner) Import(ctx context.Context, config string, flags ...CLIFlag) error
- func (r *Runner) Rename(ctx context.Context, config, section, option, name string, flags ...CLIFlag) error
- func (r *Runner) Reorder(ctx context.Context, config, section, position string, flags ...CLIFlag) error
- func (r *Runner) Revert(ctx context.Context, config, section, option string, flags ...CLIFlag) error
- func (r *Runner) Set(ctx context.Context, config, section, option, value string, flags ...CLIFlag) error
- func (r *Runner) Show(ctx context.Context, config, section, option string, flags ...CLIFlag) ([]string, error)
- func (r *Runner) Uci(ctx context.Context, flags []CLIFlag, args ...string) error
- func (r *Runner) UciWithOutput(ctx context.Context, flags []CLIFlag, args ...string) ([]string, error)
Constants ¶
const ( // ConfigDHCP is the name of config for dnsmasq and odhcpd // settings: DNS, DHCP, DHCPv6. ConfigDHCP = "dhcp" // ConfigNetwork is the name of the config for switch, interface and // route configuration: Basics, IPv4, IPv6, Routes, Rules, WAN, Aliases, // Switches, VLAN, IPv4/IPv6 transitioning, Tunneling. ConfigNetwork = "network" // ConfigWireless is the name of the config for wireless settings and // Wi-Fi network definition. ConfigWireless = "wireless" )
Constants for relevant config names as specified in the OpenWrt documentation here: https://openwrt.org/docs/guide-user/base-system/uci#configuration_files.
Variables ¶
This section is empty.
Functions ¶
func BackupConfig ¶
BackupConfig copies the config file, located at configDir/config, to the backupPath. If no backupFilePath is specified, it defaults to using configBackupDir/config. Returns the path to the newly created backup file. If the backupFilePath does not contain a directory, it is assumed that the target directory is configBackupDir.
If a file exists at backupFilePath already, it is overwritten.
Note: A "uci commit" is not necessary after running this, as it manually changes the config files and does not go through the uci CLI. However, to make the config changes used, any corresponding services that use it must be reloaded.
func CommitAndReloadConfig ¶
CommitAndReloadConfig first commits any pending config changes and then reloads its dependent service to put the changes into effect.
func ReloadConfigServices ¶
ReloadConfigServices reloads any service that uses any of the specified configs with the current committed configuration settings.
func ReloadNetwork ¶
ReloadNetwork reloads the network service with the current committed settings in ConfigNetwork. See the OpenWrt documentation for more info at https://openwrt.org/docs/guide-user/base-system/basic-networking#network_configuration_management.
func ReloadWifi ¶
ReloadWifi reloads Wi-Fi, which uses the current committed settings in that are in ConfigWireless.
func ResetConfigs ¶
func ResetConfigs(ctx context.Context, uci *Runner, expectBackupsToExist bool, configs ...string) error
ResetConfigs restores the given configs to their backed up states. If expectBackupsToExist is false, configs are backed up again after they are restored to ensure a backup exists.
Note: A "uci commit" is not necessary after running this, as it manually changes the config files and does not go through the uci CLI. However, to make the config changes used, any corresponding services that use them must be reloaded.
func RestartDnsmasq ¶
RestartDnsmasq restarts the dnsmasq service, which reloads the current committed settings that are in ConfigDHCP. See the OpenWrt documentation for more info at https://openwrt.org/docs/guide-user/base-system/dhcp.
func RestoreConfig ¶
func RestoreConfig(ctx context.Context, uci *Runner, config, backupFilePath string, ignoreMissingBackup bool) (bool, error)
RestoreConfig restores the config by replacing the existing config file, located at configDir/config, with a previously backed up copy located at backupFilePath. If no backupFilePath is specified, it defaults to using configBackupDir/config. If backupFilePath does not exist and ignoreMissingBackup is true, the config will not be changed and the function will return false. Returns true if the target config was updated from an existing backup.
Note: A "uci commit" is not necessary after running this, as it manually changes the config files and does not go through the uci CLI. However, to make the config changes used, any corresponding services that use it must be reloaded.
Types ¶
type CLIFlag ¶
type CLIFlag []string
CLIFlag is a list of the CLI arguments that make up a CLI flag and any parameters the flag requires for the uci command.
uci CLI flags are documented at https://openwrt.org/docs/guide-user/base-system/uci#usage.
func CLIFlagConfigPath ¶
CLIFlagConfigPath builds the CLIFlag that configures the uci command to set the search path for config files (default: /etc/config).
func CLIFlagDelimiter ¶
func CLIFlagDelimiter() CLIFlag
CLIFlagDelimiter builds the CLIFlag that configures the uci command to set the delimiter for list values in uci show.
func CLIFlagDisableStrictMode ¶
func CLIFlagDisableStrictMode() CLIFlag
CLIFlagDisableStrictMode builds the CLIFlag that configures the uci command to disable strict mode.
func CLIFlagDoNotNameUnnamedSections ¶
func CLIFlagDoNotNameUnnamedSections() CLIFlag
CLIFlagDoNotNameUnnamedSections builds the CLIFlag that configures the uci command to not name unnamed sections.
func CLIFlagDoNotUseShowExtendedSyntax ¶
func CLIFlagDoNotUseShowExtendedSyntax() CLIFlag
CLIFlagDoNotUseShowExtendedSyntax builds the CLIFlag that configures the uci command to not use extended syntax on 'show'.
func CLIFlagFileInput ¶
CLIFlagFileInput builds the CLIFlag that configures the uci command to use file as input instead of stdin.
func CLIFlagForceStrictMode ¶
func CLIFlagForceStrictMode() CLIFlag
CLIFlagForceStrictMode builds the CLIFlag that forces the uci command to use strict mode (stops on parser errors and is the default behavior).
func CLIFlagMerge ¶
func CLIFlagMerge() CLIFlag
CLIFlagMerge builds the CLIFlag that configures the uci command to merge data into an existing package when importing.
func CLIFlagNameUnnamedSections ¶
func CLIFlagNameUnnamedSections() CLIFlag
CLIFlagNameUnnamedSections builds the CLIFlag that configures the uci command to name unnamed sections on export (default behavior).
func CLIFlagQuietMode ¶
func CLIFlagQuietMode() CLIFlag
CLIFlagQuietMode builds the CLIFlag that configures the uci command to use quiet mode (does not print error messages).
func CLIFlagSearchPath ¶
CLIFlagSearchPath builds the CLIFlag that configures the uci command to add a search path for config change files.
func CLIFlagSearchPathDefault ¶
CLIFlagSearchPathDefault builds the CLIFlag that configures the uci command to add a search path for config change files and use it as a default.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner contains methods for running the uci command.
func NewRemoteRunner ¶
NewRemoteRunner creates an uci runner for remote execution.
func (*Runner) Add ¶
Add adds an anonymous section of type sectionType to the given configuration.
CLI usage is "uci add <config> <sectionType>".
func (*Runner) AddList ¶
func (r *Runner) AddList(ctx context.Context, config, section, option, str string, flags ...CLIFlag) error
AddList adds the given string to an existing list option.
CLI usage is "uci add_list <config>.<section>.<option>=<str>".
func (*Runner) Batch ¶
Batch executes a multi-line UCI script which is typically wrapped into a "here" document syntax. This command is not supported by this wrapper and an error will always be returned if this is called.
func (*Runner) Changes ¶
Changes lists staged changes to the given configuration file or if none given, all configuration files.
CLI usage is "uci changes [<config>]".
func (*Runner) Commit ¶
Commit writes changes of the given configuration file, or if none is given, all configuration files, to the filesystem.
All “uci set”, “uci add”, “uci rename” and “uci delete” commands are staged into a temporary location and written to flash at once with “uci commit”. This must be called after editing any of the mentioned commands to save their changes.
CLI usage is "uci commit [<config>]".
func (*Runner) DelList ¶
func (r *Runner) DelList(ctx context.Context, config, section, option, str string, flags ...CLIFlag) error
DelList removes the given string from an existing list option.
CLI usage is "uci del_list <config>.<section>.<option>=<str>".
func (*Runner) Delete ¶
func (r *Runner) Delete(ctx context.Context, config, section, option string, flags ...CLIFlag) ([]string, error)
Delete deletes the given section or option.
CLI usage is "uci delete <config>.<section>[.<option>]".
func (*Runner) Export ¶
Export exports the configuration in a machine-readable format.
CLI usage is "uci export [<config>]".
func (*Runner) Get ¶
func (r *Runner) Get(ctx context.Context, config, section, option string, flags ...CLIFlag) ([]string, error)
Get gets the value of the given option or the type of the given section.
CLI usage is "uci get <config>.<section>[.<option>]".
func (*Runner) Import ¶
Import imports configuration files in UCI syntax.
CLI usage is "uci import [<config>]".
func (*Runner) Rename ¶
func (r *Runner) Rename(ctx context.Context, config, section, option, name string, flags ...CLIFlag) error
Rename renames the given option or section to the given name.
CLI usage is "uci rename <config>.<section>[.<option>]=<name>".
func (*Runner) Reorder ¶
func (r *Runner) Reorder(ctx context.Context, config, section, position string, flags ...CLIFlag) error
Reorder moves a section to another position.
CLI usage is "uci reorder <config>.<section>=<position>".
func (*Runner) Revert ¶
func (r *Runner) Revert(ctx context.Context, config, section, option string, flags ...CLIFlag) error
Revert reverts the given option, section or configuration file.
CLI usage is "uci revert <config>[.<section>[.<option>]]".
func (*Runner) Set ¶
func (r *Runner) Set(ctx context.Context, config, section, option, value string, flags ...CLIFlag) error
Set sets the value of the given option, or adds a new section with the type set to the given value.
CLI usage is "uci set <config>.<section>[.<option>]=<value>".
func (*Runner) Show ¶
func (r *Runner) Show(ctx context.Context, config, section, option string, flags ...CLIFlag) ([]string, error)
Show shows the given option, section or configuration in compressed notation.
CLI usage is "uci show [<config>[.<section>[.<option>]]]".