Update to Centos image 7.4-1711
[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 # If it exists, copy in a specific Centos Repo for the Centos version for this image .
36
37 # Attempt up to five cycles of unpack/configure. There may be dependency
38 # problems during the first one(s).
39 echo ==========================yum repos==============================
40 if [ -f ${TEMP_PATH}/rpm/Centos-Vault.repo ] ; then
41     echo ==========================Install specific yum repo======================
42     sed -i '/gpgcheck=1/s/.*/&\nenabled=0/' /etc/yum.repos.d/CentOS-Base.repo
43     cp -f ${TEMP_PATH}/rpm/Centos-Vault.repo /etc/yum.repos.d
44 else
45     echo ==========================Update from base repo and updates================
46     : ;
47 fi
48 attempt=1
49 MAX_ATTEMPTS=3
50 try_again=1
51
52 RPM_FILE=${TEMP_PATH}/rpm/rpm-packages.txt
53 while [ $attempt -le $MAX_ATTEMPTS ] && [ $try_again -eq 1 ]
54 do
55   try_again=0
56   while read name url
57   do
58     # use rpm command if url is present in the package file
59     if [ ! -z $url ] ; then
60       rpm -i $url$name.rpm || try_again=1
61     else
62       yum install -y $name || try_again=1
63     fi
64   done < $RPM_FILE
65   attempt=$(( $attempt + 1 ))
66 done
67
68 if [[ ( $try_again == 1 ) ]]
69 then
70   echo "Still encountered errors after ${MAX_ATTEMPTS} attempts."
71 fi
72
73 ##
74 ## PIP
75 ##
76 echo "********** INSTALLING PIP PACKAGES **********"
77 pip install --no-index --find-links ${TEMP_PATH}/pip/ -r ${TEMP_PATH}/requirements.txt
78
79
80 echo "********** CREATING HISTORIC LINK FOR QEMU, COPY NESTED VM IMAGE **********"
81 mkdir -p /opt/qemu/bin
82 ln -s /usr/bin/qemu-system-x86_64 /opt/qemu/bin/qemu-system-x86_64
83
84 mkdir -p /var/lib/vm
85
86 echo "Embedding nested VM image on this image"
87 mkdir /var/lib/vm/images
88 cp ${TEMP_PATH}/nested-vm/* /var/lib/vm/images/
89 # There should only be one file at this time
90 ln -s /var/lib/vm/images/* /var/lib/vm/vhost-nested.img
91
92 ls -lR /var/lib/vm
93
94 # Mount hugepages directory for nested VM
95 mkdir -p /mnt/huge
96 echo 'hugetlbfs /mnt/huge       hugetlbfs       mode=1770,gid=111       0       0' >> /etc/fstab
97
98 ##
99 ## Java
100 ##
101 echo "********** CREATING JAVA SHELL PROFILE **********"
102 mkdir -p /etc/profile.d
103 echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' > /etc/profile.d/java.sh
104 echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile.d/java.sh
105
106
107 ##
108 ## Changelog
109 ##
110 echo "********** MOVING CHANGELOG AND VERSION FILES **********"
111
112 mv ${TEMP_PATH}/VERSION /
113 mv ${TEMP_PATH}/CHANGELOG /
114
115 echo "********** CLEANING UP **********"
116 rm -fr ${TEMP_PATH}