Skip to main content

⏯️ Switches

DI introduces a package management system. This allows defining and accessing structured packages for flexible operations like copying, extracting, or executing.


add_switch​

Defines a package with a structure of versions and associated actions.

add_switch [-exec | -import] "package_name[:zip_path]" "package_struct"
FlagDescription
-execExecutes binaries or scripts in a new process.
-importImports scripts into the DI environment.
info
  • package_name: Unique package identifier.
  • zip_path: For ZIP-based packages (Optional).
  • package_struct: Defines the package structure (see below).
warning

Avoid using | in package_name, as it’s reserved for internal array handling.

Example:

add_switch example "
key1 = source.txt, dest.txt
key2 = source2.txt, dest2.txt
keyN = sourceN.txt, destN.txt
"

Package Structure​

Define the structure of the package and the behavior of the paths.

version_name = path1, path2
ComponentDescription
version_nameKey to access the package variant.
path1Source file or directory.
path2Optional destination.
note

Behavior:

  • Paths ends with /: Treats it as a directory.
  • No /: Treats it as a full path.
warning

Avoid using | in version_name, as it’s reserved for internal array handling.


switch​

Accesses a package’s version and performs the associated action.

switch <package_name> <version_name> [ARGs]
ArgumentDescription
package_nameName of the defined package.
version_nameVersion key to access.
[ARGs]Optional arguments

Example:

switch tools v1  # Switches to version "v1" of the "tools" package

General Examples​

Here are examples showing how add_switch and switch work together:

External Files​

Define a package with tools and switch between versions:

add_switch tools "
v1 = $TMP/tool_v1.bin, $TMP/tool.bin
v2 = $TMP/tool_v2.bin, $TMP/tool.bin
data = $TMP/data/, $TMP/output
data_dir = $TMP/data/, $TMP/output/
"
switch tools v2 # Copies tool_v2.bin to $TMP/tool.bin
switch tools data # Copies data contents to $TMP/output (Result: $TMP/output)
switch tools data_dir # Copies data folder into $TMP/output (Result: $TMP/output/data)
tip

Ends paths with / to control directory vs. file behavior precisely.

ZIP-Based Package​

Extract files from a ZIP package:

add_switch "resources: /sdcard/resources.zip" "
config = config/, $TMP/setup
config_dir = config/, $TMP/setup/
file = settings.txt, $TMP/
"
switch resources config # Extracts config contents to $TMP/setup (Result: $TMP/setup)
switch resources config_dir # Extracts config into $TMP/setup (Result: $TMP/setup/config)
switch resources file # Extracts settings.txt to $TMP/

Execution Package​

Run a binary from a ZIP:

add_switch -exec "binaries: /sdcard/binaries.zip" "
bb = busybox, $TMP/binaries/
"
switch binaries bb sed --help # Executes busybox that's inside binaries.zip with extra ARGs
tip

The file destination is optional but recommended. Ensures that the binary is extracted to a predictable path, if not specified a default path will be used.

Import Package​

Import a script into the environment:

add_switch -import utils "
helper = /sdcard/helper.sh
"
switch utils helper arg1 arg2 # Imports helper.sh with ARGs "arg1" "arg2"
note

No file destination is needed here since -import sources the script directly. In addition, no extraction is performed.