]>
Commit | Line | Data |
---|---|---|
1c21ebf8 MT |
1 | #!/bin/sh |
2 | ######################################################################## | |
ffb37e51 | 3 | # Begin $rc_base/init.d/cloud-init |
1c21ebf8 MT |
4 | ######################################################################## |
5 | ||
6 | . /etc/sysconfig/rc | |
7 | . ${rc_functions} | |
8 | ||
1c21ebf8 MT |
9 | case "${1}" in |
10 | start) | |
b9021f92 MT |
11 | # Check if we are running in the cloud |
12 | if running_on_ec2; then | |
13 | scriptname="/etc/rc.d/helper/aws-setup" | |
14 | elif running_on_azure; then | |
15 | scriptname="/etc/rc.d/helper/azure-setup" | |
86c64598 MT |
16 | elif running_on_gcp; then |
17 | scriptname="/etc/rc.d/helper/gcp-setup" | |
b9021f92 MT |
18 | else |
19 | # This system is not running in the cloud | |
20 | exit 0 | |
21 | fi | |
1c21ebf8 MT |
22 | |
23 | # Find the first interface to use | |
81e1e80e MT |
24 | for i in /sys/class/net/red* /sys/class/net/eth* \ |
25 | /sys/class/net/*; do | |
1c21ebf8 MT |
26 | [ -d "${i}" ] || continue |
27 | i=$(basename ${i}) | |
28 | ||
29 | # Skip loopback | |
30 | [ "${i}" = "lo" ] && continue | |
31 | ||
32 | # Use whatever we have found | |
33 | intf="${i}" | |
34 | break | |
35 | done | |
36 | ||
37 | # Check if we found a network interface | |
38 | if [ ! -n "${intf}" ]; then | |
39 | echo_failure | |
40 | ||
41 | boot_mesg -n "Could not find a network interface" ${FAILURE} | |
42 | boot_mesg "" ${NORMAL} | |
43 | fi | |
44 | ||
bd3bcb45 | 45 | # Run a DHCP client and set up the system accordingly |
b9021f92 | 46 | dhclient -sf "${scriptname}" "${intf}" |
1c21ebf8 | 47 | |
bd3bcb45 | 48 | # End DHCP client immediately |
b9021f92 | 49 | dhclient -sf "${scriptname}" -r "${intf}" &>/dev/null |
ba062943 | 50 | |
c5465a94 MT |
51 | # Rename network devices |
52 | udevadm trigger --action="add" --subsystem-match="net" | |
53 | ||
ba062943 | 54 | exit 0 |
1c21ebf8 MT |
55 | ;; |
56 | ||
57 | status) | |
d035f60c | 58 | # Check Amazon |
1c21ebf8 MT |
59 | if running_on_ec2; then |
60 | echo "This system is running on AWS EC2" | |
61 | exit 0 | |
d035f60c MT |
62 | |
63 | # Check Microsoft | |
64 | elif running_on_azure; then | |
65 | echo "This system is running on Microsoft Azure" | |
66 | exit 0 | |
67 | ||
86c64598 MT |
68 | # Check Google |
69 | elif running_on_gcp; then | |
70 | echo "This system is running on Google Cloud" | |
71 | exit 0 | |
72 | ||
d035f60c | 73 | # The rest |
1c21ebf8 | 74 | else |
d035f60c | 75 | echo "This system is NOT running in the cloud" |
1c21ebf8 MT |
76 | exit 1 |
77 | fi | |
78 | ;; | |
79 | ||
80 | *) | |
81 | echo "Usage: ${0} {start|status}" | |
82 | exit 1 | |
83 | ;; | |
84 | esac | |
85 | ||
ffb37e51 | 86 | # End $rc_base/init.d/cloud-init |