xref: /freebsd/libexec/rc/rc.d/nuageinit (revision a91a2465)
1#!/bin/sh
2#
3
4# PROVIDE: nuageinit
5# REQUIRE: mountcritlocal
6# BEFORE: NETWORKING
7# KEYWORD: firstboot
8
9. /etc/rc.subr
10
11name="nuageinit"
12desc="Limited Cloud Init configuration"
13start_cmd="nuageinit_start"
14stop_cmd=":"
15rcvar="nuageinit_enable"
16
17nuageinit_start()
18{
19	local citype
20	# detect cloud init provider
21	# according to the specification of the config drive
22	# it either formatted in vfat or iso9660 and labeled
23	# config-2
24	for f in iso9660 msdosfs; do
25		drive="/dev/$f/[cC][oO][nN][fF][iI][gG]-2"
26		if [ -e $drive ]; then
27			citype=config-2
28			break
29		fi
30		drive="/dev/$f/[cC][iI][dD][aA][tT][aA]"
31		if [ -e $drive ]; then
32			citype=nocloud
33			break
34		fi
35		unset drive
36	done
37	if [ -z "$drive" ]; then
38		# try to detect networked based instance
39		err 1 "Impossible to find a cloud init provider"
40	fi
41	mkdir -p /media/nuageinit
42	fs=$(fstyp $drive)
43	mount -t $fs $drive /media/nuageinit
44	# according to the specification, the content is either
45	# in the openstack or ec2 directory
46	case "$citype" in
47	config-2)
48		for d in openstack ec2; do
49			dir=/media/nuageinit/$d/latest
50			if [ -d $dir ]; then
51				/usr/libexec/nuageinit $dir $citype
52				break
53			fi
54		done
55		;;
56	nocloud)
57		/usr/libexec/nuageinit /media/nuageinit $citype
58		;;
59	esac
60	if [ -n "$drive" ]; then
61		umount /media/nuageinit
62	fi
63	rmdir /media/nuageinit
64}
65
66load_rc_config $name
67run_rc_command "$1"
68