Seed code for image-provision
[ta/image-provision.git] / dracut / modules / 00netconfig / net_config_get_iso.sh
1 #!/bin/sh
2
3 # Copyright 2019 Nokia
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17
18 source /usr/lib/installmedia-lib.sh
19
20 if [ -e /tmp/cloud_configs/network_config ];then
21     warn "net_config_get_iso: Creating local network configurations, to download boot.iso."
22     source /tmp/cloud_configs/network_config
23
24     if [ $VLAN ]; then
25       warn "net_config_get_iso: Configuring VLAN network"
26       ip link add link $DEV name ${DEV}.${VLAN} type vlan id $VLAN
27       ip a a $IP dev ${DEV}.${VLAN}
28       ip link set up dev ${DEV}.${VLAN}
29       ip link set up dev ${DEV}
30       ip r a default via ${DGW} dev ${DEV}.${VLAN}
31       EXT_DEV="${DEV}.${VLAN}"
32     else
33       warn "net_config_get_iso: Configuring non-VLAN network"
34       ip a a $IP dev ${DEV}
35       ip link set up dev ${DEV}
36       ip r a default via ${DGW} dev ${DEV}
37       EXT_DEV="${DEV}"
38     fi
39     
40     wait_count=0
41     ip link show ${EXT_DEV} | grep "LOWER_UP" > /dev/null 2>&1
42     while [ $? != 0 ]
43     do
44       sleep 2
45       ((wait_count++))
46       if [[ $wait_count == 10 ]]; then
47         warn "net_config_get_iso: Link on ${EXT_DEV} did not come-up. Cannot proceed!"
48         exit 1
49       fi
50       warn "net_config_get_iso: Waiting for link to come-up on ${EXT_DEV}..."
51       ip link show ${EXT_DEV} | grep "LOWER_UP" > /dev/null 2>&1
52     done
53     
54     warn "net_config_get_iso: Link on ${EXT_DEV} came-up. Proceeding."
55     
56     if [ ${NAMESERVER} ]; then
57       echo "nameserver ${NAMESERVER}" > /etc/resolv.conf
58     fi
59     
60     # Check if DGW is pinging. If not exit. User may want to cross-check his network_config file and network and fix it.
61     warn "net_config_get_iso: Checking if DGW ${DGW} is pinging."
62     ping_wait_count=0
63     gw_ping_status=1
64     while [ ${gw_ping_status} != 0 ]
65     do
66         ((ping_wait_count++))
67         if [[ ${ping_wait_count} == 120 ]]; then
68             warn "net_config_get_iso: Provided default gateway ${DGW} is not pinging. Exiting installation."
69             exit 1
70         fi
71         if [[ ${DGW} = *:* ]]; then
72             ping -6 -c 1 -w 1 ${DGW} > /dev/null 2>&1
73         else
74             ping -c 1 -w 1 ${DGW} > /dev/null 2>&1
75         fi
76         gw_ping_status=$?
77     done
78     
79     warn "Downloading Full ISO from URL: ${ISO_URL}"
80     if ! wget --connect-timeout 5 --read-timeout 100 --no-check-certificate ${ISO_URL} --progress=dot:giga -O $BOOTCD_LOCATION; then
81         warn "net_config_get_iso: Failed to download ISO from URL: ${ISO_URL}. Exiting installation."
82         exit 1
83     fi
84 fi