]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - libexec/rc/rc.d/nuageinit
nuageinit: add basic support for cloudinit.
[FreeBSD/FreeBSD.git] / libexec / rc / rc.d / nuageinit
1 #!/bin/sh
2 #
3
4 # PROVIDE: nuageinit
5 # REQUIRE: mountcritlocal
6 # BEFORE: NETWORKING
7 # KEYWORD: firstboot
8
9 . /etc/rc.subr
10
11 name="nuageinit"
12 desc="Limited Cloud Init configuration"
13 start_cmd="nuageinit_start"
14 stop_cmd=":"
15 rcvar="nuageinit_enable"
16
17 nuageinit_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/config-2
26                 if [ -e $drive ]; then
27                         citype=config-2
28                         break
29                 fi
30                 drive=/dev/$f/cidata
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
66 load_rc_config $name
67 run_rc_command "$1"