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