]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/system/cloud-init
284e24d7b9fb4ac93ed95417fa51934faad6306c
[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 elif running_on_gcp; then
17 scriptname="/etc/rc.d/helper/gcp-setup"
18 else
19 # This system is not running in the cloud
20 exit 0
21 fi
22
23 # Find the first interface to use
24 for i in /sys/class/net/red* /sys/class/net/eth* \
25 /sys/class/net/*; do
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
45 # Run a DHCP client and set up the system accordingly
46 dhclient -sf "${scriptname}" "${intf}"
47
48 # End DHCP client immediately
49 dhclient -sf "${scriptname}" -r "${intf}" &>/dev/null
50
51 # Rename network devices
52 udevadm trigger --action="add" --subsystem-match="net"
53
54 exit 0
55 ;;
56
57 status)
58 # Check Amazon
59 if running_on_ec2; then
60 echo "This system is running on AWS EC2"
61 exit 0
62
63 # Check Microsoft
64 elif running_on_azure; then
65 echo "This system is running on Microsoft Azure"
66 exit 0
67
68 # Check Google
69 elif running_on_gcp; then
70 echo "This system is running on Google Cloud"
71 exit 0
72
73 # The rest
74 else
75 echo "This system is NOT running in the cloud"
76 exit 1
77 fi
78 ;;
79
80 *)
81 echo "Usage: ${0} {start|status}"
82 exit 1
83 ;;
84 esac
85
86 # End $rc_base/init.d/cloud-init