β―οΈ 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"
Flag | Description |
---|---|
-exec | Executes binaries or scripts in a new process. |
-import | Imports scripts into the DI environment. |
package_name
: Unique package identifier.zip_path
: For ZIP-based packages (Optional).package_struct
: Defines the package structure (see below).
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
Component | Description |
---|---|
version_name | Key to access the package variant. |
path1 | Source file or directory. |
path2 | Optional destination. |
Behavior:
- Paths ends with
/
: Treats it as a directory. - No
/
: Treats it as a full path.
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]
Argument | Description |
---|---|
package_name | Name of the defined package. |
version_name | Version 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)
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
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"
No file destination is needed here since -import
sources the script directly. In addition, no extraction is performed.