55# Usage:
66# The `_container_modules_parse` function processes a comma-separated list of modules from an environment variable.
77# Modules can be added or removed using the following syntax:
8- # - To add a module: `+module_name` or `+git:<repository_url>#<branch_or_tag>`
8+ # - To add a module: `+module_name` or `+git:<repository_url>#<branch_or_tag>[:<subpath>] `
99# Example: `+git:https://github.com/user/repo.git#v1.0.0`
1010# - To remove a module: `-module_name`
1111#
1515# - The repository is cloned into `/container/modules/<repository_name>`.
1616# - Optionally, a branch or tag can be specified using `#<branch_or_tag>` in the repository URL.
1717# - Example: `git:https://github.com/user/repo.git#main` (clones the `main` branch).
18+ # - To target a subdirectory within the repository, append `:<subpath>` after the ref.
19+ # - Example: `git:https://github.com/user/modules.git#main:tailscale` (installs from `tailscale/` subdirectory).
1820
1921if [ -n "${2}" ]; then _container_module_path:-"${2}" ; fi
2022_container_module_path=${_container_module_path:-"/container/base/modules/"}
@@ -48,13 +50,34 @@ _container_modules_remove() {
4850_container_modules_install() {
4951 if [[ "${1}" == git:* ]]; then
5052 # Handle Git-based module installation
51- local repo_url ref module_name
53+ local repo_url ref subpath module_name
5254 repo_url=$(echo "${1}" | sed 's|^git:||' | cut -d'#' -f1) # Extract the repo URL
5355 ref=$(echo "${1}" | grep -o '#.*' | sed 's|#||') # Extract the branch or tag (if specified)
54- module_name=$(basename "${repo_url}" .git) # Derive module name from repo URL
56+ subpath=""
5557
56- # Define the target directory for the module
57- local target_dir="/container/modules/${module_name}"
58+ # Check for optional :<subpath> suffix in the ref portion
59+ if echo "${ref}" | grep -q ':'; then
60+ subpath=$(echo "${ref}" | sed 's|^[^:]*:||')
61+ ref=$(echo "${ref}" | sed 's|:.*||')
62+ fi
63+
64+ # Derive module name from subpath or repo URL
65+ if [ -n "${subpath}" ]; then
66+ module_name=$(basename "${subpath}")
67+ else
68+ module_name=$(basename "${repo_url}" .git)
69+ fi
70+
71+ # Use subpath to derive repo-level directory name
72+ local repo_dir_name
73+ if [ -n "${subpath}" ]; then
74+ repo_dir_name=$(basename "${repo_url}" .git)
75+ else
76+ repo_dir_name="${module_name}"
77+ fi
78+
79+ # Define the target directory for the cloned repository
80+ local target_dir="/container/modules/${repo_dir_name}"
5881
5982 # Clone the repository
6083 if [ -d "${target_dir}" ]; then
@@ -80,9 +103,15 @@ _container_modules_install() {
80103 fi
81104 fi
82105
106+ # Determine where to find the module script
107+ local module_script_path="${target_dir}/module"
108+ if [ -n "${subpath}" ]; then
109+ module_script_path="${target_dir}/${subpath}/module"
110+ fi
111+
83112 # Treat the cloned repository as a local module
84- if [ -f "${target_dir}/module " ]; then
85- bash "${target_dir}/module " install
113+ if [ -f "${module_script_path} " ]; then
114+ bash "${module_script_path} " install
86115 case ${?} in
87116 0 )
88117 :
0 commit comments