|
|
@ -0,0 +1,102 @@ |
|
|
|
#!/bin/sh |
|
|
|
|
|
|
|
set -eu |
|
|
|
|
|
|
|
# sudo mode explicitly requested |
|
|
|
if [ "x${1:-}" = "x-r" ]; then |
|
|
|
USER_NEEDS_SUDO=true |
|
|
|
shift |
|
|
|
else |
|
|
|
USER_NEEDS_SUDO= |
|
|
|
fi |
|
|
|
|
|
|
|
# no docker? pass through |
|
|
|
if [ -z "$(which docker)" ]; then |
|
|
|
exec ${USER_NEEDS_SUDO:+sudo} "$@" |
|
|
|
fi |
|
|
|
|
|
|
|
# identify workspace |
|
|
|
# |
|
|
|
BASE="$(dirname "$0")" |
|
|
|
if [ -s "$BASE/Dockerfile" ]; then |
|
|
|
WS="$(cd "$BASE/.." && pwd -P)" |
|
|
|
elif [ -x "$BASE/bin/sde" ]; then |
|
|
|
WS="$BASE" |
|
|
|
BASE="$BASE/docker" |
|
|
|
else |
|
|
|
echo "$BASE: failed to identify workspace root" >&2 |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
if [ $# -gt 0 ]; then |
|
|
|
|
|
|
|
mode=adhoc |
|
|
|
|
|
|
|
# identify command |
|
|
|
case "$1" in |
|
|
|
sde|*/sde) |
|
|
|
mode=sde |
|
|
|
sde_options= |
|
|
|
shift |
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do |
|
|
|
case "$1" in |
|
|
|
--loop) ;; |
|
|
|
--) shift; break ;; |
|
|
|
|
|
|
|
-*) sde_options="${sde_options:+$sde_options }$1" ;; |
|
|
|
*) break ;; |
|
|
|
esac |
|
|
|
shift |
|
|
|
done |
|
|
|
|
|
|
|
case "${1:-}" in |
|
|
|
build|cleanup|clean|reschedule|defer|reown) |
|
|
|
USER_NEEDS_SUDO=true |
|
|
|
;; |
|
|
|
esac |
|
|
|
|
|
|
|
if [ -n "$sde_options" ]; then |
|
|
|
set -- $sde_options "$@" |
|
|
|
fi |
|
|
|
;; |
|
|
|
*/*) |
|
|
|
if ! expr "$1" : / > /dev/null; then |
|
|
|
cmd="$(realpath $PWD/$1)" |
|
|
|
else |
|
|
|
cmd="$1" |
|
|
|
fi |
|
|
|
|
|
|
|
case "$cmd" in |
|
|
|
"$WS/scripts"/*) |
|
|
|
cmd="./${cmd#$WS/}" |
|
|
|
mode=legacy |
|
|
|
shift |
|
|
|
|
|
|
|
case "${cmd##*/}" in |
|
|
|
Build-Pkg|Build-Target) |
|
|
|
USER_NEEDS_SUDO=true |
|
|
|
;; |
|
|
|
esac |
|
|
|
|
|
|
|
;; |
|
|
|
esac |
|
|
|
;; |
|
|
|
esac |
|
|
|
|
|
|
|
case "$mode" in |
|
|
|
sde) |
|
|
|
set -- "$WS/bin/sde" "$@" |
|
|
|
;; |
|
|
|
legacy) |
|
|
|
cd "$WS" |
|
|
|
set -- "$cmd" "$@" |
|
|
|
;; |
|
|
|
adhoc) |
|
|
|
;; |
|
|
|
esac |
|
|
|
fi |
|
|
|
|
|
|
|
# jump |
|
|
|
export DOCKER_DIR="$BASE" |
|
|
|
exec docker-ubuntu-builder ${USER_NEEDS_SUDO:+-r} "$@" |