forked from opencog/ocpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocpkg
executable file
·1404 lines (1256 loc) · 42.7 KB
/
ocpkg
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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
## @file ocpkg
## @copyright OpenCog Foundation (2012,2013,2014,2015)
## @author David Hart <[email protected]>
## @section DESCRIPTION A script to download, build, test, install and package OpenCog
## @section LICENSE Permission to copy and modify is granted under the GPL
## @section REQUIREMENT Ubuntu Linux 14.04 "Trusty Tahr". See opencog/ocpkg repo for 12.04 version
## @section SEEALSO Dockerfile - compile and run OpenCog in a Linux container
# This bash script is organized in sections
# SECTION 1. Global variable setting
# SECTION 2. Command line option handling
# SECTION 3. Error handling & cleanup
# SECTION 4. Function definitions
# SECTION 5. Main program
# Notes
# 5 minute LiveCD creation is possible with a minimum of 4GB RAM, 4GB SWAP, and /tmp on 4GB tmpfs
# test CD/DVD images using:
# testdrive -u OpenCogLive.iso
# kvm -cdrom OpenCogLive.iso -boot d -m 2048
# To do
# Debian/Ubuntu packaging abilities http://developer.ubuntu.com/packaging/html/
# incremental builds
# manifest rebuild to LiveCD/DVD
# trap errors
set -e
# SECTION 1: GLOBAL VARIABLES
declare -A PACKAGE_DESCRIPTION=(
[local]="Local install with no packaging (default)"
[demo]="LiveCD ISO image ~700MB with OpenCog Demo (auto-starting)"
[min]="LiveCD ISO image ~700MB with OpenCog Server"
[dev]="LiveDVD ISO image ~900MB with OpenCog Developement Environment"
[kvm]="TBD Ubuntu KVM image with OpenCog Server"
[demovm]="TBD Ubuntu VirtualBox image with OpenCog Unity3D proxy for demo"
[debs]="TBD Ubuntu packages (deb files)"
[docker]="TBD Docker Images"
)
PATH_PREFIX=/usr/local
CURRENT_DIR=$(pwd)
SOURCE_DIR=""
BUILD_DIR=""
if [ "$USER" == "root" ] ; then
HOST_SOURCE_BRANCH=$PATH_PREFIX/src/opencog
HOST_BUILD_DIR=/tmp/opencog_build
else
HOST_SOURCE_BRANCH=$CURRENT_DIR/opencog/src
HOST_BUILD_DIR=$CURRENT_DIR/opencog/build
fi
SLEEP_TIME=0
OUTPUT_ISO_NAME=OpenCogLive.iso
OUTPUT_ISO_LOCATION=$CURRENT_DIR
DEFAULT_PACKAGE_TYPE=local
DEFAULT_ADD_REPOSITORIES=true
DEFAULT_INSTALL_DEPENDENCIES=true
DEFAULT_UPDATE_OPENCOG=true
DEFAULT_BUILD_OPENCOG=false
DEFAULT_TEST_OPENCOG=false
# TBD: update for Ubuntu 14.04
UBUNTU_ISO=ubuntu-12.04.2-desktop-amd64.iso
UBUNTU_URL=http://releases.ubuntu.com/12.04/
UBUNTU_MD5SUM=b436b6d4c7de064652f30d783bda5b4e
UBUNTU_ISO_IMAGE=$CURRENT_DIR/$UBUNTU_ISO #default location
SELF_NAME=$(basename $0)
TOOL_NAME=octool
GUILEVERSION=2.2.3
PROCESSORS=$(grep "^processor" /proc/cpuinfo | wc -l)
MAKE_JOBS=$(($PROCESSORS+0))
SQUASHFS_OPTIONS="-noDataCompression -noappend" #faster
SQUASHFS_OPTIONS="-noappend"
LIVE_SOURCE_BRANCH=$HOST_SOURCE_BRANCH
LIVE_BUILD_DIR=$HOST_BUILD_DIR
VERBOSE="-v" #for mount, umount, rm, etc.
#QUIET="-qq" #for apt-get
LIVE_DESKTOP_SOURCE="OpenCog Source Code"
REPOSITORIES=""
# ppa:opencog-dev/ppa \
# opencog-dev: cxxtest
# gandelman: python-flask-restful
# ppa:chris-lea/zeromq \
# ppa:chris-lea/python-flask \
# ppa:chris-lea/python-itsdangerous \
# ppa:chris-lea/python-simplejson \
# ppa:gandelman-a/test-catalog \
PACKAGES_TOOLS="
squashfs-tools \
genisoimage \
"
#aria2 \
#qemu-kvm \
#testdrive \
PACKAGES_FETCH="
python-pip \
git \
"
#bzr-rewrite \
PACKAGES_ADMIN="
apt-rdepends \
synaptic \
gdebi \
epiphany-browser \
"
PACKAGES_BUILD="
build-essential \
cmake \
cxxtest \
rlwrap \
libiberty-dev \
libicu-dev \
libbz2-dev \
cython \
python3-dev \
python3-zmq \
python3-pip
python3-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 \
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 \
gearman \
libgearman-dev \
ccache \
libgsasl7 \
libldap2-dev \
krb5-multidev \
wordnet \
wordnet-dev \
wordnet-sense-index \
libatomic-ops-dev\
libgmp-dev \
libffi-dev \
libreadline-dev \
"
#liblua5.1-0-dev \
#libxmlrpc-c3-dev \
#python-flask \
#python-flask-restful \
PACKAGES_RUNTIME="
unixodbc \
odbc-postgresql \
postgresql-client \
"
PACKAGES_DOC="
ubuntu-docs \
libglib2.0-doc \
libpango1.0-doc \
libgtk-3-doc \
texlive-latex-base-doc \
python-doc \
devhelp-common \
texlive-doc-base \
doxygen \
dot2tex \
"
PACKAGES_REMOVE="
ubuntu-desktop \
example-content \
software-center \
app-install-data \
locales \
python-twisted-core \
ubiquity \
rhythmbox \
rhythmbox-data \
empathy \
empathy-common \
libtelepathy-glib0 \
firefox \
thunderbird \
libreoffice-core \
evolution-data-server \
gnome-games-common \
gnome-games-data \
aisleriot \
deja-dup \
gwibber \
oneconf \
shotwell \
ubuntuone-client \
python-ubuntuone-client \
gnome-orca \
libgweather-common \
simple-scan \
sane-utils \
printer-driver-hpcups \
printer-driver-hpijs \
hplip \
hplip-data \
libgutenprint2 \
foo2zjs \
colord \
libsane \
samba-common \
gnome-user-guide \
ure \
smbclient \
indicator-messages \
ubuntuone-client-gnome \
geoip-database \
libopencc1 \
fonts-nanum \
ttf-indic-fonts-core \
ttf-wqy-microhei \
fonts-takao-pgothic \
libpurple0 \
brltty \
liblouis-data \
"
#ubuntu-wallpapers \
#this stuff is for Unity 2D, but Ubuntu fails to login without it
#libqtgui4 \
#libqt4-core \
#libqt4-xmlpatterns \
#libwebkitgtk-3.0-0 \
#language-pack-pt-base \
#language-pack-es-base \
#language-pack-xh-base \
#language-pack-zh-hans \
#language-pack-de-base \
#language-pack-fr-base \
#language-pack-ca-base \
#language-pack-el-base \
#language-pack-sv-base \
#language-pack-ru-base \
#language-pack-gnome-zh-hans-base \
#language-pack-kde-zh-hans-base \
# NOTES
# apps listed first, then libraries that they depend upon which will
# also uninstall other stuff
# ubiquity - graphical Ubuntu installer that runs on boot
# 23MB app-install-data (ubuntu software center)
# 22MB ubuntu-docs (desktop docs)
# 44MB thunderbird
# 26MB amarok
# 200MB libreoffice
# 45MB smbclient
PACKAGES_EXDEV="
autoconf automake autotools-dev \
blt \
comerr-dev \
dpkg-dev \
emacsen-common \
fakeroot \
gettext \
gdb \
g++-4.6 \
gcc-4.6 \
krb5-multidev \
libc6-dev \
libdpkg-perl \
libdpkg-perl \
libgcrypt11-dev \
libglade2-0 \
libgnutls-dev \
libgpg-error-dev \
libgssrpc4 \
libidn11-dev \
libalgorithm-diff-perl \
libalgorithm-diff-xs-perl \
libalgorithm-merge-perl \
libkadm5clnt-mit8 \
libkadm5srv-mit8 \
libkrb5-dev \
libldap2-dev \
libltdl-dev \
libstdc++6-4.6-dev \
libtasn1-3-dev \
libtimedate-perl \
libtool \
libunistring0 \
libxss1 \
make \
manpages-dev \
m4 \
patch \
python-glade2 \
python-tk \
tcl8.5 \
tk8.5 \
ttf-lyx \
zlib1g-dev \
python-bzrlib \
linux-headers-generic \
"
# SECTION 2: Command line option handling
usage() {
if [ "$SELF_NAME" == "$TOOL_NAME" ] ; then
echo "Usage: $SELF_NAME OPTION"
echo " -r Add software repositories"
echo " -d Install base/system build dependencies"
echo " -p Install python build dependencies"
echo " -s Install haskell build dependencies in user space. Don't use sudo"
echo " -i Install build-job artifacts"
echo " -c Install Cogutil"
echo " -a Install AtomSpace"
echo " -o Install OpenCog"
echo " -n Install notebook"
echo " -l {default|java} For installing Link Grammar with java binding '-l java' else '-l default'"
echo " -m Install MOSES"
echo " -g Install Guile $GUILEVERSION"
echo " -b Build source code in git worktree found @ $PWD"
echo " -e Build examples in git worktree found @ $PWD"
echo " -t Run tests of source code in git worktree found @ $PWD"
echo " -j [jobs] override number of auto-detected make jobs"
echo " -w download data for the opencog repo"
echo " -v Verbose output for 'apt-get' commands"
echo " -h This help message"
else
echo "Usage: $SELF_NAME [OPTIONS] [PACKAGE-TYPE]"
echo " PACKAGE-TYPES:"
for key in ${!PACKAGE_DESCRIPTION[@]}; do
echo " " ${key} $'\t' "${PACKAGE_DESCRIPTION[$key]}"
done
echo " (Live CD: Ubuntu ISO image ~700MB will be downloaded if none found.)"
echo " OPTIONS:"
echo " -i [filename] ISO input filename"
echo " -o [filename] ISO output filename"
echo " -j [jobs] override number of auto-detected make jobs"
echo " -n supress git updates"
fi
}
# 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.
#if [ $1 ] && [ "$SELF_NAME" != "$TOOL_NAME" ] ; then
if [ $# -eq 0 ] ; then NO_ARGS=true ; fi
if [ "$SELF_NAME" == "$TOOL_NAME" ] ; then
while getopts "abdegipcrstl:mhvj:own" flag ; do
case $flag in
r) ADD_REPOSITORIES=true ;;
d) INSTALL_DEPENDENCIES=true ;; #base development packages
w) DOWNLOAD_DATA=true ;;
p) INSTALL_OPENCOG_PYTHON_PACKAGES=true ;;
c) INSTALL_COGUTIL=true ;;
a) INSTALL_ATOMSPACE=true ;;
o) INSTALL_OPENCOG=true ;;
l) if [ "$OPTARG" == "default" ]; then
INSTALL_LINK_GRAMMAR=true
elif [ "$OPTARG" == "java" ]; then
INSTALL_JAVA_LINK_GRAMMAR=true
else
MESSAGE="If you want java binding run '-l java' else '-l default'"
message ; exit 1
fi ;;
m) INSTALL_MOSES=true ;;
n) INSTALL_NOTEBOOKS=true;;
g) INSTALL_GUILE=true ;;
b) BUILD_SOURCE=true ;;
e) BUILD_EXAMPLES=true ;;
t) TEST_SOURCE=true ;;
v) unset QUIET ;;
j) MAKE_JOBS="$OPTARG" ;;
s) HASKELL_STACK_SETUP=true;;
i) INSTALL_BUILD=true ;;
h) usage ;;
\?) usage; exit 1 ;;
*) UNKNOWN_FLAGS=true ;;
esac
done
else
while getopts ":i:o:j:s:c:l:r:adubtnxrvh" flag ; do
case $flag in
i) INPUT_ISO_NAME="$OPTARG" ;;
o) OUTPUT_ISO_NAME="$OPTARG" ;;
j) MAKE_JOBS="$OPTARG" ;; #override auto-detected MAKE_JOBS
s) HOST_SOURCE_BRANCH="$OPTARG" ;;
c) HOST_BUILD_DIR="$OPTARG" ;; #local cached build dir
l) LIVE_BUILD_DIR="$OPTARG" ;; #live build directory
r) BZR_REVISION="$OPTARG" ;;
a) ADD_REPOSITORIES=true ;;
d) INSTALL_DEPENDENCIES=true ;; #ALL, none
u) UPDATE_OPENCOG=true ;; #git pull
b) BUILD_OPENCOG=true ;; #build opencog
t) TEST_OPENCOG=true ;; #test opencog
n) unset DEFAULT_UPDATE_OPENCOG ;; #suppress git update
x) unset DEFAULT_BUILD_OPENCOG ;; #suppress build
p) REINSTALL_PACKAGES=true ;;
v) unset QUIET ;;
h) usage ;;
\?) usage ;;
*) UNKNOWN_FLAGS=true ;;
esac
done
fi
shift $((OPTIND-1))
message() {
echo -e "\e[1;34m[$SELF_NAME] $MESSAGE\e[0m"
}
PACKAGE_TYPE=$DEFAULT_PACKAGE_TYPE
# This handles ./ocpkg runs, for e.g. `./ocpkg debs`
if [ $1 ] && [ "$SELF_NAME" != "ocpkg" ] ; then
case $1 in
debs) PACKAGE_TYPE=$1 ;;
dev) PACKAGE_TYPE=$1 ;;
demo) PACKAGE_TYPE=$1 ;;
kvm) PACKAGE_TYPE=$1 ;;
min) PACKAGE_TYPE=$1 ;;
local) PACKAGE_TYPE=$1 ;;
docker) PACKAGE_TYPE=$1 ;;
*) MESSAGE="Package type not recognized."; message ; usage ; exit 1 ;;
esac
MESSAGE="Package type: $PACKAGE_TYPE : ${PACKAGE_DESCRIPTION[$PACKAGE_TYPE]}" ; message
fi
#echo "[otheropts]==> $@"
# SECTION 3: Error handling & cleanup
debug() {
MESSAGE="Dropping to debugging chroot prompt..." ; message
chroot $LIVE_SQUASH_UNION /bin/bash -l
}
cleanup_squash() {
if [ -n "$LIVE_SQUASH_UNION" ]; then
MESSAGE="Cleaning up squash temp space..." ; message
fuser $VERBOSE --mount $LIVE_SQUASH_UNION -kill
sleep $SLEEP_TIME
umount $VERBOSE $LIVE_SQUASH_UNION/var/lib/apt/lists || true
umount $VERBOSE $LIVE_SQUASH_UNION/var/cache/apt/archives || true
umount $VERBOSE $LIVE_SQUASH_UNION/proc || true
umount $VERBOSE $LIVE_SQUASH_UNION/sys || true
umount $VERBOSE $LIVE_SQUASH_UNION/dev/pts || true
umount $VERBOSE $LIVE_SQUASH_UNION$LIVE_BUILD_DIR || true
umount $VERBOSE $LIVE_SQUASH_UNION$LIVE_SOURCE_BRANCH || true
MESSAGE="Killing processes..." ; message
fuser $VERBOSE --mount $LIVE_SQUASH_UNION -kill
sleep $SLEEP_TIME
umount -v -f $VERBOSE $LIVE_SQUASH_UNION || true
rmdir $VERBOSE $LIVE_SQUASH_UNION || true
fi
if [ -n "$LIVE_SQUASH_DELTA" ]; then
echo " $LIVE_SQUASH_DELTA"
rm -rf $LIVE_SQUASH_DELTA || true
fi
if [ -n "$UBUNTU_SQUASH_FILES" ]; then
echo " $UBUNTU_SQUASH_FILES"
umount $VERBOSE $UBUNTU_SQUASH_FILES || true
rmdir $VERBOSE $UBUNTU_SQUASH_FILES || true
fi
}
cleanup_iso() {
if [ -n "$LIVE_ISO_UNION" ] ; then
MESSAGE="Cleaning up ISO temp space..." ; message
echo " $LIVE_ISO_UNION"
umount $VERBOSE $LIVE_ISO_UNION || true
rmdir $LIVE_ISO_UNION || true
df -m $LIVE_ISO_UNION || true
fi
if [ -n "$LIVE_ISO_DELTA" ] ; then
echo " $LIVE_ISO_DELTA"
rm -rf $LIVE_ISO_DELTA || true
fi
if [ -n "$UBUNTU_ISO_FILES" ] ; then
echo " $UBUNTU_ISO_FILES"
umount $VERBOSE $UBUNTU_ISO_FILES || true
rmdir $UBUNTU_ISO_FILES || true
df -m $UBUNTU_ISO_FILES || true
fi
}
exit_trap() {
if [ "$SELF_NAME" != "$TOOL_NAME" ] ; then
MESSAGE="Exiting $SELF_NAME normally..." ; message
cleanup_squash
cleanup_iso
fi
}
quit_trap() {
if [ "$SELF_NAME" != "$TOOL_NAME" ] ; then
MESSAGE="Exiting $SELF_NAME by request..." ; message
cleanup_squash
cleanup_iso
fi
}
error_trap() {
if [ "$SELF_NAME" != "$TOOL_NAME" ] ; then
MESSAGE="Error trapped while running $SELF_NAME." ; message
MESSAGE="Cleanup will run after debug." ; message
debug
cleanup_squash
cleanup_iso
fi
}
trap error_trap ERR
trap exit_trap EXIT
trap quit_trap INT HUP QUIT TERM
# SECTION 4: Function Definitions
is_x68_64() {
ARCH=$(uname -m);
if [ "$ARCH" == "x86_64" ]; then
return 0
else
return 1
fi
}
get_distro_version() {
cat /etc/os-release | grep "^VERSION_ID=" | cut -d "=" -f 2
}
UBUNTU_VERSION=$(get_distro_version)
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
# TODO remove this when the reference os is changed to 16.04.
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B01FA116
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
sudo apt-get $QUIET --assume-yes update
}
get_github_latest_release() {
local _user="$1"
local _repo="$2"
local _file_name="$3"
# Getting the version and also accepting the file-name means that the
# download will fail if the release is updated and the file-name has a
# reference to the previous release, a hacky annoying reminder. If the
# file-name has no reference to the version then all will go well.
# TODO: Handle failure gracefully.
local _version=$(curl https://github.com/"$_user"/"$_repo"/releases/latest \
| cut -d "\"" -f 2 | cut -d "/" -f 8)
echo $_user $_repo $_version
rm -f $_file_name
wget https://github.com/"$_user"/"$_repo"/releases/download/"$_version"/"$_file_name"
}
install_admin() {
MESSAGE="Installing sysadmin tools...." ; message
if ! sudo apt-get $QUIET --no-upgrade --assume-yes install $PACKAGES_ADMIN ; then
MESSAGE="Please enable 'universe' repositories and re-run this script." ; message
exit 1
fi
}
# Install cogutil
install_cogutil(){
MESSAGE="Installing cogutil...." ; message
cd /tmp/
# cleaning up remnants from previous install failures, if any.
rm -rf master.tar.gz* cogutil-master
wget https://github.com/opencog/cogutil/archive/master.tar.gz
tar -xvf master.tar.gz
cd cogutil-master/
mkdir build
cd build/
cmake ..
make -j$(nproc)
sudo make install
sudo ldconfig
cd /tmp/
rm -rf master.tar.gz cogutil-master/
cd $CURRENT_DIR
}
# Install notebooks
install_notebooks(){
MESSAGE="Installing notebooks...." ; message
#####INSTALLING pip3 AND jupyter notebook
cd
sudo apt-get install python3-pip
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install ipython jupyter
#####INSTALLING GUILE KERNEL#####
#check if site folder exits
if [ ! -d "/usr/local/share/guile/site" ]
then
cd /usr/local/share/guile/
sudo mkdir site
cd
fi
#Install ZeroMQ library
##Clean up remenants of previous installations##
rm -rf zeromq-4.2.1*
wget https://github.com/zeromq/libzmq/releases/download/v4.2.1/zeromq-4.2.1.tar.gz
tar xvf zeromq-4.2.1.tar.gz
cd zeromq-4.2.1/
./configure
make
sudo make install
cd
#Install guile-json library
##Clean up remenants of previous installations##
rm -rf guile-json-0.6.0*
wget http://download.savannah.gnu.org/releases/guile-json/guile-json-0.6.0.tar.gz
tar xvf guile-json-0.6.0.tar.gz
cd guile-json-0.6.0
./configure --prefix=/usr/local/
make
sudo make install
cd
cd `guile -c "(display (%global-site-dir))"`
#Place guile-simple-zmq library to the guile library folder
sudo rm -rf simple-zmq.scm*
sudo wget https://raw.githubusercontent.com/jerry40/guile-simple-zmq/master/src/simple-zmq.scm
#edit simple-zmq.scm => set BUF-SIZE to 8192.
sudo sed -i 's/(define BUF-SIZE.*)/(define BUF-SIZE 8192)/' simple-zmq.scm
cd
#Kernel setup
if [ ! -d "/home/$USER/.local/share/jupyter/kernels/guile" ]
then
sudo mkdir /home/$USER/.local/share/jupyter/kernels/guile
fi
cd /home/$USER/.local/share/jupyter/kernels/guile
sudo rm -rf guile-jupyter-kernel.scm hmac.scm kernel.json tools.scm
sudo wget https://github.com/jerry40/guile-kernel/raw/master/src/guile-jupyter-kernel.scm
sudo wget https://github.com/jerry40/guile-kernel/raw/master/src/hmac.scm
sudo wget https://github.com/jerry40/guile-kernel/raw/master/src/kernel.json
sudo wget https://github.com/jerry40/guile-kernel/raw/master/src/tools.scm
sudo sed -i 's,\/home.*local,'$HOME/.local',' kernel.json
echo "export PATH=$PATH:/home/$USER/.local/bin"
echo "source /home/$USER/.bashrc"
cd $CURRENT_DIR
}
# 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.
# TODO: cleanup the requirements.txt file.
sudo pip install -U pip
sudo pip install -U $(awk '!/scipy/&&!/numpy/&&!/matplotlib/' requirements.txt)
sudo apt-get install -y python-matplotlib python-numpy python-scipy python
# For sentiment analysis
# TODO: update depending on https://github.com/opencog/opencog/issues/2285
sudo pip install -U pyyaml nltk
sudo python -m nltk.downloader -d /usr/local/share/nltk_data punkt averaged_perceptron_tagger
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/&&/stack-[0-9\.]*-linux-i386.tar.gz/' | head -n 1 | cut -d '"' -f 4)
# tar xfz stack*linux-i386.tar.gz
# rm stack*linux-i386.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
sudo wget -qO- https://get.haskellstack.org/ | sh
# 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
echo "Please run without sudo. Stack need to be run in non-root user space."
fi
}
# The following sets the source & build directory for a project
set_source_and_build_dir() {
if [ "$(git rev-parse --is-inside-work-tree)" == true ] ; then
SOURCE_DIR=$(git rev-parse --show-toplevel)
MESSAGE="Source Directory is set to $SOURCE_DIR" ; message
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
else
MESSAGE="Exiting $SELF_NAME as git worktree is not detected run inside \
a git worktree" ; message
exit 1
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
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" ; 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
}
# Run tests function for opencog, atomspace, moses & cogutil repos
test_source() {
#check if gearman service is running, start it if not
if (( $(ps -ef | grep -v grep | grep gearman-job-server | wc -l) > 0 ))
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" ; 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
}
# Install AtomSpace
install_atomspace(){
MESSAGE="Installing atomspace...." ; message
cd /tmp/
# cleaning up remnants from previous install failures, if any.
rm -rf master.tar.gz* atomspace-master
wget https://github.com/opencog/atomspace/archive/master.tar.gz
tar -xvf master.tar.gz
cd atomspace-master/
mkdir build
cd build/
cmake ..
make -j$(nproc)
sudo make install
sudo ldconfig
cd /tmp/
rm -rf master.tar.gz atomspace-master/
cd $CURRENT_DIR
}
# Install OpenCog
install_opencog(){
MESSAGE="Installing opencog...." ; message
cd /tmp/
# cleaning up remnants from previous install failures, if any.
rm -rf master.tar.gz* opencog-master
wget https://github.com/opencog/opencog/archive/master.tar.gz
tar -xvf master.tar.gz
cd opencog-master/
mkdir build
cd build/
cmake ..
make -j$(nproc)
sudo make install
sudo ldconfig
cd /tmp/
rm -rf master.tar.gz opencog-master/
cd $CURRENT_DIR
}
# Install MOSES
install_moses(){
MESSAGE="Installing MOSES...." ; message
cd /tmp/
# cleaning up remnants from previous install failures, if any.
rm -rf master.tar.gz* moses-master
wget https://github.com/opencog/moses/archive/master.tar.gz
tar -xvf master.tar.gz
cd moses-master/
mkdir build
cd build
cmake ..
make -j$(nproc)
sudo make install
sudo ldconfig
cd /tmp/
rm -rf master.tar.gz moses-master/
cd $CURRENT_DIR
}
# 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.*/
if [ $# -eq 1 ]; then
wget http://www.abisource.com/downloads/link-grammar/${1}/link-grammar-${1}.tar.gz
tar -zxf link-grammar-5*.tar.gz
else
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
fi
cd link-grammar-5.*/
mkdir build
cd build
if [ $INSTALL_JAVA_LINK_GRAMMAR ]; then
../configure
else
../configure --disable-java-bindings
fi
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
install_cpprest(){
if [[ "$UBUNTU_VERSION" == "\"14.04\"" ]]; then
if [[ -f /usr/local/lib/libcpprest.so.2.9 ]]; then
MESSAGE="cpprest is already installed." ; message
return
fi
MESSAGE="Installing cpprest...." ; message
cd /tmp/
# cleaning up remnants from previous install failures, if any.
rm -rf v2.9.0.tar.gz* cpprestsdk-2.9.0
wget https://github.com/Microsoft/cpprestsdk/archive/v2.9.0.tar.gz
tar -xvf v2.9.0.tar.gz
cd cpprestsdk-2.9.0/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 v2.9.0.tar.gz* cpprestsdk-2.9.0
cd $CURRENT_DIR
elif [[ "$UBUNTU_VERSION" == "\"16.04\"" ]]; then
sudo apt-get install -y libcpprest
fi
}