1#!/usr/bin/env bash 2set -e 3 4rootfsDir="$1" 5shift 6 7busybox="$(which busybox 2>/dev/null || true)" 8if [ -z "$busybox" ]; then 9 echo >&2 'error: busybox: not found' 10 echo >&2 ' install it with your distribution "busybox-static" package' 11 exit 1 12fi 13if ! ldd "$busybox" 2>&1 | grep -q 'not a dynamic executable'; then 14 echo >&2 "error: '$busybox' appears to be a dynamic executable" 15 echo >&2 ' you should install your distribution "busybox-static" package instead' 16 exit 1 17fi 18 19mkdir -p "$rootfsDir/bin" 20rm -f "$rootfsDir/bin/busybox" # just in case 21cp "$busybox" "$rootfsDir/bin/busybox" 22 23( 24 cd "$rootfsDir" 25 26 IFS=$'\n' 27 modules=( $(bin/busybox --list-modules) ) 28 unset IFS 29 30 for module in "${modules[@]}"; do 31 mkdir -p "$(dirname "$module")" 32 ln -sf /bin/busybox "$module" 33 done 34) 35