Systemd/test/TEST-13-NSPAWN-SMOKE/create-busybox-container
Jörg Thalheim ff12a7954c treewide: more portable bash shebangs
As in 2a5fcfae02
and in 3e67e5c992
using /usr/bin/env allows bash to be looked up in PATH
rather than being hard-coded.

As with the previous changes the same arguments apply
- distributions have scripts to rewrite shebangs on installation and
  they know what locations to rely on.
- For tests/compilation we should rather rely on the user to have setup
  there PATH correctly.

In particular this makes testing from git easier on NixOS where do not provide
/bin/bash to improve compose-ability.
2020-03-05 17:27:07 +01:00

54 lines
1 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
set -u
set -o pipefail
root="${1:?Usage $0 container-root}"
mkdir -p "$root"
mkdir "$root/bin"
cp $(type -P busybox) "$root/bin"
mkdir -p "$root/usr/lib"
touch "$root/usr/lib/os-release"
ln -s busybox "$root/bin/sh"
ln -s busybox "$root/bin/cat"
ln -s busybox "$root/bin/tr"
ln -s busybox "$root/bin/ps"
ln -s busybox "$root/bin/ip"
mkdir -p "$root/sbin"
cat <<'EOF' >"$root/sbin/init"
#!/bin/sh
printf "ps aufx:\n"
ps aufx
printf "/proc/1/cmdline:\n"
printf "%s\n\n" "$(tr '\0' ' ' </proc/1/cmdline)"
printf "/proc/1/environ:\n"
printf "%s\n\n" "$(tr '\0' '\n' </proc/1/environ)"
printf "/proc/1/mountinfo:\n"
cat /proc/self/mountinfo
printf "\n"
printf "/proc/1/cgroup:\n"
printf "%s\n\n" "$(cat /proc/1/cgroup)"
printf "/proc/1/uid_map:\n"
printf "%s\n\n" "$(cat /proc/1/uid_map)"
printf "/proc/1/setgroups:\n"
printf "%s\n\n" "$(cat /proc/1/setgroups)"
printf "/proc/1/gid_map:\n"
printf "%s\n\n" "$(cat /proc/1/gid_map)"
printf "ip link:\n"
ip link
EOF
chmod +x "$root/sbin/init"