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