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