-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmage
executable file
·25 lines (20 loc) · 937 Bytes
/
mage
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
# See: https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself
# Note: you can't refactor this out: its at the top of every script so the scripts can find their includes.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
function log() {
echo "$*" 1>&2
}
function fatal() {
echo "$*" 1>&2
exit 1
}
pushd "$SCRIPT_DIR" 1>/dev/null 2>&1 || fatal "pushd failed: ${SCRIPT_DIR}"
go run mage.go "$@"
exit $?
popd 1>/dev/null 2>&1 || fatal "popd failed: ${SCRIPT_DIR}"