Skip to content

Commit 00cd196

Browse files
authored
Added configurable user for shell commands (#785)
* Added configurable user for shell commands * Added double quotes
1 parent b52b5e8 commit 00cd196

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

bin/sail

+24-23
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ fi
141141
# Define environment variables...
142142
export APP_PORT=${APP_PORT:-80}
143143
export APP_SERVICE=${APP_SERVICE:-"laravel.test"}
144+
export APP_USER=${APP_USER:-"sail"}
144145
export DB_PORT=${DB_PORT:-3306}
145146
export WWWUSER=${WWWUSER:-$UID}
146147
export WWWGROUP=${WWWGROUP:-$(id -g)}
@@ -213,7 +214,7 @@ if [ "$1" == "php" ]; then
213214
shift 1
214215

215216
if [ "$EXEC" == "yes" ]; then
216-
ARGS+=(exec -u sail)
217+
ARGS+=(exec -u "$APP_USER")
217218
[ ! -t 0 ] && ARGS+=(-T)
218219
ARGS+=("$APP_SERVICE" "php")
219220
else
@@ -227,7 +228,7 @@ elif [ "$1" == "bin" ]; then
227228
if [ "$EXEC" == "yes" ]; then
228229
CMD=$1
229230
shift 1
230-
ARGS+=(exec -u sail)
231+
ARGS+=(exec -u "$APP_USER")
231232
[ ! -t 0 ] && ARGS+=(-T)
232233
ARGS+=("$APP_SERVICE" ./vendor/bin/"$CMD")
233234
else
@@ -241,7 +242,7 @@ elif [ "$1" == "run" ]; then
241242
if [ "$EXEC" == "yes" ]; then
242243
CMD=$1
243244
shift 1
244-
ARGS+=(exec -u sail)
245+
ARGS+=(exec -u "$APP_USER")
245246
[ ! -t 0 ] && ARGS+=(-T)
246247
ARGS+=("$APP_SERVICE" "$CMD")
247248
else
@@ -253,7 +254,7 @@ elif [ "$1" == "docker-compose" ]; then
253254
shift 1
254255

255256
if [ "$EXEC" == "yes" ]; then
256-
ARGS+=(exec -u sail)
257+
ARGS+=(exec -u "$APP_USER")
257258
[ ! -t 0 ] && ARGS+=(-T)
258259
ARGS+=("$APP_SERVICE" "${DOCKER_COMPOSE[@]}")
259260
else
@@ -265,7 +266,7 @@ elif [ "$1" == "composer" ]; then
265266
shift 1
266267

267268
if [ "$EXEC" == "yes" ]; then
268-
ARGS+=(exec -u sail)
269+
ARGS+=(exec -u "$APP_USER")
269270
[ ! -t 0 ] && ARGS+=(-T)
270271
ARGS+=("$APP_SERVICE" "composer")
271272
else
@@ -277,7 +278,7 @@ elif [ "$1" == "artisan" ] || [ "$1" == "art" ] || [ "$1" == "a" ]; then
277278
shift 1
278279

279280
if [ "$EXEC" == "yes" ]; then
280-
ARGS+=(exec -u sail)
281+
ARGS+=(exec -u "$APP_USER")
281282
[ ! -t 0 ] && ARGS+=(-T)
282283
ARGS+=("$APP_SERVICE" php artisan)
283284
else
@@ -289,7 +290,7 @@ elif [ "$1" == "debug" ]; then
289290
shift 1
290291

291292
if [ "$EXEC" == "yes" ]; then
292-
ARGS+=(exec -u sail -e XDEBUG_TRIGGER=1)
293+
ARGS+=(exec -u "$APP_USER" -e XDEBUG_TRIGGER=1)
293294
[ ! -t 0 ] && ARGS+=(-T)
294295
ARGS+=("$APP_SERVICE" php artisan)
295296
else
@@ -301,7 +302,7 @@ elif [ "$1" == "test" ]; then
301302
shift 1
302303

303304
if [ "$EXEC" == "yes" ]; then
304-
ARGS+=(exec -u sail)
305+
ARGS+=(exec -u "$APP_USER")
305306
[ ! -t 0 ] && ARGS+=(-T)
306307
ARGS+=("$APP_SERVICE" php artisan test)
307308
else
@@ -313,7 +314,7 @@ elif [ "$1" == "phpunit" ]; then
313314
shift 1
314315

315316
if [ "$EXEC" == "yes" ]; then
316-
ARGS+=(exec -u sail)
317+
ARGS+=(exec -u "$APP_USER")
317318
[ ! -t 0 ] && ARGS+=(-T)
318319
ARGS+=("$APP_SERVICE" php vendor/bin/phpunit)
319320
else
@@ -325,7 +326,7 @@ elif [ "$1" == "pest" ]; then
325326
shift 1
326327

327328
if [ "$EXEC" == "yes" ]; then
328-
ARGS+=(exec -u sail)
329+
ARGS+=(exec -u "$APP_USER")
329330
[ ! -t 0 ] && ARGS+=(-T)
330331
ARGS+=("$APP_SERVICE" php vendor/bin/pest)
331332
else
@@ -337,7 +338,7 @@ elif [ "$1" == "pint" ]; then
337338
shift 1
338339

339340
if [ "$EXEC" == "yes" ]; then
340-
ARGS+=(exec -u sail)
341+
ARGS+=(exec -u "$APP_USER")
341342
[ ! -t 0 ] && ARGS+=(-T)
342343
ARGS+=("$APP_SERVICE" php vendor/bin/pint)
343344
else
@@ -349,7 +350,7 @@ elif [ "$1" == "dusk" ]; then
349350
shift 1
350351

351352
if [ "$EXEC" == "yes" ]; then
352-
ARGS+=(exec -u sail)
353+
ARGS+=(exec -u "$APP_USER")
353354
[ ! -t 0 ] && ARGS+=(-T)
354355
ARGS+=(-e "APP_URL=http://${APP_SERVICE}")
355356
ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub")
@@ -363,7 +364,7 @@ elif [ "$1" == "dusk:fails" ]; then
363364
shift 1
364365

365366
if [ "$EXEC" == "yes" ]; then
366-
ARGS+=(exec -u sail)
367+
ARGS+=(exec -u "$APP_USER")
367368
[ ! -t 0 ] && ARGS+=(-T)
368369
ARGS+=(-e "APP_URL=http://${APP_SERVICE}")
369370
ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub")
@@ -377,7 +378,7 @@ elif [ "$1" == "tinker" ]; then
377378
shift 1
378379

379380
if [ "$EXEC" == "yes" ]; then
380-
ARGS+=(exec -u sail)
381+
ARGS+=(exec -u "$APP_USER")
381382
[ ! -t 0 ] && ARGS+=(-T)
382383
ARGS+=("$APP_SERVICE" php artisan tinker)
383384
else
@@ -389,7 +390,7 @@ elif [ "$1" == "node" ]; then
389390
shift 1
390391

391392
if [ "$EXEC" == "yes" ]; then
392-
ARGS+=(exec -u sail)
393+
ARGS+=(exec -u "$APP_USER")
393394
[ ! -t 0 ] && ARGS+=(-T)
394395
ARGS+=("$APP_SERVICE" node)
395396
else
@@ -401,7 +402,7 @@ elif [ "$1" == "npm" ]; then
401402
shift 1
402403

403404
if [ "$EXEC" == "yes" ]; then
404-
ARGS+=(exec -u sail)
405+
ARGS+=(exec -u "$APP_USER")
405406
[ ! -t 0 ] && ARGS+=(-T)
406407
ARGS+=("$APP_SERVICE" npm)
407408
else
@@ -413,7 +414,7 @@ elif [ "$1" == "npx" ]; then
413414
shift 1
414415

415416
if [ "$EXEC" == "yes" ]; then
416-
ARGS+=(exec -u sail)
417+
ARGS+=(exec -u "$APP_USER")
417418
[ ! -t 0 ] && ARGS+=(-T)
418419
ARGS+=("$APP_SERVICE" npx)
419420
else
@@ -425,7 +426,7 @@ elif [ "$1" == "pnpm" ]; then
425426
shift 1
426427

427428
if [ "$EXEC" == "yes" ]; then
428-
ARGS+=(exec -u sail)
429+
ARGS+=(exec -u "$APP_USER")
429430
[ ! -t 0 ] && ARGS+=(-T)
430431
ARGS+=("$APP_SERVICE" pnpm)
431432
else
@@ -437,7 +438,7 @@ elif [ "$1" == "pnpx" ]; then
437438
shift 1
438439

439440
if [ "$EXEC" == "yes" ]; then
440-
ARGS+=(exec -u sail)
441+
ARGS+=(exec -u "$APP_USER")
441442
[ ! -t 0 ] && ARGS+=(-T)
442443
ARGS+=("$APP_SERVICE" pnpx)
443444
else
@@ -449,7 +450,7 @@ elif [ "$1" == "yarn" ]; then
449450
shift 1
450451

451452
if [ "$EXEC" == "yes" ]; then
452-
ARGS+=(exec -u sail)
453+
ARGS+=(exec -u "$APP_USER")
453454
[ ! -t 0 ] && ARGS+=(-T)
454455
ARGS+=("$APP_SERVICE" yarn)
455456
else
@@ -461,7 +462,7 @@ elif [ "$1" == "bun" ]; then
461462
shift 1
462463

463464
if [ "$EXEC" == "yes" ]; then
464-
ARGS+=(exec -u sail)
465+
ARGS+=(exec -u "$APP_USER")
465466
[ ! -t 0 ] && ARGS+=(-T)
466467
ARGS+=("$APP_SERVICE" bun)
467468
else
@@ -473,7 +474,7 @@ elif [ "$1" == "bunx" ]; then
473474
shift 1
474475

475476
if [ "$EXEC" == "yes" ]; then
476-
ARGS+=(exec -u sail)
477+
ARGS+=(exec -u "$APP_USER")
477478
[ ! -t 0 ] && ARGS+=(-T)
478479
ARGS+=("$APP_SERVICE" bunx)
479480
else
@@ -524,7 +525,7 @@ elif [ "$1" == "shell" ] || [ "$1" == "bash" ]; then
524525
shift 1
525526

526527
if [ "$EXEC" == "yes" ]; then
527-
ARGS+=(exec -u sail)
528+
ARGS+=(exec -u "$APP_USER")
528529
[ ! -t 0 ] && ARGS+=(-T)
529530
ARGS+=("$APP_SERVICE" bash)
530531
else

0 commit comments

Comments
 (0)