blob: 582d87949e9425539839078e7073c34a456a9690 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001SUMMARY = "Tiny versions of many common UNIX utilities in a single small executable"
2DESCRIPTION = "BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides minimalist replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete POSIX environment for any small or embedded system."
Andrew Geissler82c905d2020-04-13 13:39:40 -05003HOMEPAGE = "https://www.busybox.net"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004BUGTRACKER = "https://bugs.busybox.net/"
5
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08006DEPENDS += "kern-tools-native virtual/crypt"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007
Andrew Geissler6ce62a22020-11-30 19:58:47 -06008# bzip2 applet in busybox is based on lightly-modified bzip2-1.0.4 source
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009# the GPL is version 2 only
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000010LICENSE = "GPL-2.0-only & bzip2-1.0.4"
Andrew Geissler6ce62a22020-11-30 19:58:47 -060011LIC_FILES_CHKSUM = "file://LICENSE;md5=de10de48642ab74318e893a61105afbb \
12 file://archival/libarchive/bz/LICENSE;md5=28e3301eae987e8cfe19988e98383dae"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013
14SECTION = "base"
15
16# Whether to split the suid apps into a seperate binary
17BUSYBOX_SPLIT_SUID ?= "1"
18
19export EXTRA_CFLAGS = "${CFLAGS}"
20export EXTRA_LDFLAGS = "${LDFLAGS}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050021
Patrick Williamsc0f7c042017-02-23 20:41:17 -060022EXTRA_OEMAKE = "CC='${CC}' LD='${CCLD}' V=1 ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_PREFIX} SKIP_STRIP=y HOSTCC='${BUILD_CC}' HOSTCPP='${BUILD_CPP}'"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023
24PACKAGES =+ "${PN}-httpd ${PN}-udhcpd ${PN}-udhcpc ${PN}-syslog ${PN}-mdev ${PN}-hwclock"
25
Patrick Williams213cb262021-08-07 19:21:33 -050026FILES:${PN}-httpd = "${sysconfdir}/init.d/busybox-httpd /srv/www"
Andrew Geissler5199d832021-09-24 16:47:35 -050027FILES:${PN}-syslog = "${sysconfdir}/init.d/syslog* ${sysconfdir}/syslog-startup.conf* ${sysconfdir}/syslog.conf* ${systemd_system_unitdir}/syslog.service ${sysconfdir}/default/busybox-syslog"
Patrick Williams213cb262021-08-07 19:21:33 -050028FILES:${PN}-mdev = "${sysconfdir}/init.d/mdev ${sysconfdir}/mdev.conf ${sysconfdir}/mdev/*"
29FILES:${PN}-udhcpd = "${sysconfdir}/init.d/busybox-udhcpd"
30FILES:${PN}-udhcpc = "${sysconfdir}/udhcpc.d ${datadir}/udhcpc"
31FILES:${PN}-hwclock = "${sysconfdir}/init.d/hwclock.sh"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032
33INITSCRIPT_PACKAGES = "${PN}-httpd ${PN}-syslog ${PN}-udhcpd ${PN}-mdev ${PN}-hwclock"
34
Patrick Williams213cb262021-08-07 19:21:33 -050035INITSCRIPT_NAME:${PN}-httpd = "busybox-httpd"
36INITSCRIPT_NAME:${PN}-hwclock = "hwclock.sh"
Patrick Williams8e7b46e2023-05-01 14:19:06 -050037INITSCRIPT_PARAMS:${PN}-hwclock = "start 40 S . stop 20 0 1 6 ."
Patrick Williams213cb262021-08-07 19:21:33 -050038INITSCRIPT_NAME:${PN}-mdev = "mdev"
39INITSCRIPT_PARAMS:${PN}-mdev = "start 04 S ."
40INITSCRIPT_NAME:${PN}-syslog = "syslog"
41INITSCRIPT_NAME:${PN}-udhcpd = "busybox-udhcpd"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042
43SYSTEMD_PACKAGES = "${PN}-syslog"
Patrick Williams213cb262021-08-07 19:21:33 -050044SYSTEMD_SERVICE:${PN}-syslog = "${@bb.utils.contains('SRC_URI', 'file://syslog.cfg', 'busybox-syslog.service', '', d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045
Patrick Williams213cb262021-08-07 19:21:33 -050046RDEPENDS:${PN}-syslog = "busybox"
47CONFFILES:${PN}-syslog = "${sysconfdir}/syslog-startup.conf"
48RCONFLICTS:${PN}-syslog = "rsyslog sysklogd syslog-ng"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050049
Patrick Williams213cb262021-08-07 19:21:33 -050050CONFFILES:${PN}-mdev = "${sysconfdir}/mdev.conf"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051
Patrick Williams213cb262021-08-07 19:21:33 -050052RRECOMMENDS:${PN} = "${PN}-udhcpc"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053
Patrick Williams213cb262021-08-07 19:21:33 -050054RDEPENDS:${PN} = "${@["", "busybox-inittab"][(d.getVar('VIRTUAL-RUNTIME_init_manager') == 'busybox')]}"
Brad Bishop00111322018-04-01 22:23:53 -040055
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056inherit cml1 systemd update-rc.d ptest
57
Brad Bishop19323692019-04-05 15:28:33 -040058# busybox's unzip test case needs zip command, which busybox itself does not provide
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050059RDEPENDS:${PN}-ptest = "zip coreutils"
Brad Bishop19323692019-04-05 15:28:33 -040060
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061# internal helper
62def busybox_cfg(feature, tokens, cnf, rem):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130063 if type(tokens) == type(""):
64 tokens = [tokens]
65 rem.extend(['/^[# ]*' + token + '[ =]/d' for token in tokens])
66 if feature:
67 cnf.extend([token + '=y' for token in tokens])
68 else:
69 cnf.extend(['# ' + token + ' is not set' for token in tokens])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070
71# Map distro features to config settings
72def features_to_busybox_settings(d):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130073 cnf, rem = ([], [])
74 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IPV6', cnf, rem)
75 busybox_cfg(True, 'CONFIG_LFS', cnf, rem)
76 busybox_cfg(True, 'CONFIG_FDISK_SUPPORT_LARGE_DISKS', cnf, rem)
77 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'nls', True, False, d), 'CONFIG_LOCALE_SUPPORT', cnf, rem)
78 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv4', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV4', cnf, rem)
79 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV6', cnf, rem)
Brad Bishop19323692019-04-05 15:28:33 -040080 busybox_cfg(bb.utils.contains_any('DISTRO_FEATURES', 'bluetooth wifi', True, False, d), 'CONFIG_RFKILL', cnf, rem)
Brad Bishopa5c52ff2018-11-23 10:55:50 +130081 return "\n".join(cnf), "\n".join(rem)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082
Brad Bishopd7bf8c12018-02-25 22:55:05 -050083# X, Y = ${@features_to_busybox_settings(d)}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084# unfortunately doesn't seem to work with bitbake, workaround:
85def features_to_busybox_conf(d):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130086 cnf, rem = features_to_busybox_settings(d)
87 return cnf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088def features_to_busybox_del(d):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130089 cnf, rem = features_to_busybox_settings(d)
90 return rem
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050092configmangle = '/CONFIG_EXTRA_CFLAGS/d; \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050093 '
94OE_FEATURES := "${@features_to_busybox_conf(d)}"
95OE_DEL := "${@features_to_busybox_del(d)}"
96DO_IPv4 := "${@bb.utils.contains('DISTRO_FEATURES', 'ipv4', 1, 0, d)}"
97DO_IPv6 := "${@bb.utils.contains('DISTRO_FEATURES', 'ipv6', 1, 0, d)}"
98
99python () {
100 if "${OE_DEL}":
Patrick Williams213cb262021-08-07 19:21:33 -0500101 d.setVar('configmangle:append', "${OE_DEL}" + "\n")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102 if "${OE_FEATURES}":
Patrick Williams213cb262021-08-07 19:21:33 -0500103 d.setVar('configmangle:append',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104 "/^### DISTRO FEATURES$/a\\\n%s\n\n" %
105 ("\\n".join((d.expand("${OE_FEATURES}").split("\n")))))
Patrick Williams213cb262021-08-07 19:21:33 -0500106 d.setVar('configmangle:append',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 "/^### CROSS$/a\\\n%s\n" %
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500108 ("\\n".join(["CONFIG_EXTRA_CFLAGS=\"${CFLAGS} ${HOST_CC_ARCH}\""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109 ])
110 ))
111}
112
113do_prepare_config () {
Andrew Geisslereff27472021-10-29 15:35:00 -0500114 export KCONFIG_NOTIMESTAMP=1
115
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500116 sed -e '/CONFIG_STATIC/d' \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117 < ${WORKDIR}/defconfig > ${S}/.config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500118 echo "# CONFIG_STATIC is not set" >> .config
119 for i in 'CROSS' 'DISTRO FEATURES'; do echo "### $i"; done >> \
120 ${S}/.config
121 sed -i -e '${configmangle}' ${S}/.config
122 if test ${DO_IPv4} -eq 0 && test ${DO_IPv6} -eq 0; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800123 # disable networking applets
124 mv ${S}/.config ${S}/.config.oe-tmp
125 awk 'BEGIN{net=0}
126 /^# Networking Utilities/{net=1}
127 /^#$/{if(net){net=net+1}}
128 {if(net==2&&$0 !~ /^#/&&$1){print("# "$1" is not set")}else{print}}' \
129 ${S}/.config.oe-tmp > ${S}/.config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 fi
131 sed -i 's/CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -n"/CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -b"/' ${S}/.config
Brad Bishopa34c0302019-09-23 22:34:48 -0400132 if [ -n "${DEBUG_PREFIX_MAP}" ]; then
133 sed -i 's|${DEBUG_PREFIX_MAP}||g' ${S}/.config
134 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135}
136
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500137do_configure () {
Brad Bishopa34c0302019-09-23 22:34:48 -0400138 set -x
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139 do_prepare_config
140 merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
141 cml1_do_configure
Andrew Geissler517393d2023-01-13 08:55:19 -0600142
143 # Save a copy of .config and autoconf.h.
144 cp .config .config.orig
145 cp include/autoconf.h include/autoconf.h.orig
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500146}
147
148do_compile() {
149 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
Andrew Geisslereff27472021-10-29 15:35:00 -0500150 export KCONFIG_NOTIMESTAMP=1
151
Andrew Geissler517393d2023-01-13 08:55:19 -0600152 # Ensure we start do_compile with the original .config and autoconf.h.
153 # These files should always have matching timestamps.
154 cp .config.orig .config
155 cp include/autoconf.h.orig include/autoconf.h
156
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157 if [ "${BUSYBOX_SPLIT_SUID}" = "1" -a x`grep "CONFIG_FEATURE_INDIVIDUAL=y" .config` = x ]; then
Andrew Geissler517393d2023-01-13 08:55:19 -0600158 # Guard againt interrupted do_compile: clean temporary files.
159 rm -f .config.app.suid .config.app.nosuid .config.disable.apps .config.nonapps
160
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800161 # split the .config into two parts, and make two busybox binaries
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500162 oe_runmake busybox.cfg.suid
163 oe_runmake busybox.cfg.nosuid
Brad Bishop316dfdd2018-06-25 12:45:53 -0400164
165 # workaround for suid bug 10346
166 if ! grep -q "CONFIG_SH_IS_NONE" busybox.cfg.nosuid; then
167 echo "CONFIG_SH_IS_NONE" >> busybox.cfg.suid
168 fi
169
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500170 for i in `cat busybox.cfg.suid busybox.cfg.nosuid`; do
171 echo "# $i is not set" >> .config.disable.apps
172 done
173 merge_config.sh -m .config.orig .config.disable.apps
174 cp .config .config.nonapps
175 for s in suid nosuid; do
176 cat busybox.cfg.$s | while read item; do
177 grep -w "$item" .config.orig
178 done > .config.app.$s
Brad Bishop316dfdd2018-06-25 12:45:53 -0400179
180 # workaround for suid bug 10346
181 if [ "$s" = "suid" ] ; then
182 sed "s/.*CONFIG_SH_IS_NONE.*$/CONFIG_SH_IS_NONE=y/" -i .config.app.suid
183 fi
184
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500185 merge_config.sh -m .config.nonapps .config.app.$s
186 oe_runmake busybox_unstripped
187 mv busybox_unstripped busybox.$s
188 oe_runmake busybox.links
Brad Bishope2d5b612018-11-23 10:55:50 +1300189 sort busybox.links > busybox.links.$s
190 rm busybox.links
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191 done
Brad Bishop316dfdd2018-06-25 12:45:53 -0400192
193 # hard fail if sh is being linked to the suid busybox (detects bug 10346)
194 if grep -q -x "/bin/sh" busybox.links.suid; then
195 bbfatal "busybox suid binary incorrectly provides /bin/sh"
196 fi
197
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500198 # cleanup
Andrew Geissler517393d2023-01-13 08:55:19 -0600199 rm .config.app.suid .config.app.nosuid .config.disable.apps .config.nonapps
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200 else
201 oe_runmake busybox_unstripped
202 cp busybox_unstripped busybox
203 oe_runmake busybox.links
204 fi
Andrew Geissler517393d2023-01-13 08:55:19 -0600205
206 # restore original .config and autoconf.h, because the install process
207 # may check these files
208 cp .config.orig .config
209 cp include/autoconf.h.orig include/autoconf.h
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500210}
211
212do_install () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500213 sed -i "s:^/bin/:BASE_BINDIR/:" busybox.links*
214 sed -i "s:^/sbin/:BASE_SBINDIR/:" busybox.links*
215 sed -i "s:^/usr/bin/:BINDIR/:" busybox.links*
216 sed -i "s:^/usr/sbin/:SBINDIR/:" busybox.links*
217
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800218 # Move arch/link to BINDIR to match coreutils
219 sed -i "s:^BASE_BINDIR/arch:BINDIR/arch:" busybox.links*
220 sed -i "s:^BASE_BINDIR/link:BINDIR/link:" busybox.links*
221
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500222 sed -i "s:^BASE_BINDIR/:${base_bindir}/:" busybox.links*
223 sed -i "s:^BASE_SBINDIR/:${base_sbindir}/:" busybox.links*
224 sed -i "s:^BINDIR/:${bindir}/:" busybox.links*
225 sed -i "s:^SBINDIR/:${sbindir}/:" busybox.links*
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500226
227 install -d ${D}${sysconfdir}/init.d
228
229 if ! grep -q "CONFIG_FEATURE_INDIVIDUAL=y" ${B}/.config; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500230 # Install ${base_bindir}/busybox, and the ${base_bindir}/sh link so the postinst script
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231 # can run. Let update-alternatives handle the rest.
232 install -d ${D}${base_bindir}
233 if [ "${BUSYBOX_SPLIT_SUID}" = "1" ]; then
234 install -m 4755 ${B}/busybox.suid ${D}${base_bindir}
235 install -m 0755 ${B}/busybox.nosuid ${D}${base_bindir}
236 install -m 0644 ${S}/busybox.links.suid ${D}${sysconfdir}
237 install -m 0644 ${S}/busybox.links.nosuid ${D}${sysconfdir}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400238 if grep -q "CONFIG_SH_IS_ASH=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239 ln -sf busybox.nosuid ${D}${base_bindir}/sh
240 fi
241 # Keep a default busybox for people who want to invoke busybox directly.
242 # This is also useful for the on device upgrade. Because we want
243 # to use the busybox command in postinst.
244 ln -sf busybox.nosuid ${D}${base_bindir}/busybox
245 else
246 if grep -q "CONFIG_FEATURE_SUID=y" ${B}/.config; then
247 install -m 4755 ${B}/busybox ${D}${base_bindir}
248 else
249 install -m 0755 ${B}/busybox ${D}${base_bindir}
250 fi
251 install -m 0644 ${S}/busybox.links ${D}${sysconfdir}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400252 if grep -q "CONFIG_SH_IS_ASH=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500253 ln -sf busybox ${D}${base_bindir}/sh
254 fi
255 # We make this symlink here to eliminate the error when upgrading together
256 # with busybox-syslog. Without this symlink, the opkg may think of the
257 # busybox.nosuid as obsolete and remove it, resulting in dead links like
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500258 # ${base_bindir}/sed -> ${base_bindir}/busybox.nosuid. This will make upgrading busybox-syslog fail.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500259 # This symlink will be safely deleted in postinst, thus no negative effect.
260 ln -sf busybox ${D}${base_bindir}/busybox.nosuid
261 fi
262 else
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800263 install -d ${D}${base_bindir} ${D}${bindir} ${D}${libdir}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500264 cat busybox.links | while read FILE; do
265 NAME=`basename "$FILE"`
266 install -m 0755 "0_lib/$NAME" "${D}$FILE.${BPN}"
267 done
268 # add suid bit where needed
269 for i in `grep -E "APPLET.*BB_SUID_((MAYBE|REQUIRE))" include/applets.h | grep -v _BB_SUID_DROP | cut -f 3 -d '(' | cut -f 1 -d ','`; do
270 find ${D} -name $i.${BPN} -exec chmod a+s {} \;
271 done
272 install -m 0755 0_lib/libbusybox.so.${PV} ${D}${libdir}/libbusybox.so.${PV}
273 ln -sf sh.${BPN} ${D}${base_bindir}/sh
274 ln -sf ln.${BPN} ${D}${base_bindir}/ln
275 ln -sf test.${BPN} ${D}${bindir}/test
276 if [ -f ${D}/linuxrc.${BPN} ]; then
277 mv ${D}/linuxrc.${BPN} ${D}/linuxrc
278 fi
279 install -m 0644 ${S}/busybox.links ${D}${sysconfdir}
280 fi
281
282 if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500283 install -m 0755 ${WORKDIR}/syslog ${D}${sysconfdir}/init.d/syslog
284 install -m 644 ${WORKDIR}/syslog-startup.conf ${D}${sysconfdir}/syslog-startup.conf
285 install -m 644 ${WORKDIR}/syslog.conf ${D}${sysconfdir}/syslog.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500286 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800287 if grep -q "CONFIG_CROND=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288 install -m 0755 ${WORKDIR}/busybox-cron ${D}${sysconfdir}/init.d/
289 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800290 if grep -q "CONFIG_HTTPD=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500291 install -m 0755 ${WORKDIR}/busybox-httpd ${D}${sysconfdir}/init.d/
292 install -d ${D}/srv/www
293 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800294 if grep -q "CONFIG_UDHCPD=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500295 install -m 0755 ${WORKDIR}/busybox-udhcpd ${D}${sysconfdir}/init.d/
296 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800297 if grep -q "CONFIG_HWCLOCK=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298 install -m 0755 ${WORKDIR}/hwclock.sh ${D}${sysconfdir}/init.d/
299 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800300 if grep -q "CONFIG_UDHCPC=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500301 install -d ${D}${sysconfdir}/udhcpc.d
302 install -d ${D}${datadir}/udhcpc
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500303 install -m 0755 ${WORKDIR}/simple.script ${D}${sysconfdir}/udhcpc.d/50default
304 sed -i "s:/SBIN_DIR/:${base_sbindir}/:" ${D}${sysconfdir}/udhcpc.d/50default
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500305 install -m 0755 ${WORKDIR}/default.script ${D}${datadir}/udhcpc/default.script
306 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800307 if grep -q "CONFIG_INETD=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500308 install -m 0755 ${WORKDIR}/inetd ${D}${sysconfdir}/init.d/inetd.${BPN}
309 sed -i "s:/usr/sbin/:${sbindir}/:" ${D}${sysconfdir}/init.d/inetd.${BPN}
310 install -m 0644 ${WORKDIR}/inetd.conf ${D}${sysconfdir}/
311 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800312 if grep -q "CONFIG_MDEV=y" ${B}/.config; then
313 install -m 0755 ${WORKDIR}/mdev ${D}${sysconfdir}/init.d/mdev
314 if grep "CONFIG_FEATURE_MDEV_CONF=y" ${B}/.config; then
315 install -m 644 ${WORKDIR}/mdev.conf ${D}${sysconfdir}/mdev.conf
316 install -d ${D}${sysconfdir}/mdev
317 install -m 0755 ${WORKDIR}/find-touchscreen.sh ${D}${sysconfdir}/mdev
318 install -m 0755 ${WORKDIR}/mdev-mount.sh ${D}${sysconfdir}/mdev
319 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500320 fi
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600321 if grep -q "CONFIG_INIT=y" ${B}/.config && ${@bb.utils.contains('VIRTUAL-RUNTIME_init_manager','busybox','true','false',d)}; then
Brad Bishopa34c0302019-09-23 22:34:48 -0400322 install -D -m 0755 ${WORKDIR}/rcS ${D}${sysconfdir}/init.d/rcS
323 install -D -m 0755 ${WORKDIR}/rcK ${D}${sysconfdir}/init.d/rcK
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600324 install -D -m 0755 ${WORKDIR}/rcS.default ${D}${sysconfdir}/default/rcS
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800325 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500326
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800327 if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
328 if grep -q "CONFIG_KLOGD=y" ${B}/.config; then
Andrew Geissler5199d832021-09-24 16:47:35 -0500329 install -d ${D}${systemd_system_unitdir}
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800330 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-klogd.service.in \
Andrew Geissler5199d832021-09-24 16:47:35 -0500331 > ${D}${systemd_system_unitdir}/busybox-klogd.service
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800332 fi
Brad Bishopbba38f32018-08-23 16:11:46 +0800333
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800334 if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
Andrew Geissler5199d832021-09-24 16:47:35 -0500335 install -d ${D}${systemd_system_unitdir}
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800336 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-syslog.service.in \
Andrew Geissler5199d832021-09-24 16:47:35 -0500337 > ${D}${systemd_system_unitdir}/busybox-syslog.service
338 if [ ! -e ${D}${systemd_system_unitdir}/busybox-klogd.service ] ; then
339 sed -i '/klog/d' ${D}${systemd_system_unitdir}/busybox-syslog.service
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800340 fi
341 if [ -f ${WORKDIR}/busybox-syslog.default ] ; then
342 install -d ${D}${sysconfdir}/default
343 install -m 0644 ${WORKDIR}/busybox-syslog.default ${D}${sysconfdir}/default/busybox-syslog
344 fi
345 fi
346 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500347
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800348 # Remove the sysvinit specific configuration file for systemd systems to avoid confusion
349 if ${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'false', 'true', d)}; then
350 rm -f ${D}${sysconfdir}/syslog-startup.conf
351 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500352}
353
Brad Bishopc342db32019-05-15 21:57:59 -0400354PTEST_BINDIR = "1"
355
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500356do_install_ptest () {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800357 cp -r ${B}/testsuite ${D}${PTEST_PATH}/
Andrew Geissler82c905d2020-04-13 13:39:40 -0500358 # These access the internet which is not guaranteed to work on machines running the tests
359 rm -rf ${D}${PTEST_PATH}/testsuite/wget
360 sort ${B}/.config > ${D}${PTEST_PATH}/.config
Patrick Williams03907ee2022-05-01 06:28:52 -0500361 ln -s ${base_bindir}/busybox ${D}${PTEST_PATH}/busybox
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500362}
363
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500364inherit update-alternatives
365
366ALTERNATIVE_PRIORITY = "50"
367
Patrick Williams213cb262021-08-07 19:21:33 -0500368python do_package:prepend () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500369 # We need to load the full set of busybox provides from the /etc/busybox.links
370 # Use this to see the update-alternatives with the right information
371
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500372 dvar = d.getVar('D')
373 pn = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500374 def set_alternative_vars(links, target):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500375 links = d.expand(links)
376 target = d.expand(target)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500377 f = open('%s%s' % (dvar, links), 'r')
378 for alt_link_name in f:
379 alt_link_name = alt_link_name.strip()
380 alt_name = os.path.basename(alt_link_name)
381 # Match coreutils
382 if alt_name == '[':
383 alt_name = 'lbracket'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800384 if alt_name == 'klogd' or alt_name == 'syslogd':
Patrick Williams213cb262021-08-07 19:21:33 -0500385 d.appendVar('ALTERNATIVE:%s-syslog' % (pn), ' ' + alt_name)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800386 else:
Patrick Williams213cb262021-08-07 19:21:33 -0500387 d.appendVar('ALTERNATIVE:%s' % (pn), ' ' + alt_name)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500388 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name)
389 if os.path.exists('%s%s' % (dvar, target)):
390 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, target)
391 f.close()
392 return
393
394 if os.path.exists('%s/etc/busybox.links' % (dvar)):
395 set_alternative_vars("${sysconfdir}/busybox.links", "${base_bindir}/busybox")
396 else:
397 set_alternative_vars("${sysconfdir}/busybox.links.nosuid", "${base_bindir}/busybox.nosuid")
398 set_alternative_vars("${sysconfdir}/busybox.links.suid", "${base_bindir}/busybox.suid")
399}
400
Brad Bishop96ff1982019-08-19 13:50:42 -0400401# This part of code is dedicated to the on target upgrade problem. It's known
402# that if we don't make appropriate symlinks before update-alternatives calls,
403# there will be errors indicating missing commands such as 'sed'.
404# These symlinks will later be updated by update-alternatives calls.
405# The update-alternatives.bbclass' postinst script runs firstly before other
406# postinst, but this part of code needs run firstly, so add this funtion.
Patrick Williams213cb262021-08-07 19:21:33 -0500407python populate_packages_updatealternatives:append() {
Brad Bishop96ff1982019-08-19 13:50:42 -0400408 postinst = """
409test -n 2 > /dev/null || alias test='busybox test'
410if test "x$D" = "x"; then
411 # Remove busybox.nosuid if it's a symlink, because this situation indicates
412 # that we're installing or upgrading to a one-binary busybox.
413 if test -h ${base_bindir}/busybox.nosuid; then
414 rm -f ${base_bindir}/busybox.nosuid
415 fi
416 for suffix in "" ".nosuid" ".suid"; do
417 if test -e ${sysconfdir}/busybox.links$suffix; then
418 while read link; do
419 if test ! -e "$link"; then
420 # we can use busybox here because even if we are using splitted busybox
421 # we've made a symlink from /bin/busybox to /bin/busybox.nosuid.
422 busybox rm -f $link
423 busybox ln -s "${base_bindir}/busybox$suffix" $link
424 fi
425 done < ${sysconfdir}/busybox.links$suffix
426 fi
427 done
428fi
429if grep -q "^${base_bindir}/bash$" $D${sysconfdir}/busybox.links*; then
430 grep -q "^${base_bindir}/bash$" $D${sysconfdir}/shells || echo ${base_bindir}/bash >> $D${sysconfdir}/shells
431fi
432
433"""
Patrick Williams213cb262021-08-07 19:21:33 -0500434 d.prependVar('pkg_postinst:%s' % pkg, postinst)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500435}
436
Patrick Williams213cb262021-08-07 19:21:33 -0500437pkg_postinst:${PN}:prepend () {
Andrew Geissler82c905d2020-04-13 13:39:40 -0500438 # Need path to saved utils, but they may have be removed on upgrade of busybox
439 # Only use shell to get paths. Also capture if busybox was saved.
440 BUSYBOX=""
441 if [ "x$D" = "x" ] ; then
442 for busybox_rmdir in /tmp/busyboxrm-*; do
443 if [ "$busybox_rmdir" != '/tmp/busyboxrm-*' ] ; then
444 export PATH=$busybox_rmdir:$PATH
445 if [ -e $busybox_rmdir/busybox* ] ; then
446 BUSYBOX="$busybox_rmdir/busybox*"
447 fi
448 fi
449 done
450 fi
451}
452
Patrick Williams213cb262021-08-07 19:21:33 -0500453pkg_postinst:${PN}:append () {
Andrew Geissler82c905d2020-04-13 13:39:40 -0500454 # If busybox exists in the remove directory it is because it was the only shell left.
455 if [ "x$D" = "x" ] ; then
456 if [ "x$BUSYBOX" != "x" ] ; then
457 update-alternatives --remove sh $BUSYBOX
458 rm -f $BUSYBOX
459 fi
460 fi
461}
462
Patrick Williams213cb262021-08-07 19:21:33 -0500463pkg_prerm:${PN} () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500464 # This is so you can make busybox commit suicide - removing busybox with no other packages
465 # providing its files, this will make update-alternatives work, but the update-rc.d part
466 # for syslog, httpd and/or udhcpd will fail if there is no other package providing sh
467 tmpdir=`mktemp -d /tmp/busyboxrm-XXXXXX`
468 ln -s ${base_bindir}/busybox $tmpdir/[
469 ln -s ${base_bindir}/busybox $tmpdir/test
470 ln -s ${base_bindir}/busybox $tmpdir/head
471 ln -s ${base_bindir}/busybox $tmpdir/sh
472 ln -s ${base_bindir}/busybox $tmpdir/basename
473 ln -s ${base_bindir}/busybox $tmpdir/echo
474 ln -s ${base_bindir}/busybox $tmpdir/mv
475 ln -s ${base_bindir}/busybox $tmpdir/ln
476 ln -s ${base_bindir}/busybox $tmpdir/dirname
477 ln -s ${base_bindir}/busybox $tmpdir/rm
478 ln -s ${base_bindir}/busybox $tmpdir/sed
479 ln -s ${base_bindir}/busybox $tmpdir/sort
480 ln -s ${base_bindir}/busybox $tmpdir/grep
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500481 ln -s ${base_bindir}/busybox $tmpdir/tail
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500482 export PATH=$PATH:$tmpdir
Andrew Geissler82c905d2020-04-13 13:39:40 -0500483
484 # If busybox is the shell, we need to save it since its the lowest priority shell
485 # Register saved bitbake as the lowest priority shell possible as back up.
486 if [ -n "$(readlink -f /bin/sh | grep busybox)" ] ; then
487 BUSYBOX=$(readlink -f /bin/sh)
488 cp $BUSYBOX $tmpdir/$(basename $BUSYBOX)
489 update-alternatives --install /bin/sh sh $tmpdir/$(basename $BUSYBOX) 1
490 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500491}
492
Patrick Williams213cb262021-08-07 19:21:33 -0500493pkg_postrm:${PN} () {
Andrew Geissler82c905d2020-04-13 13:39:40 -0500494 # Add path to remove dir in case we removed our only grep
495 if [ "x$D" = "x" ] ; then
496 for busybox_rmdir in /tmp/busyboxrm-*; do
497 if [ "$busybox_rmdir" != '/tmp/busyboxrm-*' ] ; then
498 export PATH=$busybox_rmdir:$PATH
499 fi
500 done
501 fi
502
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500503 if grep -q "^${base_bindir}/bash$" $D${sysconfdir}/busybox.links* && [ ! -e $D${base_bindir}/bash ]; then
504 printf "$(grep -v "^${base_bindir}/bash$" $D${sysconfdir}/shells)\n" > $D${sysconfdir}/shells
505 fi
506}
507
Patrick Williams213cb262021-08-07 19:21:33 -0500508pkg_prerm:${PN}-syslog () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500509 # remove syslog
510 if test "x$D" = "x"; then
511 if test "$1" = "upgrade" -o "$1" = "remove"; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600512 ${sysconfdir}/init.d/syslog stop || :
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500513 fi
514 fi
515}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500516
Patrick Williams213cb262021-08-07 19:21:33 -0500517RPROVIDES:${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', '/bin/sh /bin/ash', '', d)}"