Files
BMLFS/build-scripts/busybox.build

125 lines
5.9 KiB
Bash

#! /bin/bash
# Busybox
# Source: https://busybox.net/downloads/busybox-1.35.0.tar.bz2
#
# $BUILD = Directory to temporarily install
# $PKGS = Directory to store built packages
#
# DEPS
# Required: openssl
# Recommended: zip
# Optional: NONE
# Apply patches from Alpine Linux
patch -Np1 -i ../patches/busybox-alpine/0001-adduser-default-to-sbin-nologin-as-shell-for-system-.patch
patch -Np1 -i ../patches/busybox-alpine/0001-ash-add-built-in-BB_ASH_VERSION-variable.patch
patch -Np1 -i ../patches/busybox-alpine/0001-avoid-redefined-warnings-when-building-with-utmps.patch
patch -Np1 -i ../patches/busybox-alpine/0001-libbb-sockaddr2str-ensure-only-printable-characters-.patch
patch -Np1 -i ../patches/busybox-alpine/0001-modutils-check-ELF-header-before-calling-finit_module.patch
patch -Np1 -i ../patches/busybox-alpine/0001-nologin-Install-applet-to-sbin-instead-of-usr-sbin.patch
patch -Np1 -i ../patches/busybox-alpine/0001-pgrep-add-support-for-matching-against-UID-and-RUID.patch
patch -Np1 -i ../patches/busybox-alpine/0001-properly-fix-wget-https-support.patch
patch -Np1 -i ../patches/busybox-alpine/0002-fsck-resolve-LABEL-.-UUID-.-spec-to-device.patch
patch -Np1 -i ../patches/busybox-alpine/0002-nslookup-sanitize-all-printed-strings-with-printable.patch
patch -Np1 -i ../patches/busybox-alpine/0003-ash-exec-busybox.static.patch
patch -Np1 -i ../patches/busybox-alpine/0004-app-location-for-cpio-vi-and-lspci.patch
patch -Np1 -i ../patches/busybox-alpine/0005-udhcpc-set-default-discover-retries-to-5.patch
patch -Np1 -i ../patches/busybox-alpine/0006-ping-make-ping-work-without-root-privileges.patch
patch -Np1 -i ../patches/busybox-alpine/0007-fbsplash-support-console-switching.patch
patch -Np1 -i ../patches/busybox-alpine/0008-fbsplash-support-image-and-bar-alignment-and-positio.patch
patch -Np1 -i ../patches/busybox-alpine/0009-depmod-support-generating-kmod-binary-index-files.patch
patch -Np1 -i ../patches/busybox-alpine/0010-Add-flag-for-not-following-symlinks-when-recursing.patch
patch -Np1 -i ../patches/busybox-alpine/0012-udhcpc-Don-t-background-if-n-is-given.patch
patch -Np1 -i ../patches/busybox-alpine/0013-ash-fix-unsafe-use-of-mempcpy.patch
patch -Np1 -i ../patches/busybox-alpine/0014-ash-fix-use-after-free-in-bash-pattern-substitution.patch
patch -Np1 -i ../patches/busybox-alpine/0015-ed-don-t-use-memcpy-with-overlapping-memory-regions.patch
patch -Np1 -i ../patches/busybox-alpine/0016-ash-don-t-read-past-end-of-var-in-subvareval-for-bas.patch
# Create directories for different builds
mkdir -pv build-static build-dynamic build-dynamic-extras
# Build bbsuid
gcc ../files/busybox-alpine/bbsuid.c -o build-dynamic/bbsuid
# Build ssl_client
gcc $(pkg-config --cflags libcrypto libssl) \
../files/busybox-alpine/ssl_client.c -o \
build-dynamic/ssl_client $(pkg-config --libs libcrypto libssl)
# Build dynamic
cd build-dynamic
cp -v ../../files/busybox-alpine/busyboxconfig .config
sed -i -e "s/CONFIG_EXTRA_COMPAT=y/CONFIG_EXTRA_COMPAT=n/" .config
make -C .. O="$PWD" silentoldconfig
make CONFIG_EXTRA_CFLAGS="$(pkg-config --cflags --static utmps)" \
CONFIG_EXTRA_LDLIBS="$(pkg-config --libs --static utmps)"
cd ..
# build dynamic (extras)
cd build-dynamic-extras
cp -v ../../files/busybox-alpine/busyboxconfig-extras .config
sed -i -e "s/CONFIG_EXTRA_COMPAT=y/CONFIG_EXTRA_COMPAT=n/" .config
make -C .. O="$PWD" silentoldconfig
make
cd ..
# build static
cd build-static
sed -e "s/.*CONFIG_PIE.*/\# CONFIG_PIE is not set/" \
-e "s/.*CONFIG_STATIC\([A-Z_]*\).*/CONFIG_STATIC\1=y/" \
-e "s/.*CONFIG_SSL_CLIENT.*/CONFIG_SSL_CLIENT=y/" \
"../../files/busybox-alpine/busyboxconfig" > .config
sed -i -e "s/CONFIG_EXTRA_COMPAT=y/CONFIG_EXTRA_COMPAT=n/" .config
make -C .. O="$PWD" silentoldconfig
make
mv busybox busybox.static
cd ..
# Install
sudo -S mkdir -pv $BUILD/usr/bin /BMAN/install \
/BMAN/usr/share/man/man1 && \
sudo -S install -m755 build-dynamic/busybox $BUILD/usr/bin/busybox && \
sudo -S install -m 644 build-dynamic/docs/busybox.1 /BMAN/usr/share/man/man1/busybox.1 && \
cd ..
sudo -S install -Dm755 build-dynamic-extras/busybox $BUILD/usr/bin/busybox-extras && \
sudo -S install -m4111 build-dynamic/bbsuid $BUILD/usr/bin/bbsuid && \
sudo -S install -m755 build-static/busybox.static $BUILD/usr/bin/busybox.static && \
sudo -S install -m755 build-dynamic/ssl_client $BUILD/usr/bin/ssl_client && \
cd $BUILD && sudo -S mkdir -v ${BUILD}/install &&
cat > /tmp/slack-desc << "EOF"
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':' except on otherwise blank lines.
|-----handy-ruler------------------------------------------------------|
busybox: busybox
busybox:
busybox: BusyBox combines tiny versions of many common UNIX utilities into a
busybox: single small executable. It provides replacements for most of the
busybox: utilities you usually find in GNU fileutils, shellutils, etc.
busybox:
busybox: https://busybox.net/
busybox:
EOF
sudo -S mv -v /tmp/slack-desc install/ &&
sudo -S makepkg -l y -c n $PKGS/busybox-1.35.0-$(uname -m)-mlfs.txz &&
cd /BMAN && \
cat > /tmp/slack-desc << "EOF"
busybox-doc: Manpage for busybox
busybox-doc:
busybox-doc: BusyBox combines tiny versions of many common UNIX utilities into a
busybox-doc: single small executable. It provides replacements for most of the
busybox-doc: utilities you usually find in GNU fileutils, shellutils, etc.
busybox-doc:
busybox-doc: https://busybox.net/
busybox-doc:
EOF
sudo -S mv -v /tmp/slack-desc install/ && \
sudo -S makepkg -l y -c n $PKGS/busybox-doc-1.35.0-noarch-mlfs.txz && \
sudo -S rm -rf ${BUILD}/* /BMAN/*