Skip to content

Commit 11e0b75

Browse files
committed
Support multiple post-install targets and document env usage
1 parent f8d7b54 commit 11e0b75

2 files changed

Lines changed: 55 additions & 10 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ DEVBOX_PROJECTS_DIR=/volume1/projects
122122
| DEVBOX_PASSWORDLESS_SUDO | Passwordless sudo mode | on |
123123
| DEVBOX_HOME_DIR | Persistent home dir on host | auto-resolved by `devbox.sh` |
124124
| DEVBOX_CONTAINER_NAME | Container name | devbox |
125+
| POST_INSTALL_TARGET | Post-install target(s), comma-separated | empty |
125126

126127
Flags override environment variables.
127128
Note: auto-resolution for `DEVBOX_HOME_DIR` applies only when `DEVBOX_HOME_DIR` is empty/unset.
129+
Note: `POST_INSTALL_TARGET` supports one or many targets, for example `ai` or `dev,ai`.
128130

129131
### 3.2 Path Model (Important)
130132

@@ -403,6 +405,14 @@ Run with:
403405
./devbox.sh --post-install example
404406
```
405407

408+
Multiple targets in one run:
409+
410+
```bash
411+
./devbox.sh --post-install dev --post-install ai
412+
# or
413+
./devbox.sh --post-install dev,ai
414+
```
415+
406416
Playwright can be combined with any post-install target (optional):
407417

408418
```bash

devbox.sh

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Options:
2121
--playwright Also start playwright profile container
2222
--playwright-ssh-port PORT SSH port for playwright container (default: 2203)
2323
--playwright-container NAME Playwright container name (default: devbox-playwright)
24-
--post-install TARGET Optional post-install script/profile: example | dev | ai | migrate | /projects/path/script.sh
24+
--post-install TARGET Optional post-install script/profile(s): example | dev | ai | migrate | /projects/path/script.sh
25+
Repeat flag or use comma list: --post-install dev --post-install ai / --post-install dev,ai
2526
--env-file PATH Optional env file (default auto-load: ./.env, then ./.env.local)
2627
--recreate Remove existing containers before rebuild
2728
-h, --help Show this help
@@ -49,6 +50,8 @@ DEVBOX_PLAYWRIGHT_ENABLED="no"
4950
DEVBOX_PLAYWRIGHT_SSH_PORT="2203"
5051
DEVBOX_PLAYWRIGHT_CONTAINER_NAME="devbox-playwright"
5152
POST_INSTALL_TARGET=""
53+
POST_INSTALL_SET_BY_CLI="no"
54+
POST_INSTALL_TARGETS=()
5255
DEVBOX_ENV_FILE=""
5356
RECREATE="no"
5457

