blob: d1675c37aab42a27291c28634b140b8bd38fd579 [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."
3HOMEPAGE = "http://www.busybox.net"
4BUGTRACKER = "https://bugs.busybox.net/"
5
6DEPENDS += "kern-tools-native"
7
8# bzip2 applet in busybox is based on lightly-modified bzip2 source
9# the GPL is version 2 only
10LICENSE = "GPLv2 & bzip2"
11LIC_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 Bishopd7bf8c12018-02-25 22:55:05 -050044CONFFILES_${PN}-syslog = "${sysconfdir}/syslog-startup.conf"
45RCONFLICTS_${PN}-syslog = "rsyslog sysklogd syslog-ng"
46
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047CONFFILES_${PN}-mdev = "${sysconfdir}/mdev.conf"
48
49RRECOMMENDS_${PN} = "${PN}-syslog ${PN}-udhcpc"
50
Brad Bishop00111322018-04-01 22:23:53 -040051RDEPENDS_${PN} = "${@["", "busybox-inittab"][(d.getVar('VIRTUAL-RUNTIME_init_manager') == 'busybox')]}"
52
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053inherit cml1 systemd update-rc.d ptest
54
55# internal helper
56def busybox_cfg(feature, tokens, cnf, rem):
57 if type(tokens) == type(""):
58 tokens = [tokens]
59 rem.extend(['/^[# ]*' + token + '[ =]/d' for token in tokens])
60 if feature:
61 cnf.extend([token + '=y' for token in tokens])
62 else:
63 cnf.extend(['# ' + token + ' is not set' for token in tokens])
64
65# Map distro features to config settings
66def features_to_busybox_settings(d):
67 cnf, rem = ([], [])
68 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IPV6', cnf, rem)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050069 busybox_cfg(True, 'CONFIG_LFS', cnf, rem)
70 busybox_cfg(True, 'CONFIG_FDISK_SUPPORT_LARGE_DISKS', cnf, rem)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050071 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'nls', True, False, d), 'CONFIG_LOCALE_SUPPORT', cnf, rem)
72 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv4', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV4', cnf, rem)
73 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV6', cnf, rem)
74 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'wifi', True, False, d), 'CONFIG_RFKILL', cnf, rem)
75 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'bluetooth', True, False, d), 'CONFIG_RFKILL', cnf, rem)
76 return "\n".join(cnf), "\n".join(rem)
77
Brad Bishopd7bf8c12018-02-25 22:55:05 -050078# X, Y = ${@features_to_busybox_settings(d)}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079# unfortunately doesn't seem to work with bitbake, workaround:
80def features_to_busybox_conf(d):
81 cnf, rem = features_to_busybox_settings(d)
82 return cnf
83def features_to_busybox_del(d):
84 cnf, rem = features_to_busybox_settings(d)
85 return rem
86
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050087configmangle = '/CONFIG_EXTRA_CFLAGS/d; \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088 '
89OE_FEATURES := "${@features_to_busybox_conf(d)}"
90OE_DEL := "${@features_to_busybox_del(d)}"
91DO_IPv4 := "${@bb.utils.contains('DISTRO_FEATURES', 'ipv4', 1, 0, d)}"
92DO_IPv6 := "${@bb.utils.contains('DISTRO_FEATURES', 'ipv6', 1, 0, d)}"
93
94python () {
95 if "${OE_DEL}":
96 d.setVar('configmangle_append', "${OE_DEL}" + "\n")
97 if "${OE_FEATURES}":
98 d.setVar('configmangle_append',
99 "/^### DISTRO FEATURES$/a\\\n%s\n\n" %
100 ("\\n".join((d.expand("${OE_FEATURES}").split("\n")))))
101 d.setVar('configmangle_append',
102 "/^### CROSS$/a\\\n%s\n" %
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500103 ("\\n".join(["CONFIG_EXTRA_CFLAGS=\"${CFLAGS} ${HOST_CC_ARCH}\""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104 ])
105 ))
106}
107
108do_prepare_config () {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400109 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500110 export KCONFIG_NOTIMESTAMP=1
111 fi
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500112 sed -e '/CONFIG_STATIC/d' \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113 < ${WORKDIR}/defconfig > ${S}/.config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 echo "# CONFIG_STATIC is not set" >> .config
115 for i in 'CROSS' 'DISTRO FEATURES'; do echo "### $i"; done >> \
116 ${S}/.config
117 sed -i -e '${configmangle}' ${S}/.config
118 if test ${DO_IPv4} -eq 0 && test ${DO_IPv6} -eq 0; then
119 # disable networking applets
120 mv ${S}/.config ${S}/.config.oe-tmp
121 awk 'BEGIN{net=0}
122 /^# Networking Utilities/{net=1}
123 /^#$/{if(net){net=net+1}}
124 {if(net==2&&$0 !~ /^#/&&$1){print("# "$1" is not set")}else{print}}' \
125 ${S}/.config.oe-tmp > ${S}/.config
126 fi
127 sed -i 's/CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -n"/CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -b"/' ${S}/.config
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500128 sed -i 's|${DEBUG_PREFIX_MAP}||g' ${S}/.config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500129}
130
131# returns all the elements from the src uri that are .cfg files
132def find_cfgs(d):
133 sources=src_patches(d, True)
134 sources_list=[]
135 for s in sources:
136 if s.endswith('.cfg'):
137 sources_list.append(s)
138
139 return sources_list
140
141do_configure () {
142 do_prepare_config
143 merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
144 cml1_do_configure
145}
146
147do_compile() {
148 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
Brad Bishop316dfdd2018-06-25 12:45:53 -0400149 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500150 export KCONFIG_NOTIMESTAMP=1
151 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500152 if [ "${BUSYBOX_SPLIT_SUID}" = "1" -a x`grep "CONFIG_FEATURE_INDIVIDUAL=y" .config` = x ]; then
153 # split the .config into two parts, and make two busybox binaries
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500154 if [ -e .config.orig ]; then
155 # Need to guard again an interrupted do_compile - restore any backup
156 cp .config.orig .config
157 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158 cp .config .config.orig
159 oe_runmake busybox.cfg.suid
160 oe_runmake busybox.cfg.nosuid
Brad Bishop316dfdd2018-06-25 12:45:53 -0400161
162 # workaround for suid bug 10346
163 if ! grep -q "CONFIG_SH_IS_NONE" busybox.cfg.nosuid; then
164 echo "CONFIG_SH_IS_NONE" >> busybox.cfg.suid
165 fi
166
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167 for i in `cat busybox.cfg.suid busybox.cfg.nosuid`; do
168 echo "# $i is not set" >> .config.disable.apps
169 done
170 merge_config.sh -m .config.orig .config.disable.apps
171 cp .config .config.nonapps
172 for s in suid nosuid; do
173 cat busybox.cfg.$s | while read item; do
174 grep -w "$item" .config.orig
175 done > .config.app.$s
Brad Bishop316dfdd2018-06-25 12:45:53 -0400176
177 # workaround for suid bug 10346
178 if [ "$s" = "suid" ] ; then
179 sed "s/.*CONFIG_SH_IS_NONE.*$/CONFIG_SH_IS_NONE=y/" -i .config.app.suid
180 fi
181
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182 merge_config.sh -m .config.nonapps .config.app.$s
183 oe_runmake busybox_unstripped
184 mv busybox_unstripped busybox.$s
185 oe_runmake busybox.links
186 mv busybox.links busybox.links.$s
187 done
Brad Bishop316dfdd2018-06-25 12:45:53 -0400188
189 # hard fail if sh is being linked to the suid busybox (detects bug 10346)
190 if grep -q -x "/bin/sh" busybox.links.suid; then
191 bbfatal "busybox suid binary incorrectly provides /bin/sh"
192 fi
193
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500194 # copy .config.orig back to .config, because the install process may check this file
195 cp .config.orig .config
196 # cleanup
197 rm .config.orig .config.app.suid .config.app.nosuid .config.disable.apps .config.nonapps
198 else
199 oe_runmake busybox_unstripped
200 cp busybox_unstripped busybox
201 oe_runmake busybox.links
202 fi
203}
204
205do_install () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500206 sed -i "s:^/bin/:BASE_BINDIR/:" busybox.links*
207 sed -i "s:^/sbin/:BASE_SBINDIR/:" busybox.links*
208 sed -i "s:^/usr/bin/:BINDIR/:" busybox.links*
209 sed -i "s:^/usr/sbin/:SBINDIR/:" busybox.links*
210
211 sed -i "s:^BASE_BINDIR/:${base_bindir}/:" busybox.links*
212 sed -i "s:^BASE_SBINDIR/:${base_sbindir}/:" busybox.links*
213 sed -i "s:^BINDIR/:${bindir}/:" busybox.links*
214 sed -i "s:^SBINDIR/:${sbindir}/:" busybox.links*
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500215
216 install -d ${D}${sysconfdir}/init.d
217
218 if ! grep -q "CONFIG_FEATURE_INDIVIDUAL=y" ${B}/.config; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500219 # Install ${base_bindir}/busybox, and the ${base_bindir}/sh link so the postinst script
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220 # can run. Let update-alternatives handle the rest.
221 install -d ${D}${base_bindir}
222 if [ "${BUSYBOX_SPLIT_SUID}" = "1" ]; then
223 install -m 4755 ${B}/busybox.suid ${D}${base_bindir}
224 install -m 0755 ${B}/busybox.nosuid ${D}${base_bindir}
225 install -m 0644 ${S}/busybox.links.suid ${D}${sysconfdir}
226 install -m 0644 ${S}/busybox.links.nosuid ${D}${sysconfdir}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400227 if grep -q "CONFIG_SH_IS_ASH=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 ln -sf busybox.nosuid ${D}${base_bindir}/sh
229 fi
230 # Keep a default busybox for people who want to invoke busybox directly.
231 # This is also useful for the on device upgrade. Because we want
232 # to use the busybox command in postinst.
233 ln -sf busybox.nosuid ${D}${base_bindir}/busybox
234 else
235 if grep -q "CONFIG_FEATURE_SUID=y" ${B}/.config; then
236 install -m 4755 ${B}/busybox ${D}${base_bindir}
237 else
238 install -m 0755 ${B}/busybox ${D}${base_bindir}
239 fi
240 install -m 0644 ${S}/busybox.links ${D}${sysconfdir}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400241 if grep -q "CONFIG_SH_IS_ASH=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500242 ln -sf busybox ${D}${base_bindir}/sh
243 fi
244 # We make this symlink here to eliminate the error when upgrading together
245 # with busybox-syslog. Without this symlink, the opkg may think of the
246 # busybox.nosuid as obsolete and remove it, resulting in dead links like
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500247 # ${base_bindir}/sed -> ${base_bindir}/busybox.nosuid. This will make upgrading busybox-syslog fail.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500248 # This symlink will be safely deleted in postinst, thus no negative effect.
249 ln -sf busybox ${D}${base_bindir}/busybox.nosuid
250 fi
251 else
252 install -d ${D}${base_bindir} ${D}${base_sbindir}
253 install -d ${D}${libdir} ${D}${bindir} ${D}${sbindir}
254 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
277 if grep "CONFIG_CROND=y" ${B}/.config; then
278 install -m 0755 ${WORKDIR}/busybox-cron ${D}${sysconfdir}/init.d/
279 fi
280 if grep "CONFIG_HTTPD=y" ${B}/.config; then
281 install -m 0755 ${WORKDIR}/busybox-httpd ${D}${sysconfdir}/init.d/
282 install -d ${D}/srv/www
283 fi
284 if grep "CONFIG_UDHCPD=y" ${B}/.config; then
285 install -m 0755 ${WORKDIR}/busybox-udhcpd ${D}${sysconfdir}/init.d/
286 fi
287 if grep "CONFIG_HWCLOCK=y" ${B}/.config; then
288 install -m 0755 ${WORKDIR}/hwclock.sh ${D}${sysconfdir}/init.d/
289 fi
290 if grep "CONFIG_UDHCPC=y" ${B}/.config; then
291 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
297 if grep "CONFIG_INETD=y" ${B}/.config; then
298 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
302 if grep "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
310 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500311 if grep "CONFIG_INIT=y" ${B}/.config; then
312 install -D -m 0777 ${WORKDIR}/rcS ${D}${sysconfdir}/init.d/rcS
313 install -D -m 0777 ${WORKDIR}/rcK ${D}${sysconfdir}/init.d/rcK
314 install -D -m 0755 ${WORKDIR}/runlevel ${D}${base_sbindir}/runlevel
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500315 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500316
317 if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
318 if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
319 install -d ${D}${systemd_unitdir}/system
320 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-syslog.service.in \
321 > ${D}${systemd_unitdir}/system/busybox-syslog.service
322 if [ -f ${WORKDIR}/busybox-syslog.default ] ; then
323 install -d ${D}${sysconfdir}/default
324 install -m 0644 ${WORKDIR}/busybox-syslog.default ${D}${sysconfdir}/default/busybox-syslog
325 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500326 fi
327 if grep -q "CONFIG_KLOGD=y" ${B}/.config; then
328 install -d ${D}${systemd_unitdir}/system
329 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-klogd.service.in \
330 > ${D}${systemd_unitdir}/system/busybox-klogd.service
331 fi
332 fi
333
334 # Remove the sysvinit specific configuration file for systemd systems to avoid confusion
335 if ${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'false', 'true', d)}; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500336 rm -f ${D}${sysconfdir}/syslog-startup.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500337 fi
338}
339
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500340do_install_ptest () {
341 cp -r ${B}/testsuite ${D}${PTEST_PATH}/
342 cp ${B}/.config ${D}${PTEST_PATH}/
343 ln -s /bin/busybox ${D}${PTEST_PATH}/busybox
344}
345
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500346inherit update-alternatives
347
348ALTERNATIVE_PRIORITY = "50"
349
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500350python do_package_prepend () {
351 # We need to load the full set of busybox provides from the /etc/busybox.links
352 # Use this to see the update-alternatives with the right information
353
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500354 dvar = d.getVar('D')
355 pn = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500356 def set_alternative_vars(links, target):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500357 links = d.expand(links)
358 target = d.expand(target)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500359 f = open('%s%s' % (dvar, links), 'r')
360 for alt_link_name in f:
361 alt_link_name = alt_link_name.strip()
362 alt_name = os.path.basename(alt_link_name)
363 # Match coreutils
364 if alt_name == '[':
365 alt_name = 'lbracket'
366 d.appendVar('ALTERNATIVE_%s' % (pn), ' ' + alt_name)
367 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name)
368 if os.path.exists('%s%s' % (dvar, target)):
369 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, target)
370 f.close()
371 return
372
373 if os.path.exists('%s/etc/busybox.links' % (dvar)):
374 set_alternative_vars("${sysconfdir}/busybox.links", "${base_bindir}/busybox")
375 else:
376 set_alternative_vars("${sysconfdir}/busybox.links.nosuid", "${base_bindir}/busybox.nosuid")
377 set_alternative_vars("${sysconfdir}/busybox.links.suid", "${base_bindir}/busybox.suid")
378}
379
380pkg_postinst_${PN} () {
381 # This part of code is dedicated to the on target upgrade problem.
382 # It's known that if we don't make appropriate symlinks before update-alternatives calls,
383 # there will be errors indicating missing commands such as 'sed'.
384 # These symlinks will later be updated by update-alternatives calls.
385 test -n 2 > /dev/null || alias test='busybox test'
386 if test "x$D" = "x"; then
387 # Remove busybox.nosuid if it's a symlink, because this situation indicates
388 # that we're installing or upgrading to a one-binary busybox.
389 if test -h ${base_bindir}/busybox.nosuid; then
390 rm -f ${base_bindir}/busybox.nosuid
391 fi
392 for suffix in "" ".nosuid" ".suid"; do
393 if test -e ${sysconfdir}/busybox.links$suffix; then
394 while read link; do
395 if test ! -e "$link"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500396 # we can use busybox here because even if we are using splitted busybox
397 # we've made a symlink from /bin/busybox to /bin/busybox.nosuid.
398 busybox rm -f $link
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500399 busybox ln -s "${base_bindir}/busybox$suffix" $link
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500400 fi
401 done < ${sysconfdir}/busybox.links$suffix
402 fi
403 done
404 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500405 if grep -q "^${base_bindir}/bash$" $D${sysconfdir}/busybox.links*; then
406 grep -q "^${base_bindir}/bash$" $D${sysconfdir}/shells || echo ${base_bindir}/bash >> $D${sysconfdir}/shells
407 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500408}
409
410pkg_prerm_${PN} () {
411 # This is so you can make busybox commit suicide - removing busybox with no other packages
412 # providing its files, this will make update-alternatives work, but the update-rc.d part
413 # for syslog, httpd and/or udhcpd will fail if there is no other package providing sh
414 tmpdir=`mktemp -d /tmp/busyboxrm-XXXXXX`
415 ln -s ${base_bindir}/busybox $tmpdir/[
416 ln -s ${base_bindir}/busybox $tmpdir/test
417 ln -s ${base_bindir}/busybox $tmpdir/head
418 ln -s ${base_bindir}/busybox $tmpdir/sh
419 ln -s ${base_bindir}/busybox $tmpdir/basename
420 ln -s ${base_bindir}/busybox $tmpdir/echo
421 ln -s ${base_bindir}/busybox $tmpdir/mv
422 ln -s ${base_bindir}/busybox $tmpdir/ln
423 ln -s ${base_bindir}/busybox $tmpdir/dirname
424 ln -s ${base_bindir}/busybox $tmpdir/rm
425 ln -s ${base_bindir}/busybox $tmpdir/sed
426 ln -s ${base_bindir}/busybox $tmpdir/sort
427 ln -s ${base_bindir}/busybox $tmpdir/grep
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500428 ln -s ${base_bindir}/busybox $tmpdir/tail
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500429 export PATH=$PATH:$tmpdir
430}
431
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500432pkg_postrm_${PN} () {
433 if grep -q "^${base_bindir}/bash$" $D${sysconfdir}/busybox.links* && [ ! -e $D${base_bindir}/bash ]; then
434 printf "$(grep -v "^${base_bindir}/bash$" $D${sysconfdir}/shells)\n" > $D${sysconfdir}/shells
435 fi
436}
437
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500438pkg_prerm_${PN}-syslog () {
439 # remove syslog
440 if test "x$D" = "x"; then
441 if test "$1" = "upgrade" -o "$1" = "remove"; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600442 ${sysconfdir}/init.d/syslog stop || :
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500443 fi
444 fi
445}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500446
447RPROVIDES_${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', '/bin/sh', '', d)}"