-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathec2ifscan
executable file
·53 lines (47 loc) · 1.66 KB
/
ec2ifscan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Copyright (C) 2013 Amazon.com, Inc. or its affiliates.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the
# License.
if [ $UID -ne 0 ]; then
echo "error: ${0##*/} must be run as root"
exit 1
fi
logger --tag ec2net "[ec2ifscan] Waiting for primary network interface"
# Wait while primary network interface isn't ready
attempts=60
false
while [ "${?}" -gt 0 ]; do
if [ "${attempts}" -eq 0 ]; then
logger --tag ec2net "[ec2ifscan] Aborted. Primary network interface not ready yet."
exit
fi
if [ ! -f /sys/class/net/eth0/operstate ] || ! grep 'up' /sys/class/net/eth0/operstate; then
if [ ! -f /sys/class/net/ens3/operstate ] || ! grep 'up' /sys/class/net/ens3/operstate; then
if [ ! -f /sys/class/net/ens5/operstate ] || ! grep 'up' /sys/class/net/ens5/operstate; then
let attempts--
sleep 0.5
false
fi
fi
fi
done
logger --tag ec2net "[ec2ifscan] Scanning for unconfigured interfaces"
for dev in $(find /sys/class/net/eth* /sys/class/net/ens*) ; do
cfg="/etc/network/interfaces.d/if-${dev##*/}.cfg"
state=$(cat ${dev}/operstate)
if [ ! -e "${cfg}" ] && [ "${state}" == "down" ] ; then
logger --tag ec2net "[ec2ifscan] Configuring ${dev##*/}"
echo 'add' > ${dev}/uevent
fi
done