-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp
executable file
·76 lines (60 loc) · 1.92 KB
/
php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
#
# This file is part of PAW (https://github.com/yannoff/p-a-w)
#
# Copyright (c) 2023-present Yann Blacher (Yannoff)
#
# The PAW project is subject to the MIT License use-terms.
# @see https://github.com/yannoff/p-a-w/blob/main/LICENSE
#
image=${PAW_IMAGE}
called=$(basename $0)
version=${called//php/}
[ -z "${version}" ] && version=${PHP_VERSION:-8.3}
[ -z "${image}" ] && image=yannoff/php-fpm
_exec() {
[ -n "${PAW_DEBUG}" ] && echo "$*" >&2
# If stdout is not the terminal,
# suppress carriage returns from output
if [ -p /dev/stdout ] || [ -f /dev/stdout ]
then
"$@" | tr -d "\r"
else
"$@"
fi
}
args=()
if [ "$#" -gt "0" ]
then
# If first arg is an absolute path, mount it
[ "${1:0:1}" = "/" ] && args+=( -v ${1}:${1} )
# If first arg is an option or a php file, assume "php" is implicit
# This allow calling the script in the form: "php -a" or "php foo.php"
if [ "${1#-}" != "$1" ] || grep '<?' "${1}" >/dev/null 2>&1
then
set -- php "$@"
fi
else
# If no command or option specified, open a bash session
set -- bash
fi
# Mount current host directory to container working dir
args+=( -v ${PWD}:/app )
args+=( -w /app )
# Mount user/group accounts as read-only
args+=( -v /etc/group:/etc/group:ro )
args+=( -v /etc/passwd:/etc/passwd:ro )
args+=( -v /etc/shadow:/etc/shadow:ro )
# Mount user's composer home if it exists
[ -d $HOME/.composer ] && args+=( -v $HOME/.composer:/.composer )
# Mount user's ssh directory if it exists
[ -d $HOME/.ssh ] && args+=( -v $HOME/.ssh:$HOME/.ssh )
# Remove container after run
args+=( --rm )
# Run container in interactive mode
args+=( --interactive )
# If STDIN is not a pipe or a regular file, allocate a pseudo TTY
[ -p /dev/stdin ] || [ -f /dev/stdin ] || args+=( --tty )
# Run as standard, low-priviledged user
args+=( -u $(id -u):$(id -g) )
_exec docker run "${args[@]}" ${image}:${version} "$@"