summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/busybox/busybox.inc
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/busybox/busybox.inc')
-rw-r--r--meta/recipes-core/busybox/busybox.inc406
1 files changed, 406 insertions, 0 deletions
diff --git a/meta/recipes-core/busybox/busybox.inc b/meta/recipes-core/busybox/busybox.inc
new file mode 100644
index 0000000000..e59afe67bc
--- /dev/null
+++ b/meta/recipes-core/busybox/busybox.inc
@@ -0,0 +1,406 @@
1SUMMARY = "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}"
20export EXTRA_OEMAKE += "'LD=${CCLD}'"
21
22PACKAGES =+ "${PN}-httpd ${PN}-udhcpd ${PN}-udhcpc ${PN}-syslog ${PN}-mdev ${PN}-hwclock"
23
24FILES_${PN}-httpd = "${sysconfdir}/init.d/busybox-httpd /srv/www"
25FILES_${PN}-syslog = "${sysconfdir}/init.d/syslog* ${sysconfdir}/syslog-startup.conf* ${sysconfdir}/syslog.conf* ${systemd_unitdir}/system/syslog.service ${sysconfdir}/default/busybox-syslog"
26FILES_${PN}-mdev = "${sysconfdir}/init.d/mdev ${sysconfdir}/mdev.conf"
27FILES_${PN}-udhcpd = "${sysconfdir}/init.d/busybox-udhcpd"
28FILES_${PN}-udhcpc = "${sysconfdir}/udhcpc.d ${datadir}/udhcpc"
29FILES_${PN}-hwclock = "${sysconfdir}/init.d/hwclock.sh"
30
31INITSCRIPT_PACKAGES = "${PN}-httpd ${PN}-syslog ${PN}-udhcpd ${PN}-mdev ${PN}-hwclock"
32
33INITSCRIPT_NAME_${PN}-httpd = "busybox-httpd"
34INITSCRIPT_NAME_${PN}-hwclock = "hwclock.sh"
35INITSCRIPT_NAME_${PN}-mdev = "mdev"
36INITSCRIPT_PARAMS_${PN}-mdev = "start 03 S ."
37INITSCRIPT_NAME_${PN}-syslog = "syslog"
38INITSCRIPT_NAME_${PN}-udhcpd = "busybox-udhcpd"
39
40SYSTEMD_PACKAGES = "${PN}-syslog"
41SYSTEMD_SERVICE_${PN}-syslog = "busybox-syslog.service"
42
43CONFFILES_${PN}-syslog = "${sysconfdir}/syslog-startup.conf.${BPN}"
44CONFFILES_${PN}-mdev = "${sysconfdir}/mdev.conf"
45
46RRECOMMENDS_${PN} = "${PN}-syslog ${PN}-udhcpc"
47
48inherit cml1 systemd update-rc.d ptest
49
50# internal helper
51def busybox_cfg(feature, tokens, cnf, rem):
52 if type(tokens) == type(""):
53 tokens = [tokens]
54 rem.extend(['/^[# ]*' + token + '[ =]/d' for token in tokens])
55 if feature:
56 cnf.extend([token + '=y' for token in tokens])
57 else:
58 cnf.extend(['# ' + token + ' is not set' for token in tokens])
59
60# Map distro features to config settings
61def features_to_busybox_settings(d):
62 cnf, rem = ([], [])
63 busybox_cfg(base_contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IPV6', cnf, rem)
64 busybox_cfg(base_contains('DISTRO_FEATURES', 'largefile', True, False, d), 'CONFIG_LFS', cnf, rem)
65 busybox_cfg(base_contains('DISTRO_FEATURES', 'largefile', True, False, d), 'CONFIG_FDISK_SUPPORT_LARGE_DISKS', cnf, rem)
66 busybox_cfg(base_contains('DISTRO_FEATURES', 'nls', True, False, d), 'CONFIG_LOCALE_SUPPORT', cnf, rem)
67 busybox_cfg(base_contains('DISTRO_FEATURES', 'ipv4', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV4', cnf, rem)
68 busybox_cfg(base_contains('DISTRO_FEATURES', 'ipv6', True, False, d), 'CONFIG_FEATURE_IFUPDOWN_IPV6', cnf, rem)
69 busybox_cfg(base_contains('DISTRO_FEATURES', 'wifi', True, False, d), 'CONFIG_RFKILL', cnf, rem)
70 busybox_cfg(base_contains('DISTRO_FEATURES', 'bluetooth', True, False, d), 'CONFIG_RFKILL', cnf, rem)
71 return "\n".join(cnf), "\n".join(rem)
72
73# X, Y = ${@features_to_uclibc_settings(d)}
74# unfortunately doesn't seem to work with bitbake, workaround:
75def features_to_busybox_conf(d):
76 cnf, rem = features_to_busybox_settings(d)
77 return cnf
78def features_to_busybox_del(d):
79 cnf, rem = features_to_busybox_settings(d)
80 return rem
81
82configmangle = '/CROSS_COMPILER_PREFIX/d; \
83 /CONFIG_EXTRA_CFLAGS/d; \
84 '
85OE_FEATURES := "${@features_to_busybox_conf(d)}"
86OE_DEL := "${@features_to_busybox_del(d)}"
87DO_IPv4 := "${@base_contains('DISTRO_FEATURES', 'ipv4', 1, 0, d)}"
88DO_IPv6 := "${@base_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" %
99 ("\\n".join(["CONFIG_CROSS_COMPILER_PREFIX=\"${TARGET_PREFIX}\"",
100 "CONFIG_EXTRA_CFLAGS=\"${CFLAGS}\" \"${HOST_CC_ARCH}\""
101 ])
102 ))
103}
104
105do_prepare_config () {
106 sed -e 's#@DATADIR@#${datadir}#g' \
107 < ${WORKDIR}/defconfig > ${S}/.config
108 sed -i -e '/CONFIG_STATIC/d' .config
109 echo "# CONFIG_STATIC is not set" >> .config
110 for i in 'CROSS' 'DISTRO FEATURES'; do echo "### $i"; done >> \
111 ${S}/.config
112 sed -i -e '${configmangle}' ${S}/.config
113 if test ${DO_IPv4} -eq 0 && test ${DO_IPv6} -eq 0; then
114 # disable networking applets
115 mv ${S}/.config ${S}/.config.oe-tmp
116 awk 'BEGIN{net=0}
117 /^# Networking Utilities/{net=1}
118 /^#$/{if(net){net=net+1}}
119 {if(net==2&&$0 !~ /^#/&&$1){print("# "$1" is not set")}else{print}}' \
120 ${S}/.config.oe-tmp > ${S}/.config
121 fi
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 () {
174 if [ "${prefix}" != "/usr" ]; then
175 sed -i "s:^/usr/:${prefix}/:" busybox.links*
176 fi
177 if [ "${base_sbindir}" != "/sbin" ]; then
178 sed -i "s:^/sbin/:${base_sbindir}/:" busybox.links*
179 fi
180
181 install -d ${D}${sysconfdir}/init.d
182
183 if ! grep -q "CONFIG_FEATURE_INDIVIDUAL=y" ${B}/.config; then
184 # Install /bin/busybox, and the /bin/sh link so the postinst script
185 # can run. Let update-alternatives handle the rest.
186 install -d ${D}${base_bindir}
187 if [ "${BUSYBOX_SPLIT_SUID}" = "1" ]; then
188 install -m 4755 ${B}/busybox.suid ${D}${base_bindir}
189 install -m 0755 ${B}/busybox.nosuid ${D}${base_bindir}
190 install -m 0644 ${S}/busybox.links.suid ${D}${sysconfdir}
191 install -m 0644 ${S}/busybox.links.nosuid ${D}${sysconfdir}
192 if grep -q "CONFIG_FEATURE_SH_IS_ASH=y" ${B}/.config; then
193 ln -sf busybox.nosuid ${D}${base_bindir}/sh
194 fi
195 # Keep a default busybox for people who want to invoke busybox directly.
196 # This is also useful for the on device upgrade. Because we want
197 # to use the busybox command in postinst.
198 ln -sf busybox.nosuid ${D}${base_bindir}/busybox
199 else
200 if grep -q "CONFIG_FEATURE_SUID=y" ${B}/.config; then
201 install -m 4755 ${B}/busybox ${D}${base_bindir}
202 else
203 install -m 0755 ${B}/busybox ${D}${base_bindir}
204 fi
205 install -m 0644 ${S}/busybox.links ${D}${sysconfdir}
206 if grep -q "CONFIG_FEATURE_SH_IS_ASH=y" ${B}/.config; then
207 ln -sf busybox ${D}${base_bindir}/sh
208 fi
209 # We make this symlink here to eliminate the error when upgrading together
210 # with busybox-syslog. Without this symlink, the opkg may think of the
211 # busybox.nosuid as obsolete and remove it, resulting in dead links like
212 # /bin/sed -> /bin/busybox.nosuid. This will make upgrading busybox-syslog fail.
213 # This symlink will be safely deleted in postinst, thus no negative effect.
214 ln -sf busybox ${D}${base_bindir}/busybox.nosuid
215 fi
216 else
217 install -d ${D}${base_bindir} ${D}${base_sbindir}
218 install -d ${D}${libdir} ${D}${bindir} ${D}${sbindir}
219 cat busybox.links | while read FILE; do
220 NAME=`basename "$FILE"`
221 install -m 0755 "0_lib/$NAME" "${D}$FILE.${BPN}"
222 done
223 # add suid bit where needed
224 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
225 find ${D} -name $i.${BPN} -exec chmod a+s {} \;
226 done
227 install -m 0755 0_lib/libbusybox.so.${PV} ${D}${libdir}/libbusybox.so.${PV}
228 ln -sf sh.${BPN} ${D}${base_bindir}/sh
229 ln -sf ln.${BPN} ${D}${base_bindir}/ln
230 ln -sf test.${BPN} ${D}${bindir}/test
231 if [ -f ${D}/linuxrc.${BPN} ]; then
232 mv ${D}/linuxrc.${BPN} ${D}/linuxrc
233 fi
234 install -m 0644 ${S}/busybox.links ${D}${sysconfdir}
235 fi
236
237 if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
238 install -m 0755 ${WORKDIR}/syslog ${D}${sysconfdir}/init.d/syslog.${BPN}
239 install -m 644 ${WORKDIR}/syslog-startup.conf ${D}${sysconfdir}/syslog-startup.conf.${BPN}
240 install -m 644 ${WORKDIR}/syslog.conf ${D}${sysconfdir}/syslog.conf.${BPN}
241 fi
242 if grep "CONFIG_CROND=y" ${B}/.config; then
243 install -m 0755 ${WORKDIR}/busybox-cron ${D}${sysconfdir}/init.d/
244 fi
245 if grep "CONFIG_HTTPD=y" ${B}/.config; then
246 install -m 0755 ${WORKDIR}/busybox-httpd ${D}${sysconfdir}/init.d/
247 install -d ${D}/srv/www
248 fi
249 if grep "CONFIG_UDHCPD=y" ${B}/.config; then
250 install -m 0755 ${WORKDIR}/busybox-udhcpd ${D}${sysconfdir}/init.d/
251 fi
252 if grep "CONFIG_HWCLOCK=y" ${B}/.config; then
253 install -m 0755 ${WORKDIR}/hwclock.sh ${D}${sysconfdir}/init.d/
254 fi
255 if grep "CONFIG_UDHCPC=y" ${B}/.config; then
256 install -d ${D}${sysconfdir}/udhcpc.d
257 install -d ${D}${datadir}/udhcpc
258 install -m 0755 ${WORKDIR}/simple.script ${D}${sysconfdir}/udhcpc.d/50default
259 install -m 0755 ${WORKDIR}/default.script ${D}${datadir}/udhcpc/default.script
260 fi
261 if grep "CONFIG_INETD=y" ${B}/.config; then
262 install -m 0755 ${WORKDIR}/inetd ${D}${sysconfdir}/init.d/inetd.${BPN}
263 sed -i "s:/usr/sbin/:${sbindir}/:" ${D}${sysconfdir}/init.d/inetd.${BPN}
264 install -m 0644 ${WORKDIR}/inetd.conf ${D}${sysconfdir}/
265 fi
266 if grep "CONFIG_MDEV=y" ${B}/.config; then
267 install -m 0755 ${WORKDIR}/mdev ${D}${sysconfdir}/init.d/mdev
268 if grep "CONFIG_FEATURE_MDEV_CONF=y" ${B}/.config; then
269 install -m 644 ${WORKDIR}/mdev.conf ${D}${sysconfdir}/mdev.conf
270 fi
271 fi
272
273 if ${@base_contains('DISTRO_FEATURES','systemd','true','false',d)}; then
274 install -d ${D}${systemd_unitdir}/system
275 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-syslog.service.in \
276 > ${D}${systemd_unitdir}/system/busybox-syslog.service
277 sed 's,@base_sbindir@,${base_sbindir},g' < ${WORKDIR}/busybox-klogd.service.in \
278 > ${D}${systemd_unitdir}/system/busybox-klogd.service
279
280 if [ -f ${WORKDIR}/busybox-syslog.default ] ; then
281 install -d ${D}${sysconfdir}/default
282 install -m 0644 ${WORKDIR}/busybox-syslog.default ${D}${sysconfdir}/default/busybox-syslog
283 fi
284
285 ln -sf /dev/null ${D}${systemd_unitdir}/system/syslog.service
286 fi
287
288 # Remove the sysvinit specific configuration file for systemd systems to avoid confusion
289 if ${@base_contains('DISTRO_FEATURES', 'sysvinit', 'false', 'true', d)}; then
290 rm -f ${D}${sysconfdir}/syslog-startup.conf.${BPN}
291 fi
292}
293
294inherit update-alternatives
295
296ALTERNATIVE_PRIORITY = "50"
297
298ALTERNATIVE_${PN}-syslog += "syslog-conf"
299ALTERNATIVE_LINK_NAME[syslog-conf] = "${sysconfdir}/syslog.conf"
300
301python () {
302 if base_contains('DISTRO_FEATURES', 'sysvinit', True, False, d):
303 pn = d.getVar('PN', True)
304 d.appendVar('ALTERNATIVE_%s-syslog' % (pn), ' syslog-init')
305 d.setVarFlag('ALTERNATIVE_LINK_NAME', 'syslog-init', '%s/init.d/syslog' % (d.getVar('sysconfdir', True)))
306 d.setVarFlag('ALTERNATIVE_TARGET', 'syslog-init', '%s/init.d/syslog.%s' % (d.getVar('sysconfdir', True), d.getVar('BPN', True)))
307 d.appendVar('ALTERNATIVE_%s-syslog' % (pn), ' syslog-startup-conf')
308 d.setVarFlag('ALTERNATIVE_LINK_NAME', 'syslog-startup-conf', '%s/syslog-startup.conf' % (d.getVar('sysconfdir', True)))
309 d.setVarFlag('ALTERNATIVE_TARGET', 'syslog-startup-conf', '%s/syslog-startup.conf.%s' % (d.getVar('sysconfdir', True), d.getVar('BPN', True)))
310}
311
312python do_package_prepend () {
313 # We need to load the full set of busybox provides from the /etc/busybox.links
314 # Use this to see the update-alternatives with the right information
315
316 dvar = d.getVar('D', True)
317 pn = d.getVar('PN', True)
318 def set_alternative_vars(links, target):
319 f = open('%s%s' % (dvar, links), 'r')
320 for alt_link_name in f:
321 alt_link_name = alt_link_name.strip()
322 alt_name = os.path.basename(alt_link_name)
323 # Match coreutils
324 if alt_name == '[':
325 alt_name = 'lbracket'
326 d.appendVar('ALTERNATIVE_%s' % (pn), ' ' + alt_name)
327 d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name)
328 if os.path.exists('%s%s' % (dvar, target)):
329 d.setVarFlag('ALTERNATIVE_TARGET', alt_name, target)
330 f.close()
331 return
332
333 if os.path.exists('%s/etc/busybox.links' % (dvar)):
334 set_alternative_vars("/etc/busybox.links", "/bin/busybox")
335 else:
336 set_alternative_vars("/etc/busybox.links.nosuid", "/bin/busybox.nosuid")
337 set_alternative_vars("/etc/busybox.links.suid", "/bin/busybox.suid")
338}
339
340pkg_postinst_${PN} () {
341 # This part of code is dedicated to the on target upgrade problem.
342 # It's known that if we don't make appropriate symlinks before update-alternatives calls,
343 # there will be errors indicating missing commands such as 'sed'.
344 # These symlinks will later be updated by update-alternatives calls.
345 test -n 2 > /dev/null || alias test='busybox test'
346 if test "x$D" = "x"; then
347 # Remove busybox.nosuid if it's a symlink, because this situation indicates
348 # that we're installing or upgrading to a one-binary busybox.
349 if test -h /bin/busybox.nosuid; then
350 rm -f /bin/busybox.nosuid
351 fi
352 for suffix in "" ".nosuid" ".suid"; do
353 if test -e /etc/busybox.links$suffix; then
354 while read link; do
355 if test ! -e "$link"; then
356 case "$link" in
357 /*/*/*)
358 to="../../bin/busybox$suffix"
359 ;;
360 /bin/*)
361 to="busybox$suffix"
362 ;;
363 /*/*)
364 to="../bin/busybox$suffix"
365 ;;
366 esac
367 # we can use busybox here because even if we are using splitted busybox
368 # we've made a symlink from /bin/busybox to /bin/busybox.nosuid.
369 busybox rm -f $link
370 busybox ln -s $to $link
371 fi
372 done < /etc/busybox.links$suffix
373 fi
374 done
375 fi
376}
377
378pkg_prerm_${PN} () {
379 # This is so you can make busybox commit suicide - removing busybox with no other packages
380 # providing its files, this will make update-alternatives work, but the update-rc.d part
381 # for syslog, httpd and/or udhcpd will fail if there is no other package providing sh
382 tmpdir=`mktemp -d /tmp/busyboxrm-XXXXXX`
383 ln -s /bin/busybox $tmpdir/[
384 ln -s /bin/busybox $tmpdir/test
385 ln -s /bin/busybox $tmpdir/head
386 ln -s /bin/busybox $tmpdir/sh
387 ln -s /bin/busybox $tmpdir/basename
388 ln -s /bin/busybox $tmpdir/echo
389 ln -s /bin/busybox $tmpdir/mv
390 ln -s /bin/busybox $tmpdir/ln
391 ln -s /bin/busybox $tmpdir/dirname
392 ln -s /bin/busybox $tmpdir/rm
393 ln -s /bin/busybox $tmpdir/sed
394 ln -s /bin/busybox $tmpdir/sort
395 ln -s /bin/busybox $tmpdir/grep
396 export PATH=$PATH:$tmpdir
397}
398
399pkg_prerm_${PN}-syslog () {
400 # remove syslog
401 if test "x$D" = "x"; then
402 if test "$1" = "upgrade" -o "$1" = "remove"; then
403 /etc/init.d/syslog stop
404 fi
405 fi
406}