forked from opencog/ocpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
octool-wip
executable file
·696 lines (636 loc) · 22.5 KB
/
octool-wip
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
#!/bin/bash
#
## @file octool
## @copyright OpenCog Foundation 2016
## @section DESCRIPTION A script to download, build, test, install and
## configure OpenCog projects
# trap errors
set -e
SELF_NAME=$(basename $0)
PROCESSORS=$(grep "^processor" /proc/cpuinfo | wc -l)
MAKE_JOBS=$(($PROCESSORS+0))
VERBOSE="-v"
QUIET="-qq"
REPOSITORIES=""
PACKAGES_FETCH="
python-pip \
git \
wget \
"
PACKAGES_BUILD="
build-essential \
cmake \
cxxtest \
rlwrap \
guile-2.0-dev \
libiberty-dev \
libicu-dev \
libbz2-dev \
cython \
python-dev \
python-zmq \
python-simplejson \
libboost-date-time-dev \
libboost-filesystem-dev \
libboost-math-dev \
libboost-program-options-dev \
libboost-regex-dev \
libboost-serialization-dev \
libboost-thread-dev \
libboost-system-dev \
libboost-random-dev \
libjson-spirit-dev \
libzmq3-dev \
libtbb-dev \
binutils-dev \
unixodbc-dev \
libpq-dev\
uuid-dev \
libprotoc-dev \
protobuf-compiler \
libsdl-gfx1.2-dev \
libssl-dev \
tcl-dev \
tcsh \
libfreetype6-dev \
libatlas-base-dev \
gfortran \
libgearman-dev \
ros-indigo-octomap \
ccache \
libgsasl7 \
libldap2-dev \
krb5-multidev \
"
PACKAGES_RUNTIME="
unixodbc \
odbc-postgresql \
postgresql-client \
gearman \
"
# OpenCog's cmake configured projects. These are mainly C++ projects.
OPENCOG_CMAKE_PROJECTS=(cogutil atomspace opencog moses ros-behavior-scripting)
message() {
printf "\e[1;34m[$SELF_NAME] $MESSAGE\e[0m \n"
}
is_x68_64() {
ARCH=$(uname -m);
if [ "$ARCH" == "x86_64" ]; then
return 0
else
return 1
fi
}
add_stack_repository() {
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 575159689BEFB442
echo 'deb http://download.fpcomplete.com/ubuntu trusty main'|sudo tee /etc/apt/sources.list.d/fpco.list
}
add_repositories() {
MESSAGE="Adding software repositories..." ; message
for REPO in $REPOSITORIES ; do
sudo apt-add-repository -y $REPO
done
# Ros repository for opencog/opencog repo
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu trusty main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B01FA116
sudo apt-get $QUIET --assume-yes update
}
# Install Python Packages
install_opencog_python_packages(){
MESSAGE="Installing python packages...." ; message
cd /tmp
# cleaning up remnants from previous install failures, if any.
rm -f requirements.txt*
wget https://raw.githubusercontent.com/opencog/opencog/master/opencog/python/requirements.txt
# scipy, numpy & matplotlib if installed using python-pip will take a
# long time as they have to be built before being installed. And the
# arrifacts of the build occupies a lot of space blotting the docker image.
# Thus instead a system instllation is made.
sudo pip install -U $(awk '!/scipy/&&!/numpy/&&!/matplotlib/' requirements.txt)
sudo apt-get install -y python-matplotlib python-numpy python-scipy
rm -f requirements.txt*
cd $CURRENT_DIR
}
# Install Haskell Dependencies
install_haskell_dependencies(){
if ! is_x68_64; then
MESSAGE="Installing stack for haskell "; message
# Just in case curl isn't installed
sudo apt-get install -y curl
cd /tmp
rm -rf stack*
wget $(curl -s https://api.github.com/repos/commercialhaskell/stack/releases/latest | awk '/browser_download_url/&&/i386-linux.tar.gz/' | head -n 1 | cut -d '"' -f 4)
tar xfz stack*i386-linux.tar.gz
rm stack*i386-linux.tar.gz
mv stack* stack
chmod 755 stack
sudo mv stack /usr/bin/stack
rm -f stack*
cd $CURRENT_DIR
else
MESSAGE="Installing haskell dependencies in user space...." ; message
# Install stack.
add_stack_repository
sudo apt-get update && sudo apt-get $QUIET -y install stack
fi
cd /tmp
rm -rf patchelf*
wget "https://nixos.org/releases/patchelf/patchelf-0.9/patchelf-0.9.tar.bz2"
tar -jxf patchelf-0.9.tar.bz2
rm patchelf-0.9.tar.bz2
cd patchelf-0.9
./configure
sudo make install
cd /tmp
rm -rf patchelf-0.9
cd $CURRENT_DIR
# Notes
# 1. Stack setup must me run in user space:
# "stack setup" looks for proper ghc version in the system according to
# the information provided by stack.yaml. If it is not installed, it
# attempts to install proper ghc version on user space (~/.stack/...).
# Because of that, it must not be run as root.
# 2. Difference b/n .cabal and stack.yaml:
# The .cabal file contains package metadata, in this case
# "opencog-atomspace.cabal" contains information of the opencog-atomspace
# package (autor, license, dependencies, etc.). The stack.yaml file
# contains configuration options for the stack building tool, we use it
# to set the proper "long term support" snapshot that we are using,
# which determines the proper ghc version to use, etc. In this case, it
# doesn't make sense to require the .cabal file, because we are not
# using that information to build the hscolour package, but it looks
# like stack always looks for a .cabal file when building, even though,
# in this case, it doesn't use it.
if [ "$EUID" -ne 0 ] ; then
cd /tmp
wget https://raw.githubusercontent.com/opencog/atomspace/master/opencog/haskell/stack.yaml
wget https://raw.githubusercontent.com/opencog/atomspace/master/opencog/haskell/opencog-atomspace.cabal
stack --allow-different-user setup
# hscolour is necessary for haddock documentation.
stack --allow-different-user build hscolour --copy-bins
rm stack.yaml opencog-atomspace.cabal
cd $CURRENT_DIR
else
printf "Please run without sudo. Stack need to be run in non-root user space."
exit 1
fi
}
# Checks if the given argument is a name one of opencog's c++ projects.
#
# $1 = project name
is_opencog_cmake_project() {
for i in "${OPENCOG_CMAKE_PROJECTS[@]}" ; do
if [ "$i" == "$1" ] ; then
return 0
fi
done
return 1
}
# Checks if the given argument is a path to the root of one of opencog's c++
# projects.
#
# $1 = path to a directory
is_opencog_cmake_project_root() {
local DIR_NAME=${1##*/}
local DIR_NAME=${DIR_NAME%-master}
for i in "${OPENCOG_CMAKE_PROJECTS[@]}" ; do
if [ "$i" == "$DIR_NAME" ] &&
([ -d "$1/opencog" ] || [ -d "$1/moses" ]); then
return 0
fi
done
return 1
}
# Checks if the $PWD is a part of a git repo or the tar extract of OpenCog's
# cmake configured source codes from github.
set_source_and_build_dir() {
# Set source directory path
if is_opencog_cmake_project_root $PWD ; then
SOURCE_DIR=$PWD
MESSAGE="Source Directory is set to $SOURCE_DIR" ; message
elif [ "$(git rev-parse --is-inside-work-tree)" == true ] ; then
local GIT_ROOT_DIR=$(git rev-parse --show-toplevel)
if is_opencog_cmake_project_root $GIT_ROOT_DIR ; then
SOURCE_DIR=$GIT_ROOT_DIR
# IS_GIT_WORKTREE is used to differentiate git version controled
# directories from tar-balled download of source.
IS_GIT_WORKTREE="yes"
MESSAGE="Source Directory is set to $SOURCE_DIR" ; message
fi
fi
# Check if the SOURCE_DIR is set.
if [ -z "$SOURCE_DIR" ]; then
MESSAGE="Is not yet known as an OpenCog project" ; message
exit 1
fi
# Set build directory path
if [ -d $SOURCE_DIR/build ]; then
BUILD_DIR=$SOURCE_DIR/build
MESSAGE="Build Directory is set to $SOURCE_DIR/build" ; message
else
mkdir $SOURCE_DIR/build
BUILD_DIR=$SOURCE_DIR/build
MESSAGE="Build Directory is set to $SOURCE_DIR/build" ; message
fi
}
# Build function for opencog, atomspace, moses & cogutil repos
build_source() {
set_source_and_build_dir
if [ -a $BUILD_DIR/CMakeCache.txt ]; then
rm $BUILD_DIR/CMakeCache.txt
MESSAGE="Removed cmake cache file: rm $BUILD_DIR/CMakeCache.txt" ; message
fi
#stackoverflow.com/questions/20610255/how-to-tell-cmake-where-to-put-build-files
MESSAGE="cmake -B$BUILD_DIR -H$SOURCE_DIR" ; message
cmake -B$BUILD_DIR -H$SOURCE_DIR
MESSAGE="make -C $BUILD_DIR -j$MAKE_JOBS" ; message
make -C $BUILD_DIR -j$MAKE_JOBS
MESSAGE="Finished building source" ; message
}
# Build examples function for opencog, atomspace, moses & cogutil repos
build_examples() {
set_source_and_build_dir
if [ -a $BUILD_DIR/CMakeCache.txt ]; then
rm $BUILD_DIR/CMakeCache.txt
MESSAGE="Removed cmake cache file: rm $BUILD_DIR/CMakeCache.txt" ; message
fi
MESSAGE="cmake -B$BUILD_DIR -H$SOURCE_DIR" ; message
#stackoverflow.com/questions/20610255/how-to-tell-cmake-where-to-put-build-files
cmake -B$BUILD_DIR -H$SOURCE_DIR
MESSAGE="make -C $BUILD_DIR -j$MAKE_JOBS examples" ; message
make -C $BUILD_DIR -j$MAKE_JOBS examples
MESSAGE="Finished building examples" ; message
}
# Build tests function for opencog, atomspace, moses & cogutil repos
build_tests() {
set_source_and_build_dir
if [ -a $BUILD_DIR/CMakeCache.txt ]; then
rm $BUILD_DIR/CMakeCache.txt
MESSAGE="Removed cmake cache file: rm $BUILD_DIR/CMakeCache.txt" ; message
fi
MESSAGE="cmake -B$BUILD_DIR -H$SOURCE_DIR" ; message
#stackoverflow.com/questions/20610255/how-to-tell-cmake-where-to-put-build-files
cmake -B$BUILD_DIR -H$SOURCE_DIR
MESSAGE="make -C $BUILD_DIR -j$MAKE_JOBS tests" ; message
make -C $BUILD_DIR -j$MAKE_JOBS tests
MESSAGE="Finished building tests" ; message
}
# Run tests function for opencog, atomspace, moses & cogutil repos
run_tests() {
#check if gearman service is running, start it if not
if (( $(ps -ef | grep -v grep | grep gearman-job-server | wc -l) > 0 ))
# TODO: This should be done in cmake
then
MESSAGE="gearman-job-server is running!!!";message
else
sudo /etc/init.d/gearman-job-server start
fi
set_source_and_build_dir
if [ -a $BUILD_DIR/CMakeCache.txt ]; then
rm $BUILD_DIR/CMakeCache.txt
MESSAGE="Removed cmake cache file: rm $BUILD_DIR/CMakeCache.txt" ; message
fi
MESSAGE="cmake -B$BUILD_DIR -H$SOURCE_DIR" ; message
#stackoverflow.com/questions/20610255/how-to-tell-cmake-where-to-put-build-files
cmake -B$BUILD_DIR -H$SOURCE_DIR
MESSAGE="make -C $BUILD_DIR -j$MAKE_JOBS test ARGS=-j$MAKE_JOBS" ; message
make -C $BUILD_DIR -j$MAKE_JOBS test ARGS=-j$MAKE_JOBS
MESSAGE="Finished building & running tests" ; message
}
# Install build job artifacts
install_build() {
set_source_and_build_dir
MESSAGE="Starting installation" ; message
cd $BUILD_DIR
sudo make install
sudo ldconfig
cd $CURRENT_DIR
MESSAGE="Finished installation" ; message
}
# Builds and installs the project, with the name of the given argument, if
# it is on of OpenCog's c++ projects.
#
# $1 = project name
install_opencog_cmake_project() {
if is_opencog_cmake_project "$1"; then
MESSAGE="Installing $1 ...." ; message
cd /tmp/
# cleaning up remnants from previous install failures, if any.
rm -rf master.tar.gz* "$1-master"
wget https://github.com/opencog/$1/archive/master.tar.gz
tar -xvf master.tar.gz
cd "$1-master/"
build_source
install_build
cd /tmp/
rm -rf master.tar.gz "$1-master"
cd $CURRENT_DIR
else
MESSAGE="Is not yet known as an OpenCog project" ; message
fi
}
# Install Link-Grammar
install_link_grammar(){
MESSAGE="Installing Link-Grammar...." ; message
cd /tmp/
# cleaning up remnants from previous install failures, if any.
rm -rf link-grammar-5.*/
wget -r --no-parent -nH --cut-dirs=2 http://www.abisource.com/downloads/link-grammar/current/
tar -zxf current/link-grammar-5*.tar.gz
rm -r current
cd link-grammar-5.*/
mkdir build
cd build
../configure
make -j$(nproc)
sudo make install
sudo ldconfig
cd /tmp/
rm -rf link-grammar-5.*/
cd $CURRENT_DIR
}
# Installs cpprest that is needed by pattern-miner
# https://github.com/Microsoft/cpprestsdk/wiki/How-to-build-for-Linux
# TODO: Remove this when a move is made to Ubuntu >= 15.10
install_cpprest(){
MESSAGE="Installing cpprest...." ; message
cd /tmp/
# cleaning up remnants from previous install failures, if any.
rm -rf master.tar.gz* cpprestsdk-master
wget https://github.com/Microsoft/cpprestsdk/archive/master.tar.gz
tar -xvf master.tar.gz
cd cpprestsdk-master/Release
mkdir build.release
cd build.release
CXX=g++-4.8 cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
sudo make install
sudo ldconfig
cd /tmp/
rm -rf master.tar.gz* cpprestsdk-master
cd $CURRENT_DIR
}
# Install system dependencies
install_dependencies() {
MESSAGE="Installing OpenCog build dependencies...." ; message
if ! sudo apt-get $QUIET --no-upgrade --assume-yes install $PACKAGES_BUILD $PACKAGES_RUNTIME $PACKAGES_FETCH; then
# commented out the message b/c it is displayed on ctrl + c
# MESSAGE="Please enable 'universe' repositories and re-run this script." ; message
exit 1
fi
install_cpprest
}
# Updates a git source directory if it is one of the opencog cmake projects.
update_source() {
set_source_and_build_dir
if [ "$IS_GIT_WORKTREE" == "yes" ] ; then
cd $SOURCE_DIR
REPO="$(git remote -v | head -1 | cut -d "/" -f 2 | cut -d "." -f 1)"
INITIAL_BRANCH="$(git describe --contains --all HEAD)"
MESSAGE="Updating $REPO source at $SOURCE_DIR..." ; message
git stash
git checkout master
git pull upstream master
git checkout $INITIAL_BRANCH
cd -
fi
}
# This is for fast updating the octool behavior in docker images instead of
# waiting for rebuilding the docker images, as the system dependencies rarely
# change.
# TODO: make it path/symlink independent
update_octool() {
if [ "${BASH_SOURCE[0]}" == "/tmp/octool" ] &&
wget -q --spider https://github.com/opencog/ocpkg/blob/master/octool
then
MESSAGE="Updating octool ...." ; message
sudo rm /tmp/octool
wget -pO /tmp/octool \
https://raw.githubusercontent.com/opencog/ocpkg/master/octool
fi
}
# This is used for setting the file that is used for storing commit sha
#
# $1 = project name
set_opencog_setup_file() {
# Don't set config file if the effective uid is root.
# TODO: Figure out where is the linux file structure appropriate directory
# to keep the config files for all users. And add the option to store
# in that directory.
if [ "$EUID" -eq 0 ] ; then
MESSAGE="Config directory isn't created as root user ...." ; message
exit 1
fi
# Check if it an opencog cmake project
if ! is_opencog_cmake_project "$1" ; then
MESSAGE="$1 is not yet known as an OpenCog project" ; message
exit 1
fi
# Set the config directory
local CONFIG_DIR="$HOME/.config/opencog"
CONFIG_FILE="$CONFIG_DIR/$1"
if [ -a "$CONFIG_FILE" ] ; then
MESSAGE="Config file being used is $CONFIG_FILE" ; message
else
mkdir -p "$CONFIG_DIR"
touch "$CONFIG_FILE"
MESSAGE="Config file being used is $CONFIG_FILE" ; message
fi
}
# This is used for update install one of opencog's c++ projects, provided
# the given argument is a project name for one of opencog's c++ projects.
# NOTE: github has a limit on the number on unauthenticated hourly api calls.
#
# $1 = project name
update_cmake_project() {
if is_opencog_cmake_project "$1" ; then
local CURRENT_COMMIT_SHA=$(curl \
https://api.github.com/repos/opencog/$1/git/refs/heads/master \
| grep https://api.github.com/repos/opencog/$1/git/commits \
| cut -d "/" -f 9)
else
MESSAGE="$1 is not yet known as an OpenCog project" ; message
exit 1
fi
# Check if update is needed and then update
set_opencog_setup_file "$1"
INSTALLED_COMMIT_SHA=$(cat "$CONFIG_FILE")
if [ "$CURRENT_COMMIT_SHA" == "$INSTALLED_COMMIT_SHA" ] ; then
MESSAGE="$1 installation is up-to-date" ; message
else
MESSAGE="Updating $1 installation" ; message
install_opencog_cmake_project "$1"
echo "$CURRENT_COMMIT_SHA" > "$CONFIG_FILE"
fi
}
run_cogserver() {
CWD=$PWD
if [ "$OPENCOG_SOURCE_DIR" != "" ] ; then
BRANCH_DIR="$OPENCOG_SOURCE_DIR"
if [[ $# == 0 ]]; then # No argument
BUILD_DIR_NAME=build
elif [[ $# == 1 ]]; then # One argument
BUILD_DIR_NAME="$1"
else # More than one command line arguments
echo "Usage: $0 [BUILD_DIR_NAME=build]"
exit 1
fi
BUILD_DIR="${BRANCH_DIR}/${BUILD_DIR_NAME}"
cd $BUILD_DIR
"./opencog/cogserver/server/cogserver" \
-c "${BRANCH_DIR}/lib/development.conf"
else
echo "OPENCOG_SOURCE_DIR environment variable is not set."
fi
cd $CWD
}
ci_help() {
printf "Usage: %s %s [OPTIONS] \n\n" $SELF_NAME $COMMAND_MODE_CHOSEN
printf "Options: \n"
printf " -r Add software repositories \n"
printf " -d Install base/system build dependencies \n"
printf " -p Install python build dependencies \n"
printf " -s Install haskell build dependencies in user space \n"
printf " -i Install build-job artifacts \n"
printf " -c Install Cogutil \n"
printf " -a Install Atomspace \n"
printf " -l Install Link Grammar \n"
printf " -m Install MOSES \n"
printf " -b Build source code in git worktree found @ %s \n" $PWD
printf " -e Build examples in git worktree found @ %s \n" $PWD
printf " -t Run tests of source code in git worktree found @ %s \n" $PWD
printf " -j [jobs] override number of auto-detected make jobs \n"
printf " -v Verbose output for 'apt-get' commands \n"
printf " -h This help message \n"
}
# Help
octool_help() {
printf "Usage: %s [ -h | --help ] <COMMAND> [OPTIONS] \n\n" $SELF_NAME
printf "Options: \n"
printf " -h, --help Print this help \n\n"
printf "Available COMMANDS are: \n"
for i in "${!COMMAND_DESCRIPTIONS[@]}" ; do
printf " %s %s \n" "$i" "${COMMAND_DESCRIPTIONS[$i]}"
done
}
usage() {
echo "wip :-)"
}
########################
## Main Program ##
########################
# TODO: change octool usage to 'octool project command' format. Where projects
# are opencog, atomspace, cogutil... & commands are setup(for workspace),
# package(for docker,deb, rpm). Each will have various options/sub-commands.
#
declare -A COMMAND_DESCRIPTIONS=(
[build]="This is for building sources"
# 'ci' is compatible with previous octool
[ci]=" Intended for continuese integration."
# TODO 'dev' should be distro aware, that is, arch vs debian vs fedora
# shouldn't be an issue. If a dependancy doesn't exist through the distro
# then it should build from source.
[dev]=" This mode is for configuring development space"
[run]=" Run test or cogserver or some other thing"
)
# Choose command mode.
if [ $# -eq 0 ] ; then
octool_help
exit 0
else
case $1 in
ci) COMMAND_MODE_CHOSEN=ci ;;
dev) COMMAND_MODE_CHOSEN=dev ;;
build) COMMAND_MODE_CHOSEN=build ;;
run) COMMAND_MODE_CHOSEN=run ;;
--help | -h) octool_help ; exit 0 ;;
*) COMMAND_MODE_CHOSEN=ci ;;
# TODO: Replace with the following when full migration is done.
# *) MESSAGE="Modes available are: ${!COMMAND_MODE_DESCRIPTION[@]}"
# message
# exit 0 ;;
esac
fi
# Print what mode the script is running in
MESSAGE="Using '$COMMAND_MODE_CHOSEN' command mode" ; message
shift
case $COMMAND_MODE_CHOSEN in
ci) if [ $# -eq 0 ] ; then ci_help ; exit 0 ; fi
update_octool
while getopts "abdeipcrstlmhvj:" flag ; do
case $flag in
r) ADD_REPOSITORIES=true ;;
d) INSTALL_DEPENDENCIES=true ;;
p) INSTALL_OPENCOG_PYTHON_PACKAGES=true ;;
c) INSTALL_COGUTIL=true ;;
a) INSTALL_ATOMSPACE=true ;;
l) INSTALL_LINK_GRAMMAR=true ;;
m) INSTALL_MOSES=true ;;
b) BUILD_SOURCE=true ;;
e) BUILD_EXAMPLES=true ;;
t) RUN_TESTS=true ;;
v) unset QUIET ;;
j) MAKE_JOBS="$OPTARG" ;;
s) HASKELL_STACK_SETUP=true;;
i) INSTALL_BUILD=true ;;
h) ci_help ;;
\?) ci_help ;;
*) UNKNOWN_FLAGS=true ;;
esac
done
;;
build) if [ $# -eq 0 ] ; then ci_help ; exit 0 ; fi
while getopts "aehstj:" flag ; do
case $flag in
a) BUILD_ALL=true ;;
s) BUILD_SOURCE=true ;;
e) BUILD_EXAMPLES=true ;;
t) BUILD_TESTS=true ;;
j) MAKE_JOBS="$OPTARG" ;;
h) usage ;;
\?) usage ;;
*) UNKNOWN_FLAGS=true ;;
esac
done
;;
dev) printf "WIP comming soon :-) \n" ;;
run) if [ $# -eq 0 ] ; then ci_help ; exit 0 ; fi
case $1 in
cogserver) run_cogserver ;;
tests) run_tests ;;
*) MESSAGE="Only option is 'cogserver'" ; message
exit 0 ;;
esac
;;
*) echo "There is a bug in the script please report." ; exit 1;;
esac
# This is mainly for configuring workspaces depending on the type
# of project being worked on. The order here matters.
if [ $ADD_REPOSITORIES ] ; then add_repositories ; fi
if [ $INSTALL_DEPENDENCIES ] ; then install_dependencies ; fi
if [ $HASKELL_STACK_SETUP ] ; then install_haskell_dependencies ; fi
if [ $INSTALL_OPENCOG_PYTHON_PACKAGES ] ; then
install_opencog_python_packages
fi
if [ $INSTALL_COGUTIL ] ; then
install_opencog_cmake_project cogutil
fi
if [ $INSTALL_ATOMSPACE ] ; then
install_opencog_cmake_project atomspace
fi
if [ $INSTALL_LINK_GRAMMAR ] ; then install_link_grammar ; fi
if [ $INSTALL_MOSES ] ; then
install_opencog_cmake_project moses
fi
if [ $BUILD_ALL ] ; then
BUILD_SOURCE=true
BUILD_EXAMPLES=true
BUILD_TESTS=true
fi
if [ $BUILD_SOURCE ] ; then build_source ; fi
if [ $BUILD_EXAMPLES ] ; then build_examples ; fi
if [ $BUILD_TESTS ] ; then build_tests ; fi
if [ $RUN_TESTS ] ; then run_tests ; fi
if [ $INSTALL_BUILD ] ; then install_build ; fi
if [ $UNKNOWN_FLAGS ] ; then usage ; fi
exit 0