@@ -95,7 +98,19 @@ while [ $# -gt 0 ]; do
9598
--playwright) DEVBOX_PLAYWRIGHT_ENABLED="yes"; shift ;;
9699
--playwright-ssh-port) DEVBOX_PLAYWRIGHT_SSH_PORT="${2:-}"; shift 2 ;;
97100
--playwright-container) DEVBOX_PLAYWRIGHT_CONTAINER_NAME="${2:-}"; shift 2 ;;
98-
--post-install) POST_INSTALL_TARGET="${2:-}"; shift 2 ;;
101+
--post-install)
102+
if [ "${POST_INSTALL_SET_BY_CLI}" != "yes" ]; then
103+
POST_INSTALL_TARGETS=()
104+
POST_INSTALL_SET_BY_CLI="yes"
105+
fi
106+
IFS=',' read -r -a _post_items <<< "${2:-}"
107+
for _post_item in "${_post_items[@]}"; do
108+
_post_item="${_post_item#"${_post_item%%[![:space:]]*}"}"
109+
_post_item="${_post_item%"${_post_item##*[![:space:]]}"}"
110+
[ -n "${_post_item}" ] && POST_INSTALL_TARGETS+=("${_post_item}")
111+
done
112+
shift 2
113+
;;
99114
--env-file) DEVBOX_ENV_FILE="${2:-}"; shift 2 ;; # already loaded in pre-parse
100115
--recreate) RECREATE="yes"; shift ;;
101116
-h|--help) usage; exit 0 ;;
@@ -107,6 +122,15 @@ while [ $# -gt 0 ]; do
107122
esac
108123
done
109124

125+
if [ "${POST_INSTALL_SET_BY_CLI}" != "yes" ] && [ -n "${POST_INSTALL_TARGET}" ]; then
126+
IFS=',' read -r -a _post_items <<< "${POST_INSTALL_TARGET}"
127+
for _post_item in "${_post_items[@]}"; do
128+
_post_item="${_post_item#"${_post_item%%[![:space:]]*}"}"
129+
_post_item="${_post_item%"${_post_item##*[![:space:]]}"}"
130+
[ -n "${_post_item}" ] && POST_INSTALL_TARGETS+=("${_post_item}")
131+
done
132+
fi
133+
110134
if [ "${DEVBOX_WORKSPACE_LINK}" != "on" ] && [ "${DEVBOX_WORKSPACE_LINK}" != "off" ]; then
111135
echo "Error: --workspace-link must be 'on' or 'off'." >&2
112136
exit 1
@@ -219,7 +243,13 @@ export DEVBOX_USER DEVBOX_PASS DEVBOX_UID DEVBOX_GID DEVBOX_SSH_PORT DOCKER_GID
219243
export DEVBOX_PROJECTS_DIR DEVBOX_PROJECTS_MOUNT DEVBOX_WORKSPACE_LINK DEVBOX_START_DIR DEVBOX_PASSWORDLESS_SUDO DEVBOX_CONTAINER_NAME DEVBOX_HOME_DIR
220244
export DEVBOX_PLAYWRIGHT_SSH_PORT DEVBOX_PLAYWRIGHT_CONTAINER_NAME
221245

222-
POST_INSTALL_SCRIPT="$(resolve_post_install_script "$POST_INSTALL_TARGET")"
246+
POST_INSTALL_SCRIPTS=()
247+
if [ "${#POST_INSTALL_TARGETS[@]}" -gt 0 ]; then
248+
for _post_target in "${POST_INSTALL_TARGETS[@]}"; do
249+
_post_script="$(resolve_post_install_script "$_post_target")"
250+
[ -n "${_post_script}" ] && POST_INSTALL_SCRIPTS+=("${_post_script}")
251+
done
252+
fi
223253

224254
mkdir -p "${DEVBOX_PROJECTS_DIR}"
225255
mkdir -p "${DEVBOX_HOME_DIR}" "${DEVBOX_HOME_DIR}/.ssh"
@@ -275,11 +305,13 @@ if [ "${DEVBOX_PLAYWRIGHT_ENABLED}" = "yes" ]; then
275305
"chown -R '${DEVBOX_USER}' '${DEVBOX_PROJECTS_MOUNT}' '/home/${DEVBOX_USER}' || true"
276306
fi
277307

278-
if [ -n "$POST_INSTALL_SCRIPT" ]; then
279-
run_post_install "${DEVBOX_CONTAINER_NAME}" "$POST_INSTALL_SCRIPT"
280-
if [ "${DEVBOX_PLAYWRIGHT_ENABLED}" = "yes" ]; then
281-
run_post_install "${DEVBOX_PLAYWRIGHT_CONTAINER_NAME}" "$POST_INSTALL_SCRIPT"
282-
fi
308+
if [ "${#POST_INSTALL_SCRIPTS[@]}" -gt 0 ]; then
309+
for _post_script in "${POST_INSTALL_SCRIPTS[@]}"; do
310+
run_post_install "${DEVBOX_CONTAINER_NAME}" "${_post_script}"
311+
if [ "${DEVBOX_PLAYWRIGHT_ENABLED}" = "yes" ]; then
312+
run_post_install "${DEVBOX_PLAYWRIGHT_CONTAINER_NAME}" "${_post_script}"
313+
fi
314+
done
283315
fi
284316

285317
echo
@@ -295,8 +327,11 @@ echo "| Passwordless sudo: ${DEVBOX_PASSWORDLESS_SUDO}"
295327
if [ "${DEVBOX_PLAYWRIGHT_ENABLED}" = "yes" ]; then
296328
echo "| Playwright SSH: ${DEVBOX_PLAYWRIGHT_SSH_PORT}"
297329
fi
298-
if [ -n "$POST_INSTALL_SCRIPT" ]; then
299-
echo "| Post-install: ${POST_INSTALL_SCRIPT}"
330+
if [ "${#POST_INSTALL_SCRIPTS[@]}" -gt 0 ]; then
331+
echo "| Post-install:"
332+
for _post_script in "${POST_INSTALL_SCRIPTS[@]}"; do
333+
echo "| - ${_post_script}"
334+
done
300335
fi
301336
if [ "${DEVBOX_PASS}" = "changeme" ]; then
302337
echo "| Password: changeme (default)."

0 commit comments

Comments
 (0)