debian-here/debian-here.sh

30 lines
635 B
Bash
Executable File

#!/usr/bin/env bash
set -eu
set -o pipefail
set -o errtrace
shopt -s expand_aliases
[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" || :
pushd() { command pushd "$@" > /dev/null; }
popd() { command popd "$@" > /dev/null; }
here="$(pwd)"
script_dir="$(dirname "$(readlink -f "$0")")"
IMAGE="${IMAGE:-debian-here}"
run() {
if [[ "$(docker images -q ${IMAGE} 2> /dev/null)" == "" ]];then
pushd "$script_dir"
docker build -t "$IMAGE" .
popd
fi
mount_point="/mnt/$(basename "$here")"
docker run --rm -ti -v "$here":"$mount_point" -w "$mount_point" ${ARGS:-} "$IMAGE" "$@"
}
run "$@"