blob: 0c0d26ed3a34a0bdf2219cc88003a1ebff271d31 [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
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
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 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
56# internal helper
57def busybox_cfg(feature, tokens, cnf, rem):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130058 if type(tokens) == type(""):
59 tokens = [tokens]
60 rem.extend(['/^[# ]*' + token + '[ =]/d' for token in tokens])
61 if feature:
62 cnf.extend([token + '=y' for token in tokens])
63 else:
64 cnf.extend(['# ' + token + ' is not set' for token in tokens])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065
66# Map distro features to config settings
67def features_to_busybox_settings(d):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130068 cnf, rem = ([], [])
69 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IPV6', cnf, rem)
70 busybox_cfg(True, 'CONFIG_LFS', cnf, rem)
71 busybox_cfg(True, 'CONFIG_FDISK_SUPPORT_LARGE_DISKS', cnf, rem)
72 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'nls', True, False, d), 'CONFIG_LOCALE_SUPPORT', cnf, rem)
73 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv4', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV4', cnf, rem)
74 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV6', cnf, rem)
75 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'wifi', True, False, d), 'CONFIG_RFKILL', cnf, rem)
76 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'bluetooth', True, False, d), 'CONFIG_RFKILL', cnf, rem)
77 return "\n".join(cnf), "\n".join(rem)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078
Brad Bishopd7bf8c12018-02-25 22:55:05 -050079# X, Y = ${@features_to_busybox_settings(d)}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080# unfortunately doesn't seem to work with bitbake, workaround:
81def features_to_busybox_conf(d):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130082 cnf, rem = features_to_busybox_settings(d)
83 return cnf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084def features_to_busybox_del(d):
Brad Bishopa5c52ff2018-11-23 10:55:50 +130085 cnf, rem = features_to_busybox_settings(d)
86 return rem
Patrick Williamsc124f4f2015-09-15 14:41:29 -050087
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050088configmangle = '/CONFIG_EXTRA_CFLAGS/d; \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089 '
90OE_FEATURES := "${@features_to_busybox_conf(d)}"
91OE_DEL := "${@features_to_busybox_del(d)}"
92DO_IPv4 := "${@bb.utils.contains('DISTRO_FEATURES', 'ipv4', 1, 0, d)}"
93DO_IPv6 := "${@bb.utils.contains('DISTRO_FEATURES', 'ipv6', 1, 0, d)}"
94
95python () {
96 if "${OE_DEL}":
97 d.setVar('configmangle_append', "${OE_DEL}" + "\n")
98 if "${OE_FEATURES}":
99 d.setVar('configmangle_append',
100 "/^### DISTRO FEATURES$/a\\\n%s\n\n" %
101 ("\\n".join((d.expand("${OE_FEATURES}").split("\n")))))
102 d.setVar('configmangle_append',
103 "/^### CROSS$/a\\\n%s\n" %
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500104 ("\\n".join(["CONFIG_EXTRA_CFLAGS=\"${CFLAGS} ${HOST_CC_ARCH}\""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105 ])
106 ))
107}
108
109do_prepare_config () {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400110 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500111 export KCONFIG_NOTIMESTAMP=1
112 fi
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500113 sed -e '/CONFIG_STATIC/d' \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 < ${WORKDIR}/defconfig > ${S}/.config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500115 echo "# CONFIG_STATIC is not set" >> .config
116 for i in 'CROSS' 'DISTRO FEATURES'; do echo "### $i"; done >> \
117 ${S}/.config
118 sed -i -e '${configmangle}' ${S}/.config
119 if test ${DO_IPv4} -eq 0 && test ${DO_IPv6} -eq 0; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800120 # disable networking applets
121 mv ${S}/.config ${S}/.config.oe-tmp
122 awk 'BEGIN{net=0}
123 /^# Networking Utilities/{net=1}
124 /^#$/{if(net){net=net+1}}
125 {if(net==2&&$0 !~ /^#/&&$1){print("# "$1" is not set")}else{print}}' \
126 ${S}/.config.oe-tmp > ${S}/.config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500127 fi
128 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 -0500129 sed -i 's|${DEBUG_PREFIX_MAP}||g' ${S}/.config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130}
131
132# returns all the elements from the src uri that are .cfg files
133def find_cfgs(d):
134 sources=src_patches(d, True)
135 sources_list=[]
136 for s in sources:
137 if s.endswith('.cfg'):
138 sources_list.append(s)
139
140 return sources_list
141
142do_configure () {
143 do_prepare_config
144 merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
145 cml1_do_configure
146}
147
148do_compile() {
149 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
Brad Bishop316dfdd2018-06-25 12:45:53 -0400150 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500151 export KCONFIG_NOTIMESTAMP=1
152 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500153 if [ "${BUSYBOX_SPLIT_SUID}" = "1" -a x`grep "CONFIG_FEATURE_INDIVIDUAL=y" .config` = x ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800154 # split the .config into two parts, and make two busybox binaries
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500155 if [ -e .config.orig ]; then
156 # Need to guard again an interrupted do_compile - restore any backup
157 cp .config.orig .config
158 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500159 cp .config .config.orig
160 oe_runmake busybox.cfg.suid
161 oe_runmake busybox.cfg.nosuid
Brad Bishop316dfdd2018-06-25 12:45:53 -0400162
163 # workaround for suid bug 10346
164 if ! grep -q "CONFIG_SH_IS_NONE" busybox.cfg.nosuid; then
165 echo "CONFIG_SH_IS_NONE" >> busybox.cfg.suid
166 fi
167
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168 for i in `cat busybox.cfg.suid busybox.cfg.nosuid`; do
169 echo "# $i is not set" >> .config.disable.apps
170 done
171 merge_config.sh -m .config.orig .config.disable.apps
172 cp .config .config.nonapps
173 for s in suid nosuid; do
174 cat busybox.cfg.$s | while read item; do
175 grep -w "$item" .config.orig
176 done > .config.app.$s
Brad Bishop316dfdd2018-06-25 12:45:53 -0400177
178 # workaround for suid bug 10346
179 if [ "$s" = "suid" ] ; then
180 sed "s/.*CONFIG_SH_IS_NONE.*$/CONFIG_SH_IS_NONE=y/" -i .config.app.suid
181 fi
182
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183 merge_config.sh -m .config.nonapps .config.app.$s
184 oe_runmake busybox_unstripped
185 mv busybox_unstripped busybox.$s
186 oe_runmake busybox.links
Brad Bishope2d5b612018-11-23 10:55:50 +1300187 sort busybox.links > busybox.links.$s
188 rm busybox.links
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500189 done
Brad Bishop316dfdd2018-06-25 12:45:53 -0400190
191 # hard fail if sh is being linked to the suid busybox (detects bug 10346)
192 if grep -q -x "/bin/sh" busybox.links.suid; then
193 bbfatal "busybox suid binary incorrectly provides /bin/sh"
194 fi
195
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500196 # copy .config.orig back to .config, because the install process may check this file
197 cp .config.orig .config
198 # cleanup
199 rm .config.orig .config.app.suid .config.app.nosuid .config.disable.apps .config.nonapps
200 else
201 oe_runmake busybox_unstripped
202 cp busybox_unstripped busybox
203 oe_runmake busybox.links
204 fi
205}
206
207do_install () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500208 sed -i "s:^/bin/:BASE_BINDIR/:" busybox.links*
209 sed -i "s:^/sbin/:BASE_SBINDIR/:" busybox.links*
210 sed -i "s:^/usr/bin/:BINDIR/:" busybox.links*
211 sed -i "s:^/usr/sbin/:SBINDIR/:" busybox.links*
212
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800213 # Move arch/link to BINDIR to match coreutils
214 sed -i "s:^BASE_BINDIR/arch:BINDIR/arch:" busybox.links*
215 sed -i "s:^BASE_BINDIR/link:BINDIR/link:" busybox.links*
216
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500217 sed -i "s:^BASE_BINDIR/:${base_bindir}/:" busybox.links*
218 sed -i "s:^BASE_SBINDIR/:${base_sbindir}/:" busybox.links*
219 sed -i "s:^BINDIR/:${bindir}/:" busybox.links*
220 sed -i "s:^SBINDIR/:${sbindir}/:" busybox.links*
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500221
222 install -d ${D}${sysconfdir}/init.d
223
224 if ! grep -q "CONFIG_FEATURE_INDIVIDUAL=y" ${B}/.config; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500225 # Install ${base_bindir}/busybox, and the ${base_bindir}/sh link so the postinst script
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500226 # can run. Let update-alternatives handle the rest.
227 install -d ${D}${base_bindir}
228 if [ "${BUSYBOX_SPLIT_SUID}" = "1" ]; then
229 install -m 4755 ${B}/busybox.suid ${D}${base_bindir}
230 install -m 0755 ${B}/busybox.nosuid ${D}${base_bindir}
231 install -m 0644 ${S}/busybox.links.suid ${D}${sysconfdir}
232 install -m 0644 ${S}/busybox.links.nosuid ${D}${sysconfdir}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400233 if grep -q "CONFIG_SH_IS_ASH=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234 ln -sf busybox.nosuid ${D}${base_bindir}/sh
235 fi
236 # Keep a default busybox for people who want to invoke busybox directly.
237 # This is also useful for the on device upgrade. Because we want
238 # to use the busybox command in postinst.
239 ln -sf busybox.nosuid ${D}${base_bindir}/busybox
240 else
241 if grep -q "CONFIG_FEATURE_SUID=y" ${B}/.config; then
242 install -m 4755 ${B}/busybox ${D}${base_bindir}
243 else
244 install -m 0755 ${B}/busybox ${D}${base_bindir}
245 fi
246 install -m 0644 ${S}/busybox.links ${D}${sysconfdir}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400247 if grep -q "CONFIG_SH_IS_ASH=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500248 ln -sf busybox ${D}${base_bindir}/sh
249 fi
250 # We make this symlink here to eliminate the error when upgrading together
251 # with busybox-syslog. Without this symlink, the opkg may think of the
252 # busybox.nosuid as obsolete and remove it, resulting in dead links like
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500253 # ${base_bindir}/sed -> ${base_bindir}/busybox.nosuid. This will make upgrading busybox-syslog fail.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254 # This symlink will be safely deleted in postinst, thus no negative effect.
255 ln -sf busybox ${D}${base_bindir}/busybox.nosuid
256 fi
257 else
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800258 install -d ${D}${base_bindir} ${D}${bindir} ${D}${libdir}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500259 cat busybox.links | while read FILE; do
260 NAME=`basename "$FILE"`
261 install -m 0755 "0_lib/$NAME" "${D}$FILE.${BPN}"
262 done
263 # add suid bit where needed
264 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
265 find ${D} -name $i.${BPN} -exec chmod a+s {} \;
266 done
267 install -m 0755 0_lib/libbusybox.so.${PV} ${D}${libdir}/libbusybox.so.${PV}
268 ln -sf sh.${BPN} ${D}${base_bindir}/sh
269 ln -sf ln.${BPN} ${D}${base_bindir}/ln
270 ln -sf test.${BPN} ${D}${bindir}/test
271 if [ -f ${D}/linuxrc.${BPN} ]; then
272 mv ${D}/linuxrc.${BPN} ${D}/linuxrc
273 fi
274 install -m 0644 ${S}/busybox.links ${D}${sysconfdir}
275 fi
276
277 if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500278 install -m 0755 ${WORKDIR}/syslog ${D}${sysconfdir}/init.d/syslog
279 install -m 644 ${WORKDIR}/syslog-startup.conf ${D}${sysconfdir}/syslog-startup.conf
280 install -m 644 ${WORKDIR}/syslog.conf ${D}${sysconfdir}/syslog.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500281 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800282 if grep -q "CONFIG_CROND=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500283 install -m 0755 ${WORKDIR}/busybox-cron ${D}${sysconfdir}/init.d/
284 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800285 if grep -q "CONFIG_HTTPD=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500286 install -m 0755 ${WORKDIR}/busybox-httpd ${D}${sysconfdir}/init.d/
287 install -d ${D}/srv/www
288 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800289 if grep -q "CONFIG_UDHCPD=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500290 install -m 0755 ${WORKDIR}/busybox-udhcpd ${D}${sysconfdir}/init.d/
291 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800292 if grep -q "CONFIG_HWCLOCK=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500293 install -m 0755 ${WORKDIR}/hwclock.sh ${D}${sysconfdir}/init.d/
294 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800295 if grep -q "CONFIG_UDHCPC=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500296 install -d ${D}${sysconfdir}/udhcpc.d
297 install -d ${D}${datadir}/udhcpc
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500298 install -m 0755 ${WORKDIR}/simple.script ${D}${sysconfdir}/udhcpc.d/50default
299 sed -i "s:/SBIN_DIR/:${base_sbindir}/:" ${D}${sysconfdir}/udhcpc.d/50default
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500300 install -m 0755 ${WORKDIR}/default.script ${D}${datadir}/udhcpc/default.script
301 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800302 if grep -q "CONFIG_INETD=y" ${B}/.config; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500303 install -m 0755 ${WORKDIR}/inetd ${D}${sysconfdir}/init.d/inetd.${BPN}
304 sed -i "s:/usr/sbin/:${sbindir}/:" ${D}${sysconfdir}/init.d/inetd.${BPN}
305 install -m 0644 ${WORKDIR}/inetd.conf ${D}${sysconfdir}/
306 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800307 if grep -q "CONFIG_MDEV=y" ${B}/.config; then
308 install -m 0755 ${WORKDIR}/mdev ${D}${sysconfdir}/init.d/mdev
309 if grep "CONFIG_FEATURE_MDEV_CONF=y" ${B}/.config; then
310 install -m 644 ${WORKDIR}/mdev.conf ${D}${sysconfdir}/mdev.conf
311 install -d ${D}${sysconfdir}/mdev
312 install -m 0755 ${WORKDIR}/find-touchscreen.sh ${D}${sysconfdir}/mdev
313 install -m 0755 ${WORKDIR}/mdev-mount.sh ${D}${sysconfdir}/mdev
314 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500315 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800316 if grep -q "CONFIG_INIT=y" ${B}/.config; then
317 install -D -m 0777 ${WORKDIR}/rcS ${D}${sysconfdir}/init.d/rcS
318 install -D -m 0777 ${WORKDIR}/rcK ${D}${sysconfdir}/init.d/rcK
319 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500320
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800321 if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
322 if grep -q "CONFIG_KLOGD=y" ${B}/.config; then
323 install -d ${D}${systemd_unitdir}/system
324 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-klogd.service.in \
325 > ${D}${systemd_unitdir}/system/busybox-klogd.service
326 fi
Brad Bishopbba38f32018-08-23 16:11:46 +0800327
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800328 if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
329 install -d ${D}${systemd_unitdir}/system
330 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-syslog.service.in \
331 > ${D}${systemd_unitdir}/system/busybox-syslog.service
332 if [ ! -e ${D}${systemd_unitdir}/system/busybox-klogd.service ] ; then
333 sed -i '/klog/d' ${D}${systemd_unitdir}/system/busybox-syslog.service
334 fi
335 if [ -f ${WORKDIR}/busybox-syslog.default ] ; then
336 install -d ${D}${sysconfdir}/default
337 install -m 0644 ${WORKDIR}/busybox-syslog.default ${D}${sysconfdir}/default/busybox-syslog
338 fi
339 fi
340 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500341
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800342 # Remove the sysvinit specific configuration file for systemd systems to avoid confusion
343 if ${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'false', 'true', d)}; then
344 rm -f ${D}${sysconfdir}/syslog-startup.conf
345 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500346}
347
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500348do_install_ptest () {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800349 cp -r ${B}/testsuite ${D}${PTEST_PATH}/
350 cp ${B}/.config ${D}${PTEST_PATH}/
351 ln -s /bin/busybox ${D}${PTEST_PATH}/busybox
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500352}
353
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500354inherit update-alternatives
355
356ALTERNATIVE_PRIORITY = "50"
357
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500358python do_package_prepend () {
359 # We need to load the full set of busybox provides from the /etc/busybox.links
360 # Use this to see the update-alternatives with the right information
361
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500362 dvar = d.getVar('D')
363 pn = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500364 def set_alternative_vars(links, target):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500365 links = d.expand(links)
366 target = d.expand(target)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500367 f = open('%s%s' % (dvar, links), 'r')
368 for alt_link_name in f:
369 alt_link_name = alt_link_name.strip()
370 alt_name = os.path.basename(alt_link_name)
371 # Match coreutils
372 if alt_name == '[':
373 alt_name = 'lbracket'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800374 if alt_name == 'klogd' or alt_name == 'syslogd':
375 d.appendVar('ALTERNATIVE_%s-syslog' % (pn), ' ' + alt_name)
376 else:
377 d.appendVar('ALTERNATIVE_%s' % (pn), ' ' + alt_name)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500378 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name)
379 if os.path.exists('%s%s' % (dvar, target)):
380 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, target)
381 f.close()
382 return
383
384 if os.path.exists('%s/etc/busybox.links' % (dvar)):
385 set_alternative_vars("${sysconfdir}/busybox.links", "${base_bindir}/busybox")
386 else:
387 set_alternative_vars("${sysconfdir}/busybox.links.nosuid", "${base_bindir}/busybox.nosuid")
388 set_alternative_vars("${sysconfdir}/busybox.links.suid", "${base_bindir}/busybox.suid")
389}
390
391pkg_postinst_${PN} () {
392 # This part of code is dedicated to the on target upgrade problem.
393 # It's known that if we don't make appropriate symlinks before update-alternatives calls,
394 # there will be errors indicating missing commands such as 'sed'.
395 # These symlinks will later be updated by update-alternatives calls.
396 test -n 2 > /dev/null || alias test='busybox test'
397 if test "x$D" = "x"; then
398 # Remove busybox.nosuid if it's a symlink, because this situation indicates
399 # that we're installing or upgrading to a one-binary busybox.
400 if test -h ${base_bindir}/busybox.nosuid; then
401 rm -f ${base_bindir}/busybox.nosuid
402 fi
403 for suffix in "" ".nosuid" ".suid"; do
404 if test -e ${sysconfdir}/busybox.links$suffix; then
405 while read link; do
406 if test ! -e "$link"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500407 # we can use busybox here because even if we are using splitted busybox
408 # we've made a symlink from /bin/busybox to /bin/busybox.nosuid.
409 busybox rm -f $link
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500410 busybox ln -s "${base_bindir}/busybox$suffix" $link
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500411 fi
412 done < ${sysconfdir}/busybox.links$suffix
413 fi
414 done
415 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500416 if grep -q "^${base_bindir}/bash$" $D${sysconfdir}/busybox.links*; then
417 grep -q "^${base_bindir}/bash$" $D${sysconfdir}/shells || echo ${base_bindir}/bash >> $D${sysconfdir}/shells
418 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500419}
420
421pkg_prerm_${PN} () {
422 # This is so you can make busybox commit suicide - removing busybox with no other packages
423 # providing its files, this will make update-alternatives work, but the update-rc.d part
424 # for syslog, httpd and/or udhcpd will fail if there is no other package providing sh
425 tmpdir=`mktemp -d /tmp/busyboxrm-XXXXXX`
426 ln -s ${base_bindir}/busybox $tmpdir/[
427 ln -s ${base_bindir}/busybox $tmpdir/test
428 ln -s ${base_bindir}/busybox $tmpdir/head
429 ln -s ${base_bindir}/busybox $tmpdir/sh
430 ln -s ${base_bindir}/busybox $tmpdir/basename
431 ln -s ${base_bindir}/busybox $tmpdir/echo
432 ln -s ${base_bindir}/busybox $tmpdir/mv
433 ln -s ${base_bindir}/busybox $tmpdir/ln
434 ln -s ${base_bindir}/busybox $tmpdir/dirname
435 ln -s ${base_bindir}/busybox $tmpdir/rm
436 ln -s ${base_bindir}/busybox $tmpdir/sed
437 ln -s ${base_bindir}/busybox $tmpdir/sort
438 ln -s ${base_bindir}/busybox $tmpdir/grep
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500439 ln -s ${base_bindir}/busybox $tmpdir/tail
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500440 export PATH=$PATH:$tmpdir
441}
442
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500443pkg_postrm_${PN} () {
444 if grep -q "^${base_bindir}/bash$" $D${sysconfdir}/busybox.links* && [ ! -e $D${base_bindir}/bash ]; then
445 printf "$(grep -v "^${base_bindir}/bash$" $D${sysconfdir}/shells)\n" > $D${sysconfdir}/shells
446 fi
447}
448
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500449pkg_prerm_${PN}-syslog () {
450 # remove syslog
451 if test "x$D" = "x"; then
452 if test "$1" = "upgrade" -o "$1" = "remove"; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600453 ${sysconfdir}/init.d/syslog stop || :
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500454 fi
455 fi
456}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500457
458RPROVIDES_${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', '/bin/sh', '', d)}"