-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsource.sh
executable file
·84 lines (74 loc) · 2.44 KB
/
source.sh
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
77
78
79
80
81
82
83
84
# ***************************************************************
# * This script adds Ignis to the current path.
# * It assumes that Ignis is either compiled within a
# * a subdirectory named 'build' or within a subdirectory named 'build/Release'.
# ***************************************************************
# See https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
sourced=0
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
elif [ -n "$KSH_VERSION" ]; then
[ "$(cd -- "$(dirname -- "$0")" && pwd -P)/$(basename -- "$0")" != "$(cd -- "$(dirname -- "${.sh.file}")" && pwd -P)/$(basename -- "${.sh.file}")" ] && sourced=1
elif [ -n "$BASH_VERSION" ]; then
(return 0 2>/dev/null) && sourced=1
else # All other shells: examine $0 for known shell binary filenames.
# Detects `sh` and `dash`; add additional shell filenames as needed.
case ${0##*/} in sh|-sh|dash|-dash) sourced=1;; esac
fi
if [ "${sourced}" = "0" ]; then
echo "The source.sh script must be sourced, not executed. In other words, run"
echo "$ source source.sh"
exit 0
fi
# Acquire parameters
quiet=false
no_completion=false
while [ -n "$1" ]; do
case "$1" in
--no-completion)
no_completion=true
shift
;;
-q)
quiet=true
shift
;;
--)
shift
break
;;
*) echo "$1 is not an option" ;;
esac
shift
done
# Get directories
if [ "$BASH_VERSION" ]; then
IGNIS_DIR=$(dirname "$BASH_SOURCE")
export IGNIS_DIR=$(builtin cd "$IGNIS_DIR"; builtin pwd)
elif [ "$ZSH_VERSION" ]; then
export IGNIS_DIR=$(dirname "$0:A")
fi
if [ -d "$IGNIS_DIR/build/Release" ]; then
BUILD_DIR="$IGNIS_DIR/build/Release"
else
BUILD_DIR="$IGNIS_DIR/build/"
fi
export PATH="$BUILD_DIR/bin:$PATH"
export PATH="$BUILD_DIR/lib:$PATH"
export PYTHONPATH="$BUILD_DIR/api:$PYTHONPATH"
export IGNIS_SCRIPT_DIR="$IGNIS_DIR/scripts"
if [ "$no_completion" = false ]; then
# Include completion scripts if available
if [ -f "${IGNIS_DIR}/scripts/bash/ignis-completion.bash" ]; then
source "${IGNIS_DIR}/scripts/bash/ignis-completion.bash"
fi
fi
if [ "$quiet" = false ]; then
echo $(igcli --version)
echo " - Root: $IGNIS_DIR"
echo " - Build: $BUILD_DIR"
echo " - Bin: $BUILD_DIR/bin"
echo " - Lib: $BUILD_DIR/lib"
echo " - Python: $BUILD_DIR/api"
echo " - Scripts: $IGNIS_SCRIPT_DIR"
fi