60 lines
3.1 KiB
Bash
Executable File
60 lines
3.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# Build auditable option/olsr payloads. No third-party prepatched binaries.
|
|
set -eu
|
|
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
|
CACHE="$ROOT/build/runtime-sources"
|
|
mkdir -p "$CACHE"
|
|
fetch() {
|
|
url=$1 file=$2 checksum=$3
|
|
if [ ! -f "$file" ]; then curl --fail --location "$url" -o "$file"; fi
|
|
printf '%s %s\n' "$checksum" "$file" | sha256sum -c -
|
|
}
|
|
fetch https://musl.cc/arm-linux-musleabi-cross.tgz "$CACHE/toolchain.tgz" \
|
|
d70c607101fee5330083463feacf5992892a85b826d1626094500e0c37ec7d25
|
|
if [ ! -d "$CACHE/arm-linux-musleabi-cross" ]; then tar -xzf "$CACHE/toolchain.tgz" -C "$CACHE"; fi
|
|
export CROSS_COMPILE="$CACHE/arm-linux-musleabi-cross/bin/arm-linux-musleabi-"
|
|
fetch https://busybox.net/downloads/busybox-1.37.0.tar.bz2 "$CACHE/busybox.tar.bz2" \
|
|
3311dff32e746499f4df0d5df04d7eb396382d7e108bb9250e7b519b837043a4
|
|
if [ ! -d "$CACHE/busybox-1.37.0" ]; then tar -xjf "$CACHE/busybox.tar.bz2" -C "$CACHE"; fi
|
|
SOURCE="$CACHE/busybox-1.37.0"
|
|
make -C "$SOURCE" CROSS_COMPILE="$CROSS_COMPILE" allnoconfig
|
|
python3 - "$SOURCE/.config" <<'PY'
|
|
from pathlib import Path
|
|
import sys
|
|
path = Path(sys.argv[1])
|
|
settings = ['STATIC', 'LFS', 'ASH', 'SH_IS_ASH', 'BASH_IS_ASH', 'ASH_BASH_COMPAT', 'ASH_PRINTF', 'ASH_ECHO', 'ASH_TEST',
|
|
'FEATURE_FANCY_HEAD', 'CAT', 'CHMOD', 'CP', 'DATE', 'ECHO', 'GREP', 'HEAD', 'ID', 'IP',
|
|
'FEATURE_IP_ADDRESS', 'FEATURE_IP_LINK', 'FEATURE_IP_ROUTE',
|
|
'FEATURE_IP_RULE', 'KILL', 'LS', 'MKDIR', 'MKFIFO', 'MOUNT', 'MV', 'PRINTF',
|
|
'READLINK', 'RM', 'SED', 'SHA256SUM', 'SLEEP', 'STAT', 'TAIL',
|
|
'TEST', 'TIMEOUT', 'UMOUNT', 'UNAME']
|
|
text = path.read_text()
|
|
for setting in settings:
|
|
text = text.replace(f'# CONFIG_{setting} is not set', f'CONFIG_{setting}=y')
|
|
text = text.replace('CONFIG_SH_IS_NONE=y', '# CONFIG_SH_IS_NONE is not set')
|
|
text = text.replace('CONFIG_BASH_IS_NONE=y', '# CONFIG_BASH_IS_NONE is not set')
|
|
path.write_text(text)
|
|
PY
|
|
# Defaults for any Kconfig dependencies introduced by enabling applets.
|
|
python3 - "$SOURCE" "$CROSS_COMPILE" <<'PY'
|
|
import subprocess, sys
|
|
subprocess.run(['make', '-C', sys.argv[1], 'CROSS_COMPILE=' + sys.argv[2], 'oldconfig'],
|
|
input=b'\n' * 4096, check=True, stdout=subprocess.DEVNULL)
|
|
PY
|
|
make -C "$SOURCE" -j"${JOBS:-2}" CROSS_COMPILE="$CROSS_COMPILE"
|
|
mkdir -p "$ROOT/build/option-root/bin" "$ROOT/build/option-root/share/licenses"
|
|
cp "$SOURCE/busybox" "$ROOT/build/option-root/bin/busybox"
|
|
ln -sfn busybox "$ROOT/build/option-root/bin/bash"
|
|
ln -sfn busybox "$ROOT/build/option-root/bin/sh"
|
|
# Make enabled applets usable in the interactive shell too.
|
|
for applet in cat chmod cp date echo grep head id ip kill ls mkdir mkfifo mount mv printf readlink rm sed sha256sum sleep stat tail test timeout umount uname; do
|
|
ln -sfn busybox "$ROOT/build/option-root/bin/$applet"
|
|
done
|
|
cp "$SOURCE/LICENSE" "$ROOT/build/option-root/share/licenses/busybox.txt"
|
|
cp "$SOURCE/.config" "$ROOT/build/option-root/share/busybox.config"
|
|
printf '%s\n' 'BusyBox utilities only. No license generator, shell unlock, or loader patch.' \
|
|
> "$ROOT/build/option-root/share/STATUS.txt"
|
|
"$ROOT/tools/build-olsrd.sh"
|
|
|
|
"$ROOT/tools/build-bird.sh"
|