]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/system/cloud-init
cloud-init: Move detection functions into initscript function library
[ipfire-2.x.git] / src / initscripts / system / cloud-init
1 #!/bin/sh
2 ########################################################################
3 # Begin $rc_base/init.d/cloud-init
4 ########################################################################
5
6 . /etc/sysconfig/rc
7 . ${rc_functions}
8
9 case "${1}" in
10 start)
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"
16 else
17 # This system is not running in the cloud
18 exit 0
19 fi
20
21 # Find the first interface to use
22 for i in /sys/class/net/red* /sys/class/net/eth* \
23 /sys/class/net/*; do
24 [ -d "${i}" ] || continue
25 i=$(basename ${i})
26
27 # Skip loopback
28 [ "${i}" = "lo" ] && continue
29
30 # Use whatever we have found
31 intf="${i}"
32 break
33 done
34
35 # Check if we found a network interface
36 if [ ! -n "${intf}" ]; then
37 echo_failure
38
39 boot_mesg -n "Could not find a network interface" ${FAILURE}
40 boot_mesg "" ${NORMAL}
41 fi
42
43 # Run a DHCP client and set up the system accordingly
44 dhclient -sf "${scriptname}" "${intf}"
45
46 # End DHCP client immediately
47 dhclient -sf "${scriptname}" -r "${intf}" &>/dev/null
48
49 # Rename network devices
50 udevadm trigger --action="add" --subsystem-match="net"
51
52 exit 0
53 ;;
54
55 status)
56 # Check Amazon
57 if running_on_ec2; then
58 echo "This system is running on AWS EC2"
59 exit 0
60
61 # Check Microsoft
62 elif running_on_azure; then
63 echo "This system is running on Microsoft Azure"
64 exit 0
65
66 # The rest
67 else
68 echo "This system is NOT running in the cloud"
69 exit 1
70 fi
71 ;;
72
73 *)
74 echo "Usage: ${0} {start|status}"
75 exit 1
76 ;;
77 esac
78
79 # End $rc_base/init.d/cloud-init