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