unos-repository

APK repository for unos
git clone git://git.finwo.net/misc/unos-repository
Log | Files | Refs | README

test_busybox.sh (3030B)


      1 #!/bin/sh
      2 set -eu
      3 HERE=$(cd "$(dirname "$0")" && pwd)
      4 ROOT=$(cd "${HERE}/../.." && pwd)
      5 . "${HERE}/../helpers.sh"
      6 
      7 echo "==> test_busybox: applet policy"
      8 
      9 # Locate the busybox we built. The version is globbed rather than hardcoded so
     10 # a template version bump does not silently turn this test into a skip.
     11 BUSYBOX=""
     12 for c in "${ROOT}"/build/work/busybox/src/busybox-*/busybox; do
     13   [ -x "${c}" ] && BUSYBOX=${c}
     14 done
     15 
     16 # Deliberately no fallback to a host busybox. The previous version fell back to
     17 # whatever `busybox` was on PATH, which tests a completely unrelated binary's
     18 # applet policy: on a machine without busybox it reported our required applets
     19 # missing, and on a machine with a full busybox it would have passed while
     20 # telling us nothing about the package.
     21 if [ -z "${BUSYBOX}" ]; then
     22   echo "SKIP: busybox not built yet (run ./mk/build.sh busybox)"
     23   echo "==> test_busybox done"
     24   exit 0
     25 fi
     26 
     27 have=$("$BUSYBOX" --list 2>/dev/null || echo "")
     28 [ -n "${have}" ] || { echo "FAIL: ${BUSYBOX} --list produced nothing" >&2; exit 1; }
     29 
     30 for a in init halt poweroff reboot getty login mount umount switch_root ash runsv runsvdir sv svlogd chpst setuidgid tcpsvd udhcpc; do
     31   echo "$have" | grep -qx "$a" || { echo "FAIL: required $a missing" >&2; exit 1; }
     32   echo "PASS: busybox has $a"
     33 done
     34 
     35 for a in ip tc ldconfig unlzma lzcat lzma unxz xzcat xz udhcpd httpd inetd ifup ifdown; do
     36   if echo "$have" | grep -qx "$a"; then
     37     echo "FAIL: forbidden $a present" >&2; exit 1
     38   fi
     39   echo "PASS: busybox no $a"
     40 done
     41 
     42 # Exactly one package may provide `ip`. The old form of this check looked for
     43 # rootfs/sbin/ip, but an assembled rootfs is the OS-assembly repo's output and
     44 # does not exist here; asserting it at the package level tests the same
     45 # invariant one layer earlier, and apk would refuse the overwrite anyway.
     46 IPROUTE_APK=$(newest_apk iproute2)
     47 if [ -n "${IPROUTE_APK}" ]; then
     48   if tar -tf "${IPROUTE_APK}" 2>/dev/null | grep -qx "sbin/ip"; then
     49     echo "PASS: iproute2 package provides sbin/ip"
     50   else
     51     echo "FAIL: iproute2 package does not provide sbin/ip" >&2; exit 1
     52   fi
     53 else
     54   echo "SKIP: iproute2 not built yet"
     55 fi
     56 
     57 BUSYBOX_APK=$(newest_apk busybox)
     58 if [ -n "${BUSYBOX_APK}" ]; then
     59   if tar -tf "${BUSYBOX_APK}" 2>/dev/null | grep -qE '(^|/)(s?bin)/ip$'; then
     60     echo "FAIL: busybox package also provides ip (collides with iproute2)" >&2; exit 1
     61   fi
     62   echo "PASS: busybox package does not provide ip"
     63 else
     64   echo "SKIP: busybox not built yet"
     65 fi
     66 
     67 # The applet list above proves ifup is absent from this build; the .config
     68 # check proves it was turned off deliberately rather than dropped by accident.
     69 # Derived from $BUSYBOX so it cannot point at a different version than the
     70 # binary we just interrogated.
     71 BBCONFIG="$(dirname "${BUSYBOX}")/.config"
     72 assert_path_exists "${BBCONFIG}" "busybox .config present"
     73 if grep -q "^# CONFIG_IFUP is not set" "${BBCONFIG}"; then
     74   echo "PASS: busybox .config IFUP off"
     75 else
     76   echo "FAIL: busybox .config IFUP not off" >&2; exit 1
     77 fi
     78 
     79 echo "==> test_busybox done"