Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107853158
D37479.id113512.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D37479.id113512.diff
View Options
diff --git a/libexec/Makefile b/libexec/Makefile
--- a/libexec/Makefile
+++ b/libexec/Makefile
@@ -26,6 +26,7 @@
${_rshd} \
${_rtld-elf} \
save-entropy \
+ ${_nuageinit} \
${_smrsh} \
${_tests} \
${_tftp-proxy} \
@@ -112,6 +113,10 @@
_tests= tests
.endif
+.if ${MK_NUAGEINIT} != "no"
+_nuageinit= nuageinit
+.endif
+
.include <bsd.arch.inc.mk>
.include <bsd.subdir.mk>
diff --git a/libexec/nuageinit/Makefile b/libexec/nuageinit/Makefile
new file mode 100644
--- /dev/null
+++ b/libexec/nuageinit/Makefile
@@ -0,0 +1,6 @@
+#! $FreeBSD$
+
+PACKAGES= nuageinit
+SCRIPTS= nuageinit
+
+.include <bsd.prog.mk>
diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit
new file mode 100755
--- /dev/null
+++ b/libexec/nuageinit/nuageinit
@@ -0,0 +1,140 @@
+#!/usr/libexec/flua
+
+-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+--
+-- Copyright(c) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+-- 1. Redistributions of source code must retain the above copyright
+-- notice, this list of conditions and the following disclaimer.
+-- 2. Redistributions in binary form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+-- SUCH DAMAGE.
+
+-- $FreeBSD$
+
+if #arg ~= 1 then
+ print("Usage ".. arg[0] .." <cloud-init directory>")
+ os.exit(1)
+end
+path = arg[1]
+local ucl = require("ucl")
+
+local parser = ucl.parser()
+local res,err = parser:parse_file(path..'/meta_data.json')
+
+if not res then
+ print("Error parsing meta_data.json: " .. err)
+ os.exit(1)
+end
+local f = io.popen("getent passwd freebsd")
+local pwd = f:read("*a")
+local homedir = '/home/freebsd'
+if pwd:len() == 0 then
+ r = os.execute("pw useradd freebsd -m -M 0755 -w none -n freebsd -G 0 -c 'FreeBSD User' -d '" .. homedir .."' -s '/bin/sh'")
+else
+ homedir = pwd:match("%a+:.+:%d+:%d+:.*:(.*):.*")
+end
+local obj = parser:get_object()
+local sshkeys = obj["public_keys"]
+if sshkeys then
+ for _,v in pairs(sshkeys) do
+ lfs.mkdir("/home/freebsd/.ssh")
+ f = io.open("/home/freebsd/.ssh/authorized_keys", "w+")
+ f:write(v .. "\n")
+ f:close()
+ end
+ os.execute("chown -R freebsd:freebsd /home/freebsd/.ssh")
+end
+local hostname = obj["hostname"]
+if hostname then
+ f = io.open("/etc/rc.conf.d/hostname", "w")
+ f:write("hostname=\""..hostname.."\"\n")
+ f:close()
+end
+
+-- network
+parser = ucl.parser()
+local res,err = parser:parse_file(path..'/network_data.json')
+if not res then
+ print("Error parsing network_data.json: " .. err)
+ os.exit(1)
+end
+obj = parser:get_object()
+
+-- grab ifaces
+local ns = io.popen('netstat -i --libxo json')
+local netres = ns:read("*a")
+ns:close()
+parser = ucl.parser()
+local res,err = parser:parse_string(netres)
+local ifaces = parser:get_object()
+
+local myifaces = {}
+for _,iface in pairs(ifaces["statistics"]["interface"]) do
+ for o in iface["network"]:gmatch("<Link#%d>") do
+ local s = iface["address"]:lower()
+ myifaces[s] = iface["name"]
+ end
+end
+
+local mylinks = {}
+for _,v in pairs(obj["links"]) do
+ local s = v["ethernet_mac_address"]:lower()
+ mylinks[v["id"]] = myifaces[s]
+end
+
+local network = io.open("/etc/rc.conf.d/network", "w")
+local routing = io.open("/etc/rc.conf.d/routing", "w")
+local ipv6 = {}
+for _,v in pairs(obj["networks"]) do
+ if v["type"] == "ipv4_dhcp" then
+ network:write("ifconfig_"..mylinks[v["link"]].."=\"DHCP\"\n")
+ end
+ if v["type"] == "ipv6" then
+ table.insert(ipv6, mylinks[v["link"]])
+ network:write("ifconfig_"..mylinks[v["link"]].."_ipv6=\"inet6 "..v["ip_address"].."\"\n")
+ routing:write("ipv6_defaultrouter=\""..v["gateway"].."\"\n")
+ routing:write("ipv6_route_"..mylinks[v["link"]].."=\""..v["gateway"].." -prefixlen 128 -interface "..mylinks[v["link"]].."\"\n")
+ if v["route"] then
+ for _,r in v["route"] do
+ -- skip all the routes which are already covered by the default gateway, some provider
+ -- still list plenty of them.
+ if v["gateway"] == r["gateway"] then goto next end
+ print("Not implemented yet")
+ os.exit(1)
+ ::next::
+ end
+ end
+ end
+end
+network:write("ipv6_network_interfaces=\"")
+for _,v in pairs(ipv6) do
+ network:write(v.. " ")
+end
+network:write("\"\n")
+routing:write("ipv6_static_routes=\"")
+for _,v in pairs(ipv6) do
+ routing:write(v.. " ")
+end
+routing:write("\"\n")
+network:write("ipv6_default_interface=\""..ipv6[1].."\"\n")
+network:close()
+routing:close()
+local ssh = io.open("/etc/rc.conf.d/sshd", "w+")
+ssh:write("sshd_enable=\"yes\"\n")
+ssh:close()
diff --git a/libexec/rc/rc.d/Makefile b/libexec/rc/rc.d/Makefile
--- a/libexec/rc/rc.d/Makefile
+++ b/libexec/rc/rc.d/Makefile
@@ -296,6 +296,12 @@
SMRCDPACKAGE= sendmail
.endif
+.if ${MK_NUAGEINIT} != "no"
+CONFGROUPS+= NIUAGEINIT
+NIUAGEINIT= nuageinit
+NIUAGEINITPACKAGE= nuageinit
+.endif
+
.if ${MK_UNBOUND} != "no"
CONFGROUPS+= UNBOUND
UNBOUND+= local_unbound
diff --git a/libexec/rc/rc.d/nuageinit b/libexec/rc/rc.d/nuageinit
new file mode 100755
--- /dev/null
+++ b/libexec/rc/rc.d/nuageinit
@@ -0,0 +1,52 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# PROVIDE: nuageinit
+# REQUIRE: mountcritlocal
+# BEFORE: NETWORKING
+# KEYWORD: firstboot
+
+. /etc/rc.subr
+
+name="nuageinit"
+desc="Limited Cloud Init configuration"
+start_cmd="nuageinit_start"
+stop_cmd=":"
+rcvar="nuageinit_enable"
+
+nuageinit_start()
+{
+ # detect cloud init provider
+ # according to the specification of the config drive
+ # it either formatted in vfat or iso9660 and labeled
+ # config-2
+ for f in iso9660 msdosfs; do
+ drive=/dev/$f/config-2
+ if [ -e $drive ]; then
+ break
+ fi
+ unset drive
+ done
+ if [ -z "$drive" ]; then
+ err 1 "Impossible to find a cloud init provider"
+ fi
+ fs=$(fstyp $drive)
+ mkdir -p /media/cloudinit
+ mount -t $fs $drive /media/cloudinit
+ # according to the specification, the content is either
+ # in the openstack or ec2 directory
+ for d in openstack ec2; do
+ dir=/media/cloudinit/$d/latest
+ if [ -d $dir ]; then
+ /usr/libexec/nuageinit $dir
+ break
+ fi
+ done
+ umount /media/cloudinit
+ rmdir /media/cloudinit
+}
+
+load_rc_config $name
+run_rc_command "$1"
diff --git a/share/mk/src.opts.mk b/share/mk/src.opts.mk
--- a/share/mk/src.opts.mk
+++ b/share/mk/src.opts.mk
@@ -152,6 +152,7 @@
NLS_CATALOGS \
NS_CACHING \
NTP \
+ NUAGEINIT \
NVME \
OFED \
OPENSSL \
diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc
--- a/tools/build/mk/OptionalObsoleteFiles.inc
+++ b/tools/build/mk/OptionalObsoleteFiles.inc
@@ -7962,6 +7962,11 @@
OLD_FILES+=var/db/services.db
.endif
+.if ${MK_NUAGEINIT} == no
+OLD_FILES+=etc/rc.d/nuageinit
+OLD_FILES+=usr/libexec/nuageinit
+.endif
+
.if ${MK_SHAREDOCS} == no
OLD_FILES+=usr/share/doc/pjdfstest/README
OLD_DIRS+=usr/share/doc/pjdfstest
diff --git a/tools/build/options/WITHOUT_NUAGEINIT b/tools/build/options/WITHOUT_NUAGEINIT
new file mode 100644
--- /dev/null
+++ b/tools/build/options/WITHOUT_NUAGEINIT
@@ -0,0 +1,2 @@
+.\" $FreeBSD$
+Do not install the limited cloud init support scripts.
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jan 19, 5:52 PM (53 m, 43 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15953469
Default Alt Text
D37479.id113512.diff (7 KB)
Attached To
Mode
D37479: cloudinit: add basic support for cloudinit.
Attached
Detach File
Event Timeline
Log In to Comment