Update of Packer builder for Vagrant and various clouds
[osm/devops.git] / packer / packer_templates / osm / scripts / networking.sh
1 #!/bin/sh -eux
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 ubuntu_version="`lsb_release -r | awk '{print $2}'`";
16 major_version="`echo $ubuntu_version | awk -F. '{print $1}'`";
17
18 if [ "$major_version" -ge "18" ]; then
19 echo "Create netplan config for eth0"
20 cat <<EOF >/etc/netplan/01-netcfg.yaml;
21 network:
22 version: 2
23 ethernets:
24 eth0:
25 dhcp4: true
26 EOF
27 else
28 # Adding a 2 sec delay to the interface up, to make the dhclient happy
29 echo "pre-up sleep 2" >> /etc/network/interfaces;
30 fi
31
32 if [ "$major_version" -ge "16" ]; then
33 # Disable Predictable Network Interface names and use eth0
34 sed -i 's/en[[:alnum:]]*/eth0/g' /etc/network/interfaces;
35 sed -i 's/GRUB_CMDLINE_LINUX="\(.*\)"/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0 \1"/g' /etc/default/grub;
36 update-grub;
37 fi