From f4e32130fb582f84f6da1990af12cdb01609732e Mon Sep 17 00:00:00 2001 From: Mark Cilissen Date: Tue, 11 Apr 2023 14:18:08 +0200 Subject: [PATCH] openrc: add openrc-init subpackage --- recipes-init/openrc/openrc/getty.confd | 8 +++ recipes-init/openrc/openrc/getty.initd | 30 ++++++++++ recipes-init/openrc/openrc_0.45.2.bb | 81 ++++++++++++++++++++++++-- 3 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 recipes-init/openrc/openrc/getty.confd create mode 100644 recipes-init/openrc/openrc/getty.initd diff --git a/recipes-init/openrc/openrc/getty.confd b/recipes-init/openrc/openrc/getty.confd new file mode 100644 index 0000000..6eaee5d --- /dev/null +++ b/recipes-init/openrc/openrc/getty.confd @@ -0,0 +1,8 @@ +# Set the baud rate of the terminal line +#baud="" + +# set the terminal type +#term_type="linux" + +# extra options to pass to getty for this port +#getty_options="" diff --git a/recipes-init/openrc/openrc/getty.initd b/recipes-init/openrc/openrc/getty.initd new file mode 100644 index 0000000..adfbe1b --- /dev/null +++ b/recipes-init/openrc/openrc/getty.initd @@ -0,0 +1,30 @@ +#!/sbin/openrc-run + +supervisor=supervise-daemon +port="${RC_SVCNAME#*.}" +term_type="${term_type:-linux}" + +description="getty on terminal $port" +command=/sbin/getty +command_args="${getty_options} ${port} ${baud} ${term_type}" + + +depend() { + after local + keyword -prefix +} + +start_pre() { + if [ "$port" = "$RC_SVCNAME" ]; then + eerror "${RC_SVCNAME} cannot be started directly. You must create" + eerror "symbolic links to it for the ports you want to start" + eerror "getty on and add those to the appropriate runlevels." + return 1 + fi + export EINFO_QUIET=yes +} + +stop_pre() +{ + export EINFO_QUIET=yes +} diff --git a/recipes-init/openrc/openrc_0.45.2.bb b/recipes-init/openrc/openrc_0.45.2.bb index d33df07..13629bc 100644 --- a/recipes-init/openrc/openrc_0.45.2.bb +++ b/recipes-init/openrc/openrc_0.45.2.bb @@ -6,6 +6,8 @@ SRCREV = "3e5420b911922a14dd6b5cc3d2143dc30559caf4" SRC_URI = " \ git://github.com/openrc/openrc.git;nobranch=1;protocol=https \ file://volatiles.initd \ + file://getty.confd \ + file://getty.initd \ " S = "${WORKDIR}/git" @@ -21,17 +23,40 @@ PACKAGECONFIG[selinux] = "-Dselinux=enabled,-Dselinux=disabled,libselinux" PACKAGECONFIG[usrmerge] = "-Drootprefix=/usr,-Drootprefix=/" PACKAGECONFIG[zsh-completions] = "-Dzsh-completions=true,-Dzsh-completions=false" +openrc_sbindir = "${@bb.utils.contains('PACKAGECONFIG', 'usrmerge', '${sbindir}', '${base_sbindir}', d)}" +openrc_libdir = "${@bb.utils.contains('PACKAGECONFIG', 'usrmerge', '${libdir}', '${base_libdir}', d)}" + EXTRA_OEMESON += " \ -Dos=Linux \ -Dpkg_prefix=${prefix} \ + -Dsysvinit=true \ " +USE_VT ?= "1" +SYSVINIT_ENABLED_GETTYS ?= "1" + +add_getty() { + local dev="$1" + local baud="$2" + local term="$3" + ln -snf getty ${D}${OPENRC_INITDIR}/getty.${dev} + ln -snf ${OPENRC_INITDIR}/getty.${dev} ${D}${sysconfdir}/runlevels/default + echo "baud=${baud}" > ${D}${OPENRC_CONFDIR}/getty.${dev} + if [ -n "${term}" ]; then + echo "term_type=${term}" >> ${D}${OPENRC_CONFDIR}/getty.${dev} + fi +} + do_install:append() { # Default sysvinit doesn't do anything with keymaps on a minimal install so # we're not going to either. rm ${D}${sysconfdir}/runlevels/*/keymaps - install -m 755 ${WORKDIR}/volatiles.initd ${D}${OPENRC_INITDIR}/volatiles + for svc in getty volatiles; do + install -m 755 ${WORKDIR}/${svc}.initd ${D}${OPENRC_INITDIR}/${svc} + ! [ -f ${WORKDIR}/${svc}.confd ] || install -m 644 ${WORKDIR}/${svc}.confd ${D}${OPENRC_CONFDIR}/${svc} + sed -i "s|/sbin/openrc-run|${openrc_sbindir}/openrc-run|" ${D}${OPENRC_INITDIR}/${svc} + done ln -snf ${OPENRC_INITDIR}/volatiles ${D}${sysconfdir}/runlevels/boot if ! ${@bb.utils.contains('DISTRO_FEATURES', 'openrc', 'true', 'false', d)}; then @@ -40,13 +65,30 @@ do_install:append() { fi if ${@bb.utils.contains('PACKAGECONFIG', 'usrmerge', 'true', 'false', d)}; then - if [ -f ${D}${base_sbindir}/start-stop-daemon ]; then - mv ${D}${base_sbindir}/start-stop-daemon ${D}${sbindir}/start-stop-daemon.openrc + if [ -f ${D}${openrc_sbindir}/start-stop-daemon ]; then + mv ${D}${openrc_sbindir}/start-stop-daemon ${D}${openrc_sbindir}/start-stop-daemon.openrc fi - sed -i "s|/sbin/openrc-run|${sbindir}/openrc-run|" ${D}${OPENRC_INITDIR}/volatiles + fi + + # Remove bonus TTY scripts installed when -Dsysvinit=true is selected, and add the correct ones. + for x in 1 2 3 4 5 6; do + rm ${D}${OPENRC_INITDIR}/agetty.tty${x} ${D}${sysconfdir}/runlevels/default/agetty.tty${x} + done + consoles="$(echo "${SERIAL_CONSOLES}" | tr ';' ',')" + for entry in ${consoles}; do + dev="$(echo "${entry}" | cut -d, -f2-)" + baud="$(echo "${entry}" | cut -d, -f1)" + add_getty ${dev} ${baud} vt102 + done + if [ "${USE_VT}" = 1 ]; then + for vt in ${SYSVINIT_ENABLED_GETTYS}; do + add_getty "tty${vt}" 38400 + done fi } +PACKAGES =+ "${PN}-init" + RDEPENDS:${PN} = " \ kbd \ ${@bb.utils.contains('DISTRO_FEATURES', 'openrc', 'virtual/openrc-inittab', '', d)} \ @@ -61,12 +103,39 @@ RCONFLICTS:${PN} = " \ init-ifupdown \ modutils-initscripts \ " +RCONFLICTS:${PN}-init = " \ + ${@oe.utils.str_filter_out(d.expand('${PN}-init'), d.getVar('VIRTUAL-RUNTIME_init_manager'), d)} \ +" + +RPROVIDES:${PN}-init = " \ + ${@oe.utils.conditional('VIRTUAL-RUNTIME_init_manager', d.expand('${PN}-init'), 'virtual/openrc-inittab', '', d)} \ +" FILES:${PN}-doc:append = " ${datadir}/${BPN}/support" -FILES:${PN}:append = " ${@bb.utils.contains('PACKAGECONFIG', 'usrmerge', '${libdir}/rc/', '${base_libdir}/rc/', d)}" +FILES:${PN}:append = " ${openrc_libdir}/rc/" +FILES:${PN}-init = " \ + ${openrc_sbindir}/init \ + ${openrc_sbindir}/halt \ + ${openrc_sbindir}/poweroff \ + ${openrc_sbindir}/reboot \ + ${openrc_sbindir}/shutdown \ + ${openrc_sbindir}/openrc-init \ + ${openrc_sbindir}/openrc-shutdown \ + ${OPENRC_CONFDIR}/getty \ + ${OPENRC_CONFDIR}/getty.* \ + ${OPENRC_INITDIR}/getty \ + ${OPENRC_INITDIR}/getty.* \ + ${sysconfdir}/runlevels/default/getty.* \ +" inherit update-alternatives ALTERNATIVE_PRIORITY = "100" ALTERNATIVE:${PN} = "start-stop-daemon" -ALTERNATIVE_LINK_NAME[start-stop-daemon] = "${@bb.utils.contains('PACKAGECONFIG', 'usrmerge', '${sbindir}', '${base_sbindir}', d)}/start-stop-daemon" +ALTERNATIVE:${PN}-init = "init halt poweroff reboot shutdown" +ALTERNATIVE_LINK_NAME[start-stop-daemon] = "${openrc_sbindir}/start-stop-daemon" +ALTERNATIVE_LINK_NAME[init] = "${openrc_sbindir}/init" +ALTERNATIVE_LINK_NAME[halt] = "${openrc_sbindir}/halt" +ALTERNATIVE_LINK_NAME[poweroff] = "${openrc_sbindir}/poweroff" +ALTERNATIVE_LINK_NAME[reboot] = "${openrc_sbindir}/reboot" +ALTERNATIVE_LINK_NAME[shutdown] = "${openrc_sbindir}/shutdown"