-
Notifications
You must be signed in to change notification settings - Fork 0
/
logicmoo_env.sh
executable file
·167 lines (135 loc) · 4.41 KB
/
logicmoo_env.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
function MAINTAINER {
/bin/true
}
export BIN_CLASS_DIR=~prologmud_server/classes
export CLASSPATH="$BIN_CLASS_DIR:/usr/share/java/*"
ECHO=MAINTAINER
export SWI_TAG=e68098ba2b38d7d9597def1b4fc0a8cef1ed43cb
if [[ "${1}" == "-q" ]] ;then
ECHO=MAINTAINER
elif [[ "${1}" == "-v" ]] ;then
ECHO=echo
fi
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
munge () {
local value="${1}"
if ! echo "$value" | grep -Eq "(^|:)$2($|:)" ; then
if [ "$3" = "after" ] ; then
value="$value:$2"
else
value="$2:$value"
fi
fi
echo "$value"
}
pathmunge () {
PATH=$(munge "$PATH" $1 $2)
}
if [[ -f /usr/local/lib/swipl/lib/x86_64-linux/libswipl.so ]]; then
export LD_PRELOAD=/usr/local/lib/swipl/lib/x86_64-linux/libswipl.so
fi
export -f pathmunge
unset LOGICMOO_WS
export LOGICMOO_WS=""
if [[ -z "${LOGICMOO_WS}" ]]; then
WS_MAYBE="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)"
if [[ -d "${WS_MAYBE}/packs_sys" ]]; then
export LOGICMOO_WS=$WS_MAYBE
fi
if [[ -z "${LOGICMOO_WS}" ]]; then
WS_MAYBE=`find . -mindepth 1 -maxdepth 10 -type d -name logicmoo_workspace -printf "%T@\t%p\0" | sort -z -n | cut -z -f2- | tail -z -n1 | xargs -0 realpath`
if [[ -d "${WS_MAYBE}/packs_sys" ]]; then
export LOGICMOO_WS=$WS_MAYBE
fi
fi
if [[ -z "${LOGICMOO_WS}" ]]; then
WS_MAYBE="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)"
if [[ -d "${WS_MAYBE}/packs_sys" ]]; then
export LOGICMOO_WS=$WS_MAYBE
fi
fi
if [[ -z "${LOGICMOO_WS}" ]]; then
WS_MAYBE=/opt/logicmoo_workspace
if [[ -d "${WS_MAYBE}/packs_sys" ]]; then
export LOGICMOO_WS=$WS_MAYBE
fi
fi
LOGICMOO_WS=$(echo $LOGICMOO_WS | sed -e 's|@2||g')
$ECHO "#* Set logicmoo workspace"
$ECHO "#* LOGICMOO_WS=$LOGICMOO_WS"
fi
if [[ ":$PATH:" == *"$LOGICMOO_WS/bin:"* ]]; then
$ECHO "#* "
if [[ -z "$1" ]]; then
$ECHO "#* GOOD: Logicmoo [$LOGICMOO_WS/bin] found in your PATH"
fi
else
# PATH="/root/.cpm/bin:/opt/logicmoo_workspace/packs_xtra/logicmoo_packages/prolog/pakcs/bin:$PATH"
export PATH="$LOGICMOO_WS/bin:$PATH"
$ECHO "#* PATH=$PATH"
fi
pathmunge $LOGICMOO_WS/packs_lib/sparqlprog/bin after
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
set -o ignoreeof
fi
if command -v nmap &> /dev/null
then
# Declare an array of string with type
declare -a StringArray=("10.0.0.78" "172.17.0.1" "127.0.0.1" )
for val in ${StringArray[@]}; do
if [ -n "$DISPLAY" ] || [ -z "$DISPLAY" ]; then
NMAP=$(nmap -p 6000 $val)
if (echo "$NMAP" | grep "Host is up" && echo "$NMAP" | grep "open") > /dev/null; then
export DISPLAY=$val:0.0
fi
fi
done
fi
$ECHO "#* DISPLAY=$DISPLAY"
if [[ -z "${LIBJVM}" ]]; then
$ECHO "Finding/Setting LIBJVM..."
if ! [[ -z "${JAVA_HOME}" ]]; then
export LIBJVM=$(find $JAVA_HOME -name libjvm.so -printf "%h\n" | head -n 1)
elif [ -d /usr/lib/jvm ]; then
export LIBJVM=$(find /usr/lib/jvm -name libjvm.so -printf "%h\n" | head -n 1)
fi
fi
$ECHO "#* LIBJVM=$LIBJVM"
if ! [[ -z "${LIBJVM}" ]]; then
if ! [ ":$LD_LIBRARY_PATH:" == ":$LIBJVM"* ]; then
$ECHO "Finding/Setting LD_LIBRARY_PATH..."
if [[ -z "${LD_LIBRARY_PATH}" ]]; then
export LD_LIBRARY_PATH=$LIBJVM:/usr/local/lib
else
export LD_LIBRARY_PATH=$LIBJVM:$LD_LIBRARY_PATH
fi
export BOOST_ROOT=$LOGICMOO_WS/taupl/boost_1_67_0
#export LD_LIBRARY_PATH=/usr/lib
#export LD_LIBRARY_PATH=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server:.:$BOOST_ROOT/lib:$LD_LIBRARY_PATH
fi
fi
$ECHO "#* LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
$ECHO "#* PATH=$PATH"
if [[ ! -v SSH_TTY ]]; then
/bin/true
elif [[ -z "$SSH_TTY" ]]; then
/bin/true
elif [[ -w "$SSH_TTY" ]]; then
/bin/true
else
$ECHO "#* MAYBE: need to chmod o+rw $SSH_TTY"
chmod o+rw $SSH_TTY
fi
if [[ -d ~/.local/share/swi-prolog/pack/ ]]; then
$ECHO "#* Found ~/.local/share/swi-prolog/pack"
else
echo "#* Attempting: ln -s $LOGICMOO_WS/prologmud_server/ ~/.local/share/swi-prolog/pack"
mkdir -p ~/.local/share/swi-prolog
ln -s $LOGICMOO_WS/prologmud_server/.local/share/swi-prolog/pack/ ~/.local/share/swi-prolog/pack
ls ~/.local/share/swi-prolog/pack/
fi
export LIBJVM
export LD_LIBRARY_PATH
export PATH
(eval `swipl --dump-runtime-variables` ) 2>/dev/null