-
Notifications
You must be signed in to change notification settings - Fork 15
/
setenv.sh
64 lines (55 loc) · 1.95 KB
/
setenv.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
#!/usr/bin/env bash
## Usage: $ . ./setenv.sh
##############################################################################
## Subroutines
getHome() {
local source="${BASH_SOURCE[0]}"
while [[ -h "$source" ]]; do
local linked="$(readlink "$source")"
local dir="$( cd -P $(dirname "$source") && cd -P $(dirname "$linked") && pwd )"
source="$dir/$(basename "$linked")"
done
( cd -P "$(dirname "$source")" && pwd )
}
getOS() {
local os
case "$(uname -s)" in
Linux*) os=linux;;
Darwin*) os=mac;;
CYGWIN*) os=cygwin;;
MINGW*) os=mingw;;
*) os=unknown
esac
echo $os
}
getPath() {
local path=""
for i in $(ls -d "$1"*/ 2>/dev/null); do path=$i; done
# ignore trailing slash introduced in for loop
[[ -z "$path" ]] && echo "" || echo "${path::-1}"
}
##############################################################################
## Environment setup
PROG_HOME="$(getHome)"
OS="$(getOS)"
[[ $OS == "unknown" ]] && { echo "Unsuppored OS"; exit 1; }
if [[ $OS == "cygwin" || $OS == "mingw" ]]; then
[[ $OS == "cygwin" ]] && prefix="/cygdrive" || prefix=""
export HOME=$prefix/c/Users/$USER
export GIT_HOME="$(getPath "$prefix/c/opt/Git-2")"
export MONGO_HOME="$(getPath "$prefix/c/opt/mongodb-win32")"
export NODE_HOME="$(getPath "$prefix/c/opt/node-v14")"
export NODE12_HOME="$(getPath "$prefix/c/opt/node-v12")"
export NODE14_HOME="$(getPath "$prefix/c/opt/node-v14")"
export NODE16_HOME="$(getPath "$prefix/c/opt/node-v16")"
else
export MONGO_HOME="$(getPath "/opt/mongodb-win32")"
export NODE_HOME="$(getPath "/opt/node-v14")"
export NODE12_HOME="$(getPath "/opt/node-v12")"
export NODE14_HOME="$(getPath "/opt/node-v14")"
export NODE16_HOME="$(getPath "/opt/node-v16")"
fi
PATH1="$PATH"
[[ -x "$NODE_HOME/node" ]] && PATH1="$PATH1:$NODE_HOME"
[[ -x "$GIT_HOME/bin/git" ]] && PATH1="$PATH1:$GIT_HOME/bin"
export PATH="$PATH1"