9ae16082035f56186b7c1bcb59c13662e16a09bb
[csit.git] / resources / tools / disk-image-builder / centos / 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 ### RPMs
20 ###
21 echo "********** INSTALLING RPMs **********"
22
23 # We're doing this the hard way as we're dealing with a bunch of
24 # rpm packages without using yum.
25
26 # Attempt up to five cycles of unpack/configure. There may be dependency
27 # problems during the first one(s).
28 echo ==========================yum update==============================
29 yum clean all
30 yum install -y @base
31 yum install -y deltarpm
32 yum update -y
33 yum -y install epel-release
34 yum update -y
35 echo ==========================end yum update==============================
36 attempt=1
37 MAX_ATTEMPTS=3
38 try_again=1
39
40 RPM_FILE=${TEMP_PATH}/rpm/rpm-packages.txt
41 while [ $attempt -le $MAX_ATTEMPTS ] && [ $try_again -eq 1 ]
42 do
43   try_again=0
44   while read name url
45   do
46     # use rpm command if url is present in the package file
47     if [ ! -z $url ] ; then
48       rpm -i $url$name || try_again=1
49     else
50       yum install -y $name || try_again=1
51     fi
52   done < $RPM_FILE
53   attempt=$(( $attempt + 1 ))
54 done
55
56 if [[ ( $try_again == 1 ) ]]
57 then
58   echo "Still encountered errors after ${MAX_ATTEMPTS} attempts."
59 fi
60
61 ##
62 ## PIP
63 ##
64 echo "********** INSTALLING PIP PACKAGES **********"
65 pip install --no-index --find-links ${TEMP_PATH}/pip/ -r ${TEMP_PATH}/requirements.txt
66
67
68 echo "********** CREATING HISTORIC LINK FOR QEMU, COPY NESTED VM IMAGE **********"
69 mkdir -p /opt/qemu/bin
70 ln -s /usr/bin/qemu-system-x86_64 /opt/qemu/bin/qemu-system-x86_64
71
72 mkdir -p /var/lib/vm
73
74 echo "Embedding nested VM image on this image"
75 mkdir /var/lib/vm/images
76 cp ${TEMP_PATH}/nested-vm/* /var/lib/vm/images/
77 # There should only be one file at this time
78 ln -s /var/lib/vm/images/* /var/lib/vm/vhost-nested.img
79
80 ls -lR /var/lib/vm
81
82 # Mount hugepages directory for nested VM
83 mkdir -p /mnt/huge
84 echo 'hugetlbfs /mnt/huge       hugetlbfs       mode=1770,gid=111       0       0' >> /etc/fstab
85
86 ##
87 ## Java
88 ##
89 echo "********** CREATING JAVA SHELL PROFILE **********"
90 mkdir -p /etc/profile.d
91 echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' > /etc/profile.d/java.sh
92 echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile.d/java.sh
93
94
95 ##
96 ## Changelog
97 ##
98 echo "********** MOVING CHANGELOG AND VERSION FILES **********"
99
100 mv ${TEMP_PATH}/VERSION /
101 mv ${TEMP_PATH}/CHANGELOG /
102
103 echo "********** CLEANING UP **********"
104 rm -fr ${TEMP_PATH}