blob: adc6e9a717be0d0f5fd8493165ff7a8fe16d0e08 [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"
42SYSTEMD_SERVICE_${PN}-syslog = "busybox-syslog.service"
43
44CONFFILES_${PN}-syslog = "${sysconfdir}/syslog-startup.conf.${BPN}"
45CONFFILES_${PN}-mdev = "${sysconfdir}/mdev.conf"
46
47RRECOMMENDS_${PN} = "${PN}-syslog ${PN}-udhcpc"
48
49inherit cml1 systemd update-rc.d ptest
50
51# internal helper
52def busybox_cfg(feature, tokens, cnf, rem):
53 if type(tokens) == type(""):
54 tokens = [tokens]
55 rem.extend(['/^[# ]*' + token + '[ =]/d' for token in tokens])
56 if feature:
57 cnf.extend([token + '=y' for token in tokens])
58 else:
59 cnf.extend(['# ' + token + ' is not set' for token in tokens])
60
61# Map distro features to config settings
62def features_to_busybox_settings(d):
63 cnf, rem = ([], [])
64 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IPV6', cnf, rem)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065 busybox_cfg(True, 'CONFIG_LFS', cnf, rem)
66 busybox_cfg(True, 'CONFIG_FDISK_SUPPORT_LARGE_DISKS', cnf, rem)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'nls', True, False, d), 'CONFIG_LOCALE_SUPPORT', cnf, rem)
68 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv4', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV4', cnf, rem)
69 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV6', cnf, rem)
70 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'wifi', True, False, d), 'CONFIG_RFKILL', cnf, rem)
71 busybox_cfg(bb.utils.contains('DISTRO_FEATURES', 'bluetooth', True, False, d), 'CONFIG_RFKILL', cnf, rem)
72 return "\n".join(cnf), "\n".join(rem)
73
74# X, Y = ${@features_to_uclibc_settings(d)}
75# unfortunately doesn't seem to work with bitbake, workaround:
76def features_to_busybox_conf(d):
77 cnf, rem = features_to_busybox_settings(d)
78 return cnf
79def features_to_busybox_del(d):
80 cnf, rem = features_to_busybox_settings(d)
81 return rem
82
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050083configmangle = '/CONFIG_EXTRA_CFLAGS/d; \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084 '
85OE_FEATURES := "${@features_to_busybox_conf(d)}"
86OE_DEL := "${@features_to_busybox_del(d)}"
87DO_IPv4 := "${@bb.utils.contains('DISTRO_FEATURES', 'ipv4', 1, 0, d)}"
88DO_IPv6 := "${@bb.utils.contains('DISTRO_FEATURES', 'ipv6', 1, 0, d)}"
89
90python () {
91 if "${OE_DEL}":
92 d.setVar('configmangle_append', "${OE_DEL}" + "\n")
93 if "${OE_FEATURES}":
94 d.setVar('configmangle_append',
95 "/^### DISTRO FEATURES$/a\\\n%s\n\n" %
96 ("\\n".join((d.expand("${OE_FEATURES}").split("\n")))))
97 d.setVar('configmangle_append',
98 "/^### CROSS$/a\\\n%s\n" %
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050099 ("\\n".join(["CONFIG_EXTRA_CFLAGS=\"${CFLAGS} ${HOST_CC_ARCH}\""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100 ])
101 ))
102}
103
104do_prepare_config () {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500105 sed -e '/CONFIG_STATIC/d' \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500106 < ${WORKDIR}/defconfig > ${S}/.config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 echo "# CONFIG_STATIC is not set" >> .config
108 for i in 'CROSS' 'DISTRO FEATURES'; do echo "### $i"; done >> \
109 ${S}/.config
110 sed -i -e '${configmangle}' ${S}/.config
111 if test ${DO_IPv4} -eq 0 && test ${DO_IPv6} -eq 0; then
112 # disable networking applets
113 mv ${S}/.config ${S}/.config.oe-tmp
114 awk 'BEGIN{net=0}
115 /^# Networking Utilities/{net=1}
116 /^#$/{if(net){net=net+1}}
117 {if(net==2&&$0 !~ /^#/&&$1){print("# "$1" is not set")}else{print}}' \
118 ${S}/.config.oe-tmp > ${S}/.config
119 fi
120 sed -i 's/CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -n"/CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -b"/' ${S}/.config
121}
122
123# returns all the elements from the src uri that are .cfg files
124def find_cfgs(d):
125 sources=src_patches(d, True)
126 sources_list=[]
127 for s in sources:
128 if s.endswith('.cfg'):
129 sources_list.append(s)
130
131 return sources_list
132
133do_configure () {
134 do_prepare_config
135 merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
136 cml1_do_configure
137}
138
139do_compile() {
140 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
141 if [ "${BUSYBOX_SPLIT_SUID}" = "1" -a x`grep "CONFIG_FEATURE_INDIVIDUAL=y" .config` = x ]; then
142 # split the .config into two parts, and make two busybox binaries
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500143 if [ -e .config.orig ]; then
144 # Need to guard again an interrupted do_compile - restore any backup
145 cp .config.orig .config
146 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500147 cp .config .config.orig
148 oe_runmake busybox.cfg.suid
149 oe_runmake busybox.cfg.nosuid
150 for i in `cat busybox.cfg.suid busybox.cfg.nosuid`; do
151 echo "# $i is not set" >> .config.disable.apps
152 done
153 merge_config.sh -m .config.orig .config.disable.apps
154 cp .config .config.nonapps
155 for s in suid nosuid; do
156 cat busybox.cfg.$s | while read item; do
157 grep -w "$item" .config.orig
158 done > .config.app.$s
159 merge_config.sh -m .config.nonapps .config.app.$s
160 oe_runmake busybox_unstripped
161 mv busybox_unstripped busybox.$s
162 oe_runmake busybox.links
163 mv busybox.links busybox.links.$s
164 done
165 # copy .config.orig back to .config, because the install process may check this file
166 cp .config.orig .config
167 # cleanup
168 rm .config.orig .config.app.suid .config.app.nosuid .config.disable.apps .config.nonapps
169 else
170 oe_runmake busybox_unstripped
171 cp busybox_unstripped busybox
172 oe_runmake busybox.links
173 fi
174}
175
176do_install () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500177 sed -i "s:^/bin/:BASE_BINDIR/:" busybox.links*
178 sed -i "s:^/sbin/:BASE_SBINDIR/:" busybox.links*
179 sed -i "s:^/usr/bin/:BINDIR/:" busybox.links*
180 sed -i "s:^/usr/sbin/:SBINDIR/:" busybox.links*
181
182 sed -i "s:^BASE_BINDIR/:${base_bindir}/:" busybox.links*
183 sed -i "s:^BASE_SBINDIR/:${base_sbindir}/:" busybox.links*
184 sed -i "s:^BINDIR/:${bindir}/:" busybox.links*
185 sed -i "s:^SBINDIR/:${sbindir}/:" busybox.links*
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186
187 install -d ${D}${sysconfdir}/init.d
188
189 if ! grep -q "CONFIG_FEATURE_INDIVIDUAL=y" ${B}/.config; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500190 # Install ${base_bindir}/busybox, and the ${base_bindir}/sh link so the postinst script
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191 # can run. Let update-alternatives handle the rest.
192 install -d ${D}${base_bindir}
193 if [ "${BUSYBOX_SPLIT_SUID}" = "1" ]; then
194 install -m 4755 ${B}/busybox.suid ${D}${base_bindir}
195 install -m 0755 ${B}/busybox.nosuid ${D}${base_bindir}
196 install -m 0644 ${S}/busybox.links.suid ${D}${sysconfdir}
197 install -m 0644 ${S}/busybox.links.nosuid ${D}${sysconfdir}
198 if grep -q "CONFIG_FEATURE_SH_IS_ASH=y" ${B}/.config; then
199 ln -sf busybox.nosuid ${D}${base_bindir}/sh
200 fi
201 # Keep a default busybox for people who want to invoke busybox directly.
202 # This is also useful for the on device upgrade. Because we want
203 # to use the busybox command in postinst.
204 ln -sf busybox.nosuid ${D}${base_bindir}/busybox
205 else
206 if grep -q "CONFIG_FEATURE_SUID=y" ${B}/.config; then
207 install -m 4755 ${B}/busybox ${D}${base_bindir}
208 else
209 install -m 0755 ${B}/busybox ${D}${base_bindir}
210 fi
211 install -m 0644 ${S}/busybox.links ${D}${sysconfdir}
212 if grep -q "CONFIG_FEATURE_SH_IS_ASH=y" ${B}/.config; then
213 ln -sf busybox ${D}${base_bindir}/sh
214 fi
215 # We make this symlink here to eliminate the error when upgrading together
216 # with busybox-syslog. Without this symlink, the opkg may think of the
217 # busybox.nosuid as obsolete and remove it, resulting in dead links like
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500218 # ${base_bindir}/sed -> ${base_bindir}/busybox.nosuid. This will make upgrading busybox-syslog fail.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500219 # This symlink will be safely deleted in postinst, thus no negative effect.
220 ln -sf busybox ${D}${base_bindir}/busybox.nosuid
221 fi
222 else
223 install -d ${D}${base_bindir} ${D}${base_sbindir}
224 install -d ${D}${libdir} ${D}${bindir} ${D}${sbindir}
225 cat busybox.links | while read FILE; do
226 NAME=`basename "$FILE"`
227 install -m 0755 "0_lib/$NAME" "${D}$FILE.${BPN}"
228 done
229 # add suid bit where needed
230 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
231 find ${D} -name $i.${BPN} -exec chmod a+s {} \;
232 done
233 install -m 0755 0_lib/libbusybox.so.${PV} ${D}${libdir}/libbusybox.so.${PV}
234 ln -sf sh.${BPN} ${D}${base_bindir}/sh
235 ln -sf ln.${BPN} ${D}${base_bindir}/ln
236 ln -sf test.${BPN} ${D}${bindir}/test
237 if [ -f ${D}/linuxrc.${BPN} ]; then
238 mv ${D}/linuxrc.${BPN} ${D}/linuxrc
239 fi
240 install -m 0644 ${S}/busybox.links ${D}${sysconfdir}
241 fi
242
243 if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
244 install -m 0755 ${WORKDIR}/syslog ${D}${sysconfdir}/init.d/syslog.${BPN}
245 install -m 644 ${WORKDIR}/syslog-startup.conf ${D}${sysconfdir}/syslog-startup.conf.${BPN}
246 install -m 644 ${WORKDIR}/syslog.conf ${D}${sysconfdir}/syslog.conf.${BPN}
247 fi
248 if grep "CONFIG_CROND=y" ${B}/.config; then
249 install -m 0755 ${WORKDIR}/busybox-cron ${D}${sysconfdir}/init.d/
250 fi
251 if grep "CONFIG_HTTPD=y" ${B}/.config; then
252 install -m 0755 ${WORKDIR}/busybox-httpd ${D}${sysconfdir}/init.d/
253 install -d ${D}/srv/www
254 fi
255 if grep "CONFIG_UDHCPD=y" ${B}/.config; then
256 install -m 0755 ${WORKDIR}/busybox-udhcpd ${D}${sysconfdir}/init.d/
257 fi
258 if grep "CONFIG_HWCLOCK=y" ${B}/.config; then
259 install -m 0755 ${WORKDIR}/hwclock.sh ${D}${sysconfdir}/init.d/
260 fi
261 if grep "CONFIG_UDHCPC=y" ${B}/.config; then
262 install -d ${D}${sysconfdir}/udhcpc.d
263 install -d ${D}${datadir}/udhcpc
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500264 install -m 0755 ${WORKDIR}/simple.script ${D}${sysconfdir}/udhcpc.d/50default
265 sed -i "s:/SBIN_DIR/:${base_sbindir}/:" ${D}${sysconfdir}/udhcpc.d/50default
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266 install -m 0755 ${WORKDIR}/default.script ${D}${datadir}/udhcpc/default.script
267 fi
268 if grep "CONFIG_INETD=y" ${B}/.config; then
269 install -m 0755 ${WORKDIR}/inetd ${D}${sysconfdir}/init.d/inetd.${BPN}
270 sed -i "s:/usr/sbin/:${sbindir}/:" ${D}${sysconfdir}/init.d/inetd.${BPN}
271 install -m 0644 ${WORKDIR}/inetd.conf ${D}${sysconfdir}/
272 fi
273 if grep "CONFIG_MDEV=y" ${B}/.config; then
274 install -m 0755 ${WORKDIR}/mdev ${D}${sysconfdir}/init.d/mdev
275 if grep "CONFIG_FEATURE_MDEV_CONF=y" ${B}/.config; then
276 install -m 644 ${WORKDIR}/mdev.conf ${D}${sysconfdir}/mdev.conf
277 install -d ${D}${sysconfdir}/mdev
278 install -m 0755 ${WORKDIR}/find-touchscreen.sh ${D}${sysconfdir}/mdev
279 install -m 0755 ${WORKDIR}/mdev-mount.sh ${D}${sysconfdir}/mdev
280 fi
281 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500282 if grep "CONFIG_INIT=y" ${B}/.config; then
283 install -D -m 0777 ${WORKDIR}/rcS ${D}${sysconfdir}/init.d/rcS
284 install -D -m 0777 ${WORKDIR}/rcK ${D}${sysconfdir}/init.d/rcK
285 install -D -m 0755 ${WORKDIR}/runlevel ${D}${base_sbindir}/runlevel
286 if grep "CONFIG_FEATURE_USE_INITTAB=y" ${B}/.config; then
287 install -D -m 0777 ${WORKDIR}/inittab ${D}${sysconfdir}/inittab
288 tmp="${SERIAL_CONSOLES}"
289 for i in $tmp
290 do
291 j=`echo ${i} | sed s/\;/\ /g`
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600292 id=`echo ${i} | sed -e 's/^.*;//' -e 's/;.*//'`
293 echo "$id::respawn:${base_sbindir}/getty ${j}" >> ${D}${sysconfdir}/inittab
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500294 done
295 fi
296 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500297
298 if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
299 if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
300 install -d ${D}${systemd_unitdir}/system
301 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-syslog.service.in \
302 > ${D}${systemd_unitdir}/system/busybox-syslog.service
303 if [ -f ${WORKDIR}/busybox-syslog.default ] ; then
304 install -d ${D}${sysconfdir}/default
305 install -m 0644 ${WORKDIR}/busybox-syslog.default ${D}${sysconfdir}/default/busybox-syslog
306 fi
307 ln -sf /dev/null ${D}${systemd_unitdir}/system/syslog.service
308 fi
309 if grep -q "CONFIG_KLOGD=y" ${B}/.config; then
310 install -d ${D}${systemd_unitdir}/system
311 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-klogd.service.in \
312 > ${D}${systemd_unitdir}/system/busybox-klogd.service
313 fi
314 fi
315
316 # Remove the sysvinit specific configuration file for systemd systems to avoid confusion
317 if ${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'false', 'true', d)}; then
318 rm -f ${D}${sysconfdir}/syslog-startup.conf.${BPN}
319 fi
320}
321
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500322do_install_ptest () {
323 cp -r ${B}/testsuite ${D}${PTEST_PATH}/
324 cp ${B}/.config ${D}${PTEST_PATH}/
325 ln -s /bin/busybox ${D}${PTEST_PATH}/busybox
326}
327
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500328inherit update-alternatives
329
330ALTERNATIVE_PRIORITY = "50"
331
332ALTERNATIVE_${PN}-syslog += "syslog-conf"
333ALTERNATIVE_LINK_NAME[syslog-conf] = "${sysconfdir}/syslog.conf"
334
335python () {
336 if bb.utils.contains('DISTRO_FEATURES', 'sysvinit', True, False, d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500337 pn = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500338 d.appendVar('ALTERNATIVE_%s-syslog' % (pn), ' syslog-init')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500339 d.setVarFlag('ALTERNATIVE_LINK_NAME', 'syslog-init', '%s/init.d/syslog' % (d.getVar('sysconfdir')))
340 d.setVarFlag('ALTERNATIVE_TARGET', 'syslog-init', '%s/init.d/syslog.%s' % (d.getVar('sysconfdir'), d.getVar('BPN')))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500341 d.appendVar('ALTERNATIVE_%s-syslog' % (pn), ' syslog-startup-conf')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500342 d.setVarFlag('ALTERNATIVE_LINK_NAME', 'syslog-startup-conf', '%s/syslog-startup.conf' % (d.getVar('sysconfdir')))
343 d.setVarFlag('ALTERNATIVE_TARGET', 'syslog-startup-conf', '%s/syslog-startup.conf.%s' % (d.getVar('sysconfdir'), d.getVar('BPN')))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500344}
345
346python do_package_prepend () {
347 # We need to load the full set of busybox provides from the /etc/busybox.links
348 # Use this to see the update-alternatives with the right information
349
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500350 dvar = d.getVar('D')
351 pn = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500352 def set_alternative_vars(links, target):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500353 links = d.expand(links)
354 target = d.expand(target)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500355 f = open('%s%s' % (dvar, links), 'r')
356 for alt_link_name in f:
357 alt_link_name = alt_link_name.strip()
358 alt_name = os.path.basename(alt_link_name)
359 # Match coreutils
360 if alt_name == '[':
361 alt_name = 'lbracket'
362 d.appendVar('ALTERNATIVE_%s' % (pn), ' ' + alt_name)
363 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name)
364 if os.path.exists('%s%s' % (dvar, target)):
365 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, target)
366 f.close()
367 return
368
369 if os.path.exists('%s/etc/busybox.links' % (dvar)):
370 set_alternative_vars("${sysconfdir}/busybox.links", "${base_bindir}/busybox")
371 else:
372 set_alternative_vars("${sysconfdir}/busybox.links.nosuid", "${base_bindir}/busybox.nosuid")
373 set_alternative_vars("${sysconfdir}/busybox.links.suid", "${base_bindir}/busybox.suid")
374}
375
376pkg_postinst_${PN} () {
377 # This part of code is dedicated to the on target upgrade problem.
378 # It's known that if we don't make appropriate symlinks before update-alternatives calls,
379 # there will be errors indicating missing commands such as 'sed'.
380 # These symlinks will later be updated by update-alternatives calls.
381 test -n 2 > /dev/null || alias test='busybox test'
382 if test "x$D" = "x"; then
383 # Remove busybox.nosuid if it's a symlink, because this situation indicates
384 # that we're installing or upgrading to a one-binary busybox.
385 if test -h ${base_bindir}/busybox.nosuid; then
386 rm -f ${base_bindir}/busybox.nosuid
387 fi
388 for suffix in "" ".nosuid" ".suid"; do
389 if test -e ${sysconfdir}/busybox.links$suffix; then
390 while read link; do
391 if test ! -e "$link"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500392 # we can use busybox here because even if we are using splitted busybox
393 # we've made a symlink from /bin/busybox to /bin/busybox.nosuid.
394 busybox rm -f $link
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500395 busybox ln -s "${base_bindir}/busybox$suffix" $link
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500396 fi
397 done < ${sysconfdir}/busybox.links$suffix
398 fi
399 done
400 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500401 if grep -q "^${base_bindir}/bash$" $D${sysconfdir}/busybox.links*; then
402 grep -q "^${base_bindir}/bash$" $D${sysconfdir}/shells || echo ${base_bindir}/bash >> $D${sysconfdir}/shells
403 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500404}
405
406pkg_prerm_${PN} () {
407 # This is so you can make busybox commit suicide - removing busybox with no other packages
408 # providing its files, this will make update-alternatives work, but the update-rc.d part
409 # for syslog, httpd and/or udhcpd will fail if there is no other package providing sh
410 tmpdir=`mktemp -d /tmp/busyboxrm-XXXXXX`
411 ln -s ${base_bindir}/busybox $tmpdir/[
412 ln -s ${base_bindir}/busybox $tmpdir/test
413 ln -s ${base_bindir}/busybox $tmpdir/head
414 ln -s ${base_bindir}/busybox $tmpdir/sh
415 ln -s ${base_bindir}/busybox $tmpdir/basename
416 ln -s ${base_bindir}/busybox $tmpdir/echo
417 ln -s ${base_bindir}/busybox $tmpdir/mv
418 ln -s ${base_bindir}/busybox $tmpdir/ln
419 ln -s ${base_bindir}/busybox $tmpdir/dirname
420 ln -s ${base_bindir}/busybox $tmpdir/rm
421 ln -s ${base_bindir}/busybox $tmpdir/sed
422 ln -s ${base_bindir}/busybox $tmpdir/sort
423 ln -s ${base_bindir}/busybox $tmpdir/grep
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500424 ln -s ${base_bindir}/busybox $tmpdir/tail
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500425 export PATH=$PATH:$tmpdir
426}
427
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500428pkg_postrm_${PN} () {
429 if grep -q "^${base_bindir}/bash$" $D${sysconfdir}/busybox.links* && [ ! -e $D${base_bindir}/bash ]; then
430 printf "$(grep -v "^${base_bindir}/bash$" $D${sysconfdir}/shells)\n" > $D${sysconfdir}/shells
431 fi
432}
433
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500434pkg_prerm_${PN}-syslog () {
435 # remove syslog
436 if test "x$D" = "x"; then
437 if test "$1" = "upgrade" -o "$1" = "remove"; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600438 ${sysconfdir}/init.d/syslog stop || :
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500439 fi
440 fi
441}