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