blob: 45aaa2b41c15fbc34e70fd21bd36b51736baa672 [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
8# bzip2 applet in busybox is based on lightly-modified bzip2 source
9# the GPL is version 2 only
Andrew Geissler82c905d2020-04-13 13:39:40 -050010LICENSE = "GPLv2 & bzip2-1.0.6"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011LIC_FILES_CHKSUM = "file://LICENSE;md5=de10de48642ab74318e893a61105afbb"
12
13SECTION = "base"
14
15# Whether to split the suid apps into a seperate binary
16BUSYBOX_SPLIT_SUID ?= "1"
17
18export EXTRA_CFLAGS = "${CFLAGS}"
19export EXTRA_LDFLAGS = "${LDFLAGS}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050020
Patrick Williamsc0f7c042017-02-23 20:41:17 -060021EXTRA_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 -050022
23PACKAGES =+ "${PN}-httpd ${PN}-udhcpd ${PN}-udhcpc ${PN}-syslog ${PN}-mdev ${PN}-hwclock"
24
25FILES_${PN}-httpd = "${sysconfdir}/init.d/busybox-httpd /srv/www"
26FILES_${PN}-syslog = "${sysconfdir}/init.d/syslog* ${sysconfdir}/syslog-startup.conf* ${sysconfdir}/syslog.conf* ${systemd_unitdir}/system/syslog.service ${sysconfdir}/default/busybox-syslog"
27FILES_${PN}-mdev = "${sysconfdir}/init.d/mdev ${sysconfdir}/mdev.conf ${sysconfdir}/mdev/*"
28FILES_${PN}-udhcpd = "${sysconfdir}/init.d/busybox-udhcpd"
29FILES_${PN}-udhcpc = "${sysconfdir}/udhcpc.d ${datadir}/udhcpc"
30FILES_${PN}-hwclock = "${sysconfdir}/init.d/hwclock.sh"
31
32INITSCRIPT_PACKAGES = "${PN}-httpd ${PN}-syslog ${PN}-udhcpd ${PN}-mdev ${PN}-hwclock"
33
34INITSCRIPT_NAME_${PN}-httpd = "busybox-httpd"
35INITSCRIPT_NAME_${PN}-hwclock = "hwclock.sh"
36INITSCRIPT_NAME_${PN}-mdev = "mdev"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050037INITSCRIPT_PARAMS_${PN}-mdev = "start 04 S ."
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038INITSCRIPT_NAME_${PN}-syslog = "syslog"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050039INITSCRIPT_NAME_${PN}-udhcpd = "busybox-udhcpd"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040
41SYSTEMD_PACKAGES = "${PN}-syslog"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042SYSTEMD_SERVICE_${PN}-syslog = "${@bb.utils.contains('SRC_URI', 'file://syslog.cfg', 'busybox-syslog.service', '', d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080044RDEPENDS_${PN}-syslog = "busybox"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045CONFFILES_${PN}-syslog = "${sysconfdir}/syslog-startup.conf"
46RCONFLICTS_${PN}-syslog = "rsyslog sysklogd syslog-ng"
47
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048CONFFILES_${PN}-mdev = "${sysconfdir}/mdev.conf"
49
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080050RRECOMMENDS_${PN} = "${PN}-udhcpc"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051
Brad Bishop00111322018-04-01 22:23:53 -040052RDEPENDS_${PN} = "${@["", "busybox-inittab"][(d.getVar('VIRTUAL-RUNTIME_init_manager') == 'busybox')]}"
53
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054inherit cml1 systemd update-rc.d ptest
55
Brad Bishop19323692019-04-05 15:28:33 -040056# busybox's unzip test case needs zip command, which busybox itself does not provide
57RDEPENDS_${PN}-ptest = "zip"
58
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059# internal helper
60def busybox_cfg(feature, tokens, cnf, rem):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130061 if type(tokens) == type(""):
62 tokens = [tokens]
63 rem.extend(['/^[# ]*' + token + '[ =]/d' for token in tokens])
64 if feature:
65 cnf.extend([token + '=y' for token in tokens])
66 else:
67 cnf.extend(['# ' + token + ' is not set' for token in tokens])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068
69# Map distro features to config settings
70def features_to_busybox_settings(d):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130071 cnf, rem = ([], [])
72 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IPV6', cnf, rem)
73 busybox_cfg(True, 'CONFIG_LFS', cnf, rem)
74 busybox_cfg(True, 'CONFIG_FDISK_SUPPORT_LARGE_DISKS', cnf, rem)
75 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'nls', True, False, d), 'CONFIG_LOCALE_SUPPORT', cnf, rem)
76 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv4', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV4', cnf, rem)
77 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV6', cnf, rem)
Brad Bishop19323692019-04-05 15:28:33 -040078 busybox_cfg(bb.utils.contains_any('DISTRO_FEATURES', 'bluetooth wifi', True, False, d), 'CONFIG_RFKILL', cnf, rem)
Brad Bishopa5c52ff2018-11-23 10:55:50 +130079 return "\n".join(cnf), "\n".join(rem)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080
Brad Bishopd7bf8c12018-02-25 22:55:05 -050081# X, Y = ${@features_to_busybox_settings(d)}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082# unfortunately doesn't seem to work with bitbake, workaround:
83def features_to_busybox_conf(d):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130084 cnf, rem = features_to_busybox_settings(d)
85 return cnf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086def features_to_busybox_del(d):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130087 cnf, rem = features_to_busybox_settings(d)
88 return rem
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050090configmangle = '/CONFIG_EXTRA_CFLAGS/d; \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 '
92OE_FEATURES := "${@features_to_busybox_conf(d)}"
93OE_DEL := "${@features_to_busybox_del(d)}"
94DO_IPv4 := "${@bb.utils.contains('DISTRO_FEATURES', 'ipv4', 1, 0, d)}"
95DO_IPv6 := "${@bb.utils.contains('DISTRO_FEATURES', 'ipv6', 1, 0, d)}"
96
97python () {
98 if "${OE_DEL}":
99 d.setVar('configmangle_append', "${OE_DEL}" + "\n")
100 if "${OE_FEATURES}":
101 d.setVar('configmangle_append',
102 "/^### DISTRO FEATURES$/a\\\n%s\n\n" %
103 ("\\n".join((d.expand("${OE_FEATURES}").split("\n")))))
104 d.setVar('configmangle_append',
105 "/^### CROSS$/a\\\n%s\n" %
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500106 ("\\n".join(["CONFIG_EXTRA_CFLAGS=\"${CFLAGS} ${HOST_CC_ARCH}\""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 ])
108 ))
109}
110
111do_prepare_config () {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400112 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500113 export KCONFIG_NOTIMESTAMP=1
114 fi
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500115 sed -e '/CONFIG_STATIC/d' \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116 < ${WORKDIR}/defconfig > ${S}/.config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117 echo "# CONFIG_STATIC is not set" >> .config
118 for i in 'CROSS' 'DISTRO FEATURES'; do echo "### $i"; done >> \
119 ${S}/.config
120 sed -i -e '${configmangle}' ${S}/.config
121 if test ${DO_IPv4} -eq 0 && test ${DO_IPv6} -eq 0; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800122 # disable networking applets
123 mv ${S}/.config ${S}/.config.oe-tmp
124 awk 'BEGIN{net=0}
125 /^# Networking Utilities/{net=1}
126 /^#$/{if(net){net=net+1}}
127 {if(net==2&&$0 !~ /^#/&&$1){print("# "$1" is not set")}else{print}}' \
128 ${S}/.config.oe-tmp > ${S}/.config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500129 fi
130 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 -0400131 if [ -n "${DEBUG_PREFIX_MAP}" ]; then
132 sed -i 's|${DEBUG_PREFIX_MAP}||g' ${S}/.config
133 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500134}
135
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136do_configure () {
Brad Bishopa34c0302019-09-23 22:34:48 -0400137 set -x
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500138 do_prepare_config
139 merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
140 cml1_do_configure
141}
142
143do_compile() {
144 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
Brad Bishop316dfdd2018-06-25 12:45:53 -0400145 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500146 export KCONFIG_NOTIMESTAMP=1
147 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148 if [ "${BUSYBOX_SPLIT_SUID}" = "1" -a x`grep "CONFIG_FEATURE_INDIVIDUAL=y" .config` = x ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800149 # split the .config into two parts, and make two busybox binaries
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500150 if [ -e .config.orig ]; then
151 # Need to guard again an interrupted do_compile - restore any backup
152 cp .config.orig .config
153 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 cp .config .config.orig
155 oe_runmake busybox.cfg.suid
156 oe_runmake busybox.cfg.nosuid
Brad Bishop316dfdd2018-06-25 12:45:53 -0400157
158 # workaround for suid bug 10346
159 if ! grep -q "CONFIG_SH_IS_NONE" busybox.cfg.nosuid; then
160 echo "CONFIG_SH_IS_NONE" >> busybox.cfg.suid
161 fi
162
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500163 for i in `cat busybox.cfg.suid busybox.cfg.nosuid`; do
164 echo "# $i is not set" >> .config.disable.apps
165 done
166 merge_config.sh -m .config.orig .config.disable.apps
167 cp .config .config.nonapps
168 for s in suid nosuid; do
169 cat busybox.cfg.$s | while read item; do
170 grep -w "$item" .config.orig
171 done > .config.app.$s
Brad Bishop316dfdd2018-06-25 12:45:53 -0400172
173 # workaround for suid bug 10346
174 if [ "$s" = "suid" ] ; then
175 sed "s/.*CONFIG_SH_IS_NONE.*$/CONFIG_SH_IS_NONE=y/" -i .config.app.suid
176 fi
177
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500178 merge_config.sh -m .config.nonapps .config.app.$s
179 oe_runmake busybox_unstripped
180 mv busybox_unstripped busybox.$s
181 oe_runmake busybox.links
Brad Bishope2d5b612018-11-23 10:55:50 +1300182 sort busybox.links > busybox.links.$s
183 rm busybox.links
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500184 done
Brad Bishop316dfdd2018-06-25 12:45:53 -0400185
186 # hard fail if sh is being linked to the suid busybox (detects bug 10346)
187 if grep -q -x "/bin/sh" busybox.links.suid; then
188 bbfatal "busybox suid binary incorrectly provides /bin/sh"
189 fi
190
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191 # copy .config.orig back to .config, because the install process may check this file
192 cp .config.orig .config
193 # cleanup
194 rm .config.orig .config.app.suid .config.app.nosuid .config.disable.apps .config.nonapps
195 else
196 oe_runmake busybox_unstripped
197 cp busybox_unstripped busybox
198 oe_runmake busybox.links
199 fi
200}
201
202do_install () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500203 sed -i "s:^/bin/:BASE_BINDIR/:" busybox.links*
204 sed -i "s:^/sbin/:BASE_SBINDIR/:" busybox.links*
205 sed -i "s:^/usr/bin/:BINDIR/:" busybox.links*
206 sed -i "s:^/usr/sbin/:SBINDIR/:" busybox.links*
207
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800208 # Move arch/link to BINDIR to match coreutils
209 sed -i "s:^BASE_BINDIR/arch:BINDIR/arch:" busybox.links*
210 sed -i "s:^BASE_BINDIR/link:BINDIR/link:" busybox.links*
211
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500212 sed -i "s:^BASE_BINDIR/:${base_bindir}/:" busybox.links*
213 sed -i "s:^BASE_SBINDIR/:${base_sbindir}/:" busybox.links*
214 sed -i "s:^BINDIR/:${bindir}/:" busybox.links*
215 sed -i "s:^SBINDIR/:${sbindir}/:" busybox.links*
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500216
217 install -d ${D}${sysconfdir}/init.d
218
219 if ! grep -q "CONFIG_FEATURE_INDIVIDUAL=y" ${B}/.config; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500220 # Install ${base_bindir}/busybox, and the ${base_bindir}/sh link so the postinst script
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500221 # can run. Let update-alternatives handle the rest.
222 install -d ${D}${base_bindir}
223 if [ "${BUSYBOX_SPLIT_SUID}" = "1" ]; then
224 install -m 4755 ${B}/busybox.suid ${D}${base_bindir}
225 install -m 0755 ${B}/busybox.nosuid ${D}${base_bindir}
226 install -m 0644 ${S}/busybox.links.suid ${D}${sysconfdir}
227 install -m 0644 ${S}/busybox.links.nosuid ${D}${sysconfdir}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400228 if grep -q "CONFIG_SH_IS_ASH=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500229 ln -sf busybox.nosuid ${D}${base_bindir}/sh
230 fi
231 # Keep a default busybox for people who want to invoke busybox directly.
232 # This is also useful for the on device upgrade. Because we want
233 # to use the busybox command in postinst.
234 ln -sf busybox.nosuid ${D}${base_bindir}/busybox
235 else
236 if grep -q "CONFIG_FEATURE_SUID=y" ${B}/.config; then
237 install -m 4755 ${B}/busybox ${D}${base_bindir}
238 else
239 install -m 0755 ${B}/busybox ${D}${base_bindir}
240 fi
241 install -m 0644 ${S}/busybox.links ${D}${sysconfdir}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400242 if grep -q "CONFIG_SH_IS_ASH=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500243 ln -sf busybox ${D}${base_bindir}/sh
244 fi
245 # We make this symlink here to eliminate the error when upgrading together
246 # with busybox-syslog. Without this symlink, the opkg may think of the
247 # busybox.nosuid as obsolete and remove it, resulting in dead links like
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500248 # ${base_bindir}/sed -> ${base_bindir}/busybox.nosuid. This will make upgrading busybox-syslog fail.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500249 # This symlink will be safely deleted in postinst, thus no negative effect.
250 ln -sf busybox ${D}${base_bindir}/busybox.nosuid
251 fi
252 else
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800253 install -d ${D}${base_bindir} ${D}${bindir} ${D}${libdir}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254 cat busybox.links | while read FILE; do
255 NAME=`basename "$FILE"`
256 install -m 0755 "0_lib/$NAME" "${D}$FILE.${BPN}"
257 done
258 # add suid bit where needed
259 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
260 find ${D} -name $i.${BPN} -exec chmod a+s {} \;
261 done
262 install -m 0755 0_lib/libbusybox.so.${PV} ${D}${libdir}/libbusybox.so.${PV}
263 ln -sf sh.${BPN} ${D}${base_bindir}/sh
264 ln -sf ln.${BPN} ${D}${base_bindir}/ln
265 ln -sf test.${BPN} ${D}${bindir}/test
266 if [ -f ${D}/linuxrc.${BPN} ]; then
267 mv ${D}/linuxrc.${BPN} ${D}/linuxrc
268 fi
269 install -m 0644 ${S}/busybox.links ${D}${sysconfdir}
270 fi
271
272 if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500273 install -m 0755 ${WORKDIR}/syslog ${D}${sysconfdir}/init.d/syslog
274 install -m 644 ${WORKDIR}/syslog-startup.conf ${D}${sysconfdir}/syslog-startup.conf
275 install -m 644 ${WORKDIR}/syslog.conf ${D}${sysconfdir}/syslog.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500276 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800277 if grep -q "CONFIG_CROND=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278 install -m 0755 ${WORKDIR}/busybox-cron ${D}${sysconfdir}/init.d/
279 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800280 if grep -q "CONFIG_HTTPD=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500281 install -m 0755 ${WORKDIR}/busybox-httpd ${D}${sysconfdir}/init.d/
282 install -d ${D}/srv/www
283 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800284 if grep -q "CONFIG_UDHCPD=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500285 install -m 0755 ${WORKDIR}/busybox-udhcpd ${D}${sysconfdir}/init.d/
286 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800287 if grep -q "CONFIG_HWCLOCK=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288 install -m 0755 ${WORKDIR}/hwclock.sh ${D}${sysconfdir}/init.d/
289 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800290 if grep -q "CONFIG_UDHCPC=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500291 install -d ${D}${sysconfdir}/udhcpc.d
292 install -d ${D}${datadir}/udhcpc
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500293 install -m 0755 ${WORKDIR}/simple.script ${D}${sysconfdir}/udhcpc.d/50default
294 sed -i "s:/SBIN_DIR/:${base_sbindir}/:" ${D}${sysconfdir}/udhcpc.d/50default
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500295 install -m 0755 ${WORKDIR}/default.script ${D}${datadir}/udhcpc/default.script
296 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800297 if grep -q "CONFIG_INETD=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298 install -m 0755 ${WORKDIR}/inetd ${D}${sysconfdir}/init.d/inetd.${BPN}
299 sed -i "s:/usr/sbin/:${sbindir}/:" ${D}${sysconfdir}/init.d/inetd.${BPN}
300 install -m 0644 ${WORKDIR}/inetd.conf ${D}${sysconfdir}/
301 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800302 if grep -q "CONFIG_MDEV=y" ${B}/.config; then
303 install -m 0755 ${WORKDIR}/mdev ${D}${sysconfdir}/init.d/mdev
304 if grep "CONFIG_FEATURE_MDEV_CONF=y" ${B}/.config; then
305 install -m 644 ${WORKDIR}/mdev.conf ${D}${sysconfdir}/mdev.conf
306 install -d ${D}${sysconfdir}/mdev
307 install -m 0755 ${WORKDIR}/find-touchscreen.sh ${D}${sysconfdir}/mdev
308 install -m 0755 ${WORKDIR}/mdev-mount.sh ${D}${sysconfdir}/mdev
309 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800311 if grep -q "CONFIG_INIT=y" ${B}/.config; then
Brad Bishopa34c0302019-09-23 22:34:48 -0400312 install -D -m 0755 ${WORKDIR}/rcS ${D}${sysconfdir}/init.d/rcS
313 install -D -m 0755 ${WORKDIR}/rcK ${D}${sysconfdir}/init.d/rcK
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800314 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500315
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800316 if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
317 if grep -q "CONFIG_KLOGD=y" ${B}/.config; then
318 install -d ${D}${systemd_unitdir}/system
319 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-klogd.service.in \
320 > ${D}${systemd_unitdir}/system/busybox-klogd.service
321 fi
Brad Bishopbba38f32018-08-23 16:11:46 +0800322
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800323 if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
324 install -d ${D}${systemd_unitdir}/system
325 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-syslog.service.in \
326 > ${D}${systemd_unitdir}/system/busybox-syslog.service
327 if [ ! -e ${D}${systemd_unitdir}/system/busybox-klogd.service ] ; then
328 sed -i '/klog/d' ${D}${systemd_unitdir}/system/busybox-syslog.service
329 fi
330 if [ -f ${WORKDIR}/busybox-syslog.default ] ; then
331 install -d ${D}${sysconfdir}/default
332 install -m 0644 ${WORKDIR}/busybox-syslog.default ${D}${sysconfdir}/default/busybox-syslog
333 fi
334 fi
335 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500336
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800337 # Remove the sysvinit specific configuration file for systemd systems to avoid confusion
338 if ${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'false', 'true', d)}; then
339 rm -f ${D}${sysconfdir}/syslog-startup.conf
340 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500341}
342
Brad Bishopc342db32019-05-15 21:57:59 -0400343PTEST_BINDIR = "1"
344
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500345do_install_ptest () {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800346 cp -r ${B}/testsuite ${D}${PTEST_PATH}/
Andrew Geissler82c905d2020-04-13 13:39:40 -0500347 # These access the internet which is not guaranteed to work on machines running the tests
348 rm -rf ${D}${PTEST_PATH}/testsuite/wget
349 sort ${B}/.config > ${D}${PTEST_PATH}/.config
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800350 ln -s /bin/busybox ${D}${PTEST_PATH}/busybox
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500351}
352
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500353inherit update-alternatives
354
355ALTERNATIVE_PRIORITY = "50"
356
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357python do_package_prepend () {
358 # We need to load the full set of busybox provides from the /etc/busybox.links
359 # Use this to see the update-alternatives with the right information
360
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500361 dvar = d.getVar('D')
362 pn = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500363 def set_alternative_vars(links, target):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500364 links = d.expand(links)
365 target = d.expand(target)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500366 f = open('%s%s' % (dvar, links), 'r')
367 for alt_link_name in f:
368 alt_link_name = alt_link_name.strip()
369 alt_name = os.path.basename(alt_link_name)
370 # Match coreutils
371 if alt_name == '[':
372 alt_name = 'lbracket'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800373 if alt_name == 'klogd' or alt_name == 'syslogd':
374 d.appendVar('ALTERNATIVE_%s-syslog' % (pn), ' ' + alt_name)
375 else:
376 d.appendVar('ALTERNATIVE_%s' % (pn), ' ' + alt_name)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500377 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name)
378 if os.path.exists('%s%s' % (dvar, target)):
379 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, target)
380 f.close()
381 return
382
383 if os.path.exists('%s/etc/busybox.links' % (dvar)):
384 set_alternative_vars("${sysconfdir}/busybox.links", "${base_bindir}/busybox")
385 else:
386 set_alternative_vars("${sysconfdir}/busybox.links.nosuid", "${base_bindir}/busybox.nosuid")
387 set_alternative_vars("${sysconfdir}/busybox.links.suid", "${base_bindir}/busybox.suid")
388}
389
Brad Bishop96ff1982019-08-19 13:50:42 -0400390# This part of code is dedicated to the on target upgrade problem. It's known
391# that if we don't make appropriate symlinks before update-alternatives calls,
392# there will be errors indicating missing commands such as 'sed'.
393# These symlinks will later be updated by update-alternatives calls.
394# The update-alternatives.bbclass' postinst script runs firstly before other
395# postinst, but this part of code needs run firstly, so add this funtion.
396python populate_packages_updatealternatives_append() {
397 postinst = """
398test -n 2 > /dev/null || alias test='busybox test'
399if test "x$D" = "x"; then
400 # Remove busybox.nosuid if it's a symlink, because this situation indicates
401 # that we're installing or upgrading to a one-binary busybox.
402 if test -h ${base_bindir}/busybox.nosuid; then
403 rm -f ${base_bindir}/busybox.nosuid
404 fi
405 for suffix in "" ".nosuid" ".suid"; do
406 if test -e ${sysconfdir}/busybox.links$suffix; then
407 while read link; do
408 if test ! -e "$link"; then
409 # we can use busybox here because even if we are using splitted busybox
410 # we've made a symlink from /bin/busybox to /bin/busybox.nosuid.
411 busybox rm -f $link
412 busybox ln -s "${base_bindir}/busybox$suffix" $link
413 fi
414 done < ${sysconfdir}/busybox.links$suffix
415 fi
416 done
417fi
418if grep -q "^${base_bindir}/bash$" $D${sysconfdir}/busybox.links*; then
419 grep -q "^${base_bindir}/bash$" $D${sysconfdir}/shells || echo ${base_bindir}/bash >> $D${sysconfdir}/shells
420fi
421
422"""
423 d.prependVar('pkg_postinst_%s' % pkg, postinst)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500424}
425
Andrew Geissler82c905d2020-04-13 13:39:40 -0500426pkg_postinst_${PN}_prepend () {
427 # Need path to saved utils, but they may have be removed on upgrade of busybox
428 # Only use shell to get paths. Also capture if busybox was saved.
429 BUSYBOX=""
430 if [ "x$D" = "x" ] ; then
431 for busybox_rmdir in /tmp/busyboxrm-*; do
432 if [ "$busybox_rmdir" != '/tmp/busyboxrm-*' ] ; then
433 export PATH=$busybox_rmdir:$PATH
434 if [ -e $busybox_rmdir/busybox* ] ; then
435 BUSYBOX="$busybox_rmdir/busybox*"
436 fi
437 fi
438 done
439 fi
440}
441
442pkg_postinst_${PN}_append () {
443 # If busybox exists in the remove directory it is because it was the only shell left.
444 if [ "x$D" = "x" ] ; then
445 if [ "x$BUSYBOX" != "x" ] ; then
446 update-alternatives --remove sh $BUSYBOX
447 rm -f $BUSYBOX
448 fi
449 fi
450}
451
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500452pkg_prerm_${PN} () {
453 # This is so you can make busybox commit suicide - removing busybox with no other packages
454 # providing its files, this will make update-alternatives work, but the update-rc.d part
455 # for syslog, httpd and/or udhcpd will fail if there is no other package providing sh
456 tmpdir=`mktemp -d /tmp/busyboxrm-XXXXXX`
457 ln -s ${base_bindir}/busybox $tmpdir/[
458 ln -s ${base_bindir}/busybox $tmpdir/test
459 ln -s ${base_bindir}/busybox $tmpdir/head
460 ln -s ${base_bindir}/busybox $tmpdir/sh
461 ln -s ${base_bindir}/busybox $tmpdir/basename
462 ln -s ${base_bindir}/busybox $tmpdir/echo
463 ln -s ${base_bindir}/busybox $tmpdir/mv
464 ln -s ${base_bindir}/busybox $tmpdir/ln
465 ln -s ${base_bindir}/busybox $tmpdir/dirname
466 ln -s ${base_bindir}/busybox $tmpdir/rm
467 ln -s ${base_bindir}/busybox $tmpdir/sed
468 ln -s ${base_bindir}/busybox $tmpdir/sort
469 ln -s ${base_bindir}/busybox $tmpdir/grep
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500470 ln -s ${base_bindir}/busybox $tmpdir/tail
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500471 export PATH=$PATH:$tmpdir
Andrew Geissler82c905d2020-04-13 13:39:40 -0500472
473 # If busybox is the shell, we need to save it since its the lowest priority shell
474 # Register saved bitbake as the lowest priority shell possible as back up.
475 if [ -n "$(readlink -f /bin/sh | grep busybox)" ] ; then
476 BUSYBOX=$(readlink -f /bin/sh)
477 cp $BUSYBOX $tmpdir/$(basename $BUSYBOX)
478 update-alternatives --install /bin/sh sh $tmpdir/$(basename $BUSYBOX) 1
479 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500480}
481
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500482pkg_postrm_${PN} () {
Andrew Geissler82c905d2020-04-13 13:39:40 -0500483 # Add path to remove dir in case we removed our only grep
484 if [ "x$D" = "x" ] ; then
485 for busybox_rmdir in /tmp/busyboxrm-*; do
486 if [ "$busybox_rmdir" != '/tmp/busyboxrm-*' ] ; then
487 export PATH=$busybox_rmdir:$PATH
488 fi
489 done
490 fi
491
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500492 if grep -q "^${base_bindir}/bash$" $D${sysconfdir}/busybox.links* && [ ! -e $D${base_bindir}/bash ]; then
493 printf "$(grep -v "^${base_bindir}/bash$" $D${sysconfdir}/shells)\n" > $D${sysconfdir}/shells
494 fi
495}
496
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500497pkg_prerm_${PN}-syslog () {
498 # remove syslog
499 if test "x$D" = "x"; then
500 if test "$1" = "upgrade" -o "$1" = "remove"; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600501 ${sysconfdir}/init.d/syslog stop || :
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500502 fi
503 fi
504}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500505
Brad Bishop19323692019-04-05 15:28:33 -0400506RPROVIDES_${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', '/bin/sh /bin/ash', '', d)}"