mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-09 18:45:54 +02:00
Add initscript that automatically configures IPFire on AWS EC2
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
@@ -5,6 +5,7 @@ etc/rc.d/helper/getdnsfromdhcpc.pl
|
||||
#etc/rc.d/init.d
|
||||
etc/rc.d/init.d/acpid
|
||||
etc/rc.d/init.d/apache
|
||||
etc/rc.d/init.d/aws
|
||||
etc/rc.d/init.d/beep
|
||||
etc/rc.d/init.d/checkfs
|
||||
etc/rc.d/init.d/cleanfs
|
||||
@@ -184,6 +185,7 @@ etc/rc.d/rcsysinit.d/S50cleanfs
|
||||
etc/rc.d/rcsysinit.d/S60setclock
|
||||
etc/rc.d/rcsysinit.d/S70console
|
||||
etc/rc.d/rcsysinit.d/S73swconfig
|
||||
etc/rc.d/rcsysinit.d/S74aws
|
||||
etc/rc.d/rcsysinit.d/S75firstsetup
|
||||
etc/rc.d/rcsysinit.d/S80localnet
|
||||
etc/rc.d/rcsysinit.d/S81pakfire
|
||||
|
||||
@@ -5,6 +5,7 @@ etc/rc.d/helper/getdnsfromdhcpc.pl
|
||||
#etc/rc.d/init.d
|
||||
etc/rc.d/init.d/acpid
|
||||
etc/rc.d/init.d/apache
|
||||
etc/rc.d/init.d/aws
|
||||
etc/rc.d/init.d/beep
|
||||
etc/rc.d/init.d/checkfs
|
||||
etc/rc.d/init.d/cleanfs
|
||||
@@ -184,6 +185,7 @@ etc/rc.d/rcsysinit.d/S50cleanfs
|
||||
etc/rc.d/rcsysinit.d/S60setclock
|
||||
etc/rc.d/rcsysinit.d/S70console
|
||||
etc/rc.d/rcsysinit.d/S73swconfig
|
||||
etc/rc.d/rcsysinit.d/S74aws
|
||||
etc/rc.d/rcsysinit.d/S75firstsetup
|
||||
etc/rc.d/rcsysinit.d/S80localnet
|
||||
etc/rc.d/rcsysinit.d/S81pakfire
|
||||
|
||||
@@ -5,6 +5,7 @@ etc/rc.d/helper/getdnsfromdhcpc.pl
|
||||
#etc/rc.d/init.d
|
||||
etc/rc.d/init.d/acpid
|
||||
etc/rc.d/init.d/apache
|
||||
etc/rc.d/init.d/aws
|
||||
etc/rc.d/init.d/beep
|
||||
etc/rc.d/init.d/checkfs
|
||||
etc/rc.d/init.d/cleanfs
|
||||
@@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S45udev_retry
|
||||
etc/rc.d/rcsysinit.d/S50cleanfs
|
||||
etc/rc.d/rcsysinit.d/S60setclock
|
||||
etc/rc.d/rcsysinit.d/S70console
|
||||
etc/rc.d/rcsysinit.d/S74aws
|
||||
etc/rc.d/rcsysinit.d/S75firstsetup
|
||||
etc/rc.d/rcsysinit.d/S80localnet
|
||||
etc/rc.d/rcsysinit.d/S81pakfire
|
||||
|
||||
@@ -5,6 +5,7 @@ etc/rc.d/helper/getdnsfromdhcpc.pl
|
||||
#etc/rc.d/init.d
|
||||
etc/rc.d/init.d/acpid
|
||||
etc/rc.d/init.d/apache
|
||||
etc/rc.d/init.d/aws
|
||||
etc/rc.d/init.d/beep
|
||||
etc/rc.d/init.d/checkfs
|
||||
etc/rc.d/init.d/cleanfs
|
||||
@@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S45udev_retry
|
||||
etc/rc.d/rcsysinit.d/S50cleanfs
|
||||
etc/rc.d/rcsysinit.d/S60setclock
|
||||
etc/rc.d/rcsysinit.d/S70console
|
||||
etc/rc.d/rcsysinit.d/S74aws
|
||||
etc/rc.d/rcsysinit.d/S75firstsetup
|
||||
etc/rc.d/rcsysinit.d/S80localnet
|
||||
etc/rc.d/rcsysinit.d/S81pakfire
|
||||
|
||||
@@ -173,6 +173,7 @@ $(TARGET) :
|
||||
ln -sf ../init.d/setclock /etc/rc.d/rc0.d/K47setclock
|
||||
ln -sf ../init.d/setclock /etc/rc.d/rc6.d/K47setclock
|
||||
ln -sf ../init.d/console /etc/rc.d/rcsysinit.d/S70console
|
||||
ln -sf ../init.d/aws /etc/rc.d/rcsysinit.d/S74aws
|
||||
ln -sf ../init.d/firstsetup /etc/rc.d/rcsysinit.d/S75firstsetup
|
||||
ln -sf ../init.d/localnet /etc/rc.d/rcsysinit.d/S80localnet
|
||||
ln -sf ../init.d/pakfire /etc/rc.d/rcsysinit.d/S81pakfire
|
||||
|
||||
103
src/initscripts/system/aws
Normal file
103
src/initscripts/system/aws
Normal file
@@ -0,0 +1,103 @@
|
||||
#!/bin/sh
|
||||
########################################################################
|
||||
# Begin $rc_base/init.d/aws
|
||||
########################################################################
|
||||
|
||||
. /etc/sysconfig/rc
|
||||
. ${rc_functions}
|
||||
|
||||
MD_URL="http://169.254.169.254/latest/meta-data"
|
||||
|
||||
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html
|
||||
running_on_ec2() {
|
||||
local uuid
|
||||
|
||||
# Check if the hypervisor UUID starts with ec2
|
||||
if [ -r "/sys/hypervisor/uuid" ]; then
|
||||
uuid=$(</sys/hypervisor/uuid)
|
||||
|
||||
[ "${uuid:0:3}" = "ec2" ] && return 0
|
||||
fi
|
||||
|
||||
# Check if the DMI product UUID starts with EC2
|
||||
if [ -r "/sys/devices/virtual/dmi/id/product_uuid" ]; then
|
||||
uuid=$(</sys/devices/virtual/dmi/id/product_uuid)
|
||||
|
||||
[ "${uuid:0:3}" = "EC2" ] && return 0
|
||||
fi
|
||||
|
||||
# We are not running on AWS EC2
|
||||
return 1
|
||||
}
|
||||
|
||||
case "${1}" in
|
||||
start)
|
||||
# Do nothing if we are not running on AWS EC2
|
||||
running_on_ec2 || exit 0
|
||||
|
||||
boot_mesg "Setting up system to run on AWS EC2..."
|
||||
|
||||
# Find the first interface to use
|
||||
for i in /sys/class/net/*; do
|
||||
[ -d "${i}" ] || continue
|
||||
i=$(basename ${i})
|
||||
|
||||
# Skip loopback
|
||||
[ "${i}" = "lo" ] && continue
|
||||
|
||||
# Use whatever we have found
|
||||
intf="${i}"
|
||||
break
|
||||
done
|
||||
|
||||
# Check if we found a network interface
|
||||
if [ ! -n "${intf}" ]; then
|
||||
echo_failure
|
||||
|
||||
boot_mesg -n "Could not find a network interface" ${FAILURE}
|
||||
boot_mesg "" ${NORMAL}
|
||||
fi
|
||||
|
||||
# Assign ourselves an IP address to communicate with the meta-data service
|
||||
ip addr add 169.254.169.1/24 dev "${intf}"
|
||||
ip link set "${intf}" up
|
||||
|
||||
# Initialise system settings
|
||||
if [ ! -s "/var/ipfire/main/settings" ]; then
|
||||
hostname=$(curl ${MD_URL}/local-hostname)
|
||||
|
||||
(
|
||||
echo "HOSTNAME=${hostname%%.*}"
|
||||
echo "DOMAINNAME=${hostname#*.}"
|
||||
echo "THEME=ipfire"
|
||||
echo "LANGUAGE=en"
|
||||
echo "KEYMAP=/lib/kbd/keymaps/i386/qwerty/us.map.gz"
|
||||
echo "TIMEZONE=/usr/share/zoneinfo/posix/UTC"
|
||||
) > /var/ipfire/main/settings
|
||||
fi
|
||||
|
||||
# Remove any IP addresses
|
||||
ip addr flush dev "${intf}"
|
||||
echo_ok
|
||||
|
||||
# This script has now completed the first steps of setup
|
||||
touch /var/ipfire/main/firstsetup_ok
|
||||
;;
|
||||
|
||||
status)
|
||||
if running_on_ec2; then
|
||||
echo "This system is running on AWS EC2"
|
||||
exit 0
|
||||
else
|
||||
echo "This system is NOT running on AWS EC2"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: ${0} {start|status}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# End $rc_base/init.d/aws
|
||||
Reference in New Issue
Block a user