-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphp-tool-run
executable file
·74 lines (67 loc) · 2.08 KB
/
php-tool-run
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
#!/bin/bash
# This file is part of mcustiel/docker-php-tools.
#
# docker-php-tools is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# docker-php-tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with mcustiel/docker-php-tools. If not, see <http://www.gnu.org/licenses/>.
DIR=$(pwd)
USER=$(id -u)
GROUP=$(id -g)
COMMAND=""
options=($@)
function fail {
echo $1
exit 1
}
function usage {
echo "php-tool-run [--dpt-dir <directory>] [--dpt-user <user>] [--dpt-group <group>] COMMAND ...ARGS"
echo " --dpt-dir: Working directory for the command to run - Default: \$CWD"
echo " --dpt-user: Runs the command as the given user - Default: \$USER"
echo " --dpt-user: Runs the command as the given group - Default: Users's default group"
echo
exit 0
}
while [ "${#options[@]}" -gt 0 ]; do
case "${options[0]}" in
-h|--help)
usage
;;
--dpt-dir)
DIR=$(realpath ${options[1]})
if [ ! -d $DIR ]; then
fail "Option ${options[0]} requires a path to a directory as an argument."
fi
options=(${options[@]:1})
;;
--dpt-user)
USER=${options[1]}
options=(${options[@]:1})
;;
--dpt-group)
GROUP=${options[1]}
options=(${options[@]:1})
;;
*)
COMMAND="$COMMAND ${options[0]}"
;;
esac
options=(${options[@]:1})
done
echo "RUNNING: '$COMMAND' in directory '$DIR'"
docker run -it --rm \
--volume $DIR:/app \
--volume $SSH_AUTH_SOCK:/ssh-auth.sock \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--env SSH_AUTH_SOCK=/ssh-auth.sock \
--user $USER:$GROUP \
php-tools:php73 $COMMAND