Add JAVA_HOME and include Java in PATH environment variables.
[csit.git] / resources / tools / disk-image-builder / ubuntu / scripts-remote / post-install.sh
1 #!/bin/sh -e
2
3 # Copyright (c) 2016 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 TEMP_PATH="/root/temp"
17
18 ###
19 ### APT
20 ###
21 echo "********** INSTALLING APT PACKAGES **********"
22 echo -n > /etc/apt/sources.list
23
24 export DEBIAN_FRONTEND=noninteractive
25
26 # We're doing this the hard way as we're dealing with a bunch of
27 # .deb packages rather than any sources organized through APT.
28
29 # Attempt up to five cycles of unpack/configure. There may be dependency
30 # problems during the first one(s).
31
32 attempt=1
33 MAX_ATTEMPTS=5
34 try_again=1
35
36 while [ $attempt -le $MAX_ATTEMPTS ] && [ $try_again -eq 1 ]
37 do
38   try_again=0
39   echo "Attempting .deb package installation, attempt #${attempt}/${MAX_ATTEMPTS}"
40   dpkg --unpack --recursive --skip-same-version ${TEMP_PATH}/deb || try_again=1
41   dpkg --configure --pending || try_again=1
42   if [ $try_again -eq 1 ]
43   then
44     echo Encountered errors.
45   fi
46   attempt=$(( $attempt + 1 ))
47 done
48
49 if [ $try_again -eq 1 ]
50 then
51   echo "Still encountered errors after ${MAX_ATTEMPTS} attempts. Aborting".
52   exit 1
53 fi
54
55 ##
56 ## PIP
57 ##
58 echo "********** INSTALLING PIP PACKAGES **********"
59 pip install --no-index --find-links ${TEMP_PATH}/pip/ -r ${TEMP_PATH}/requirements.txt
60
61
62 echo "********** CREATING HISTORIC LINK FOR QEMU, COPY NESTED VM IMAGE **********"
63 mkdir -p /opt/qemu/bin
64 ln -s /usr/bin/qemu-system-x86_64 /opt/qemu/bin/qemu-system-x86_64
65
66 mkdir -p /var/lib/vm
67
68 echo "Embedding nested VM image on this image"
69 mkdir /var/lib/vm/images
70 cp ${TEMP_PATH}/nested-vm/* /var/lib/vm/images/
71 # There should only be one file at this time
72 ln -s /var/lib/vm/images/* /var/lib/vm/vhost-nested.img
73
74 ls -lR /var/lib/vm
75
76 # Mount hugepages directory for nested VM
77 mkdir -p /mnt/huge
78 echo 'hugetlbfs /mnt/huge       hugetlbfs       mode=1770,gid=111       0       0' >> /etc/fstab
79
80 ##
81 ## Java
82 ##
83 echo "********** CREATING JAVA SHELL PROFILE **********"
84 mkdir -p /etc/profile.d
85 echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' > /etc/profile.d/java.sh
86 echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile.d/java.sh
87
88
89 ##
90 ## Changelog
91 ##
92 echo "********** MOVING CHANGELOG AND VERSION FILES **********"
93
94 mv ${TEMP_PATH}/VERSION /
95 mv ${TEMP_PATH}/CHANGELOG /
96
97 echo "********** CLEANING UP **********"
98 rm -fr ${TEMP_PATH}