1#!/usr/bin/env bash
2# SPDX-License-Identifier: LGPL-2.1-or-later
3
4set -e
5set -u
6set -o pipefail
7
8root="${1:?Usage $0 container-root}"
9mkdir -p "$root"
10mkdir "$root/bin"
11
12# On openSUSE the static linked version of busybox is named "busybox-static".
13busybox="$(type -P busybox-static || type -P busybox)"
14cp "$busybox" "$root/bin/busybox"
15
16mkdir -p "$root/usr/lib"
17touch "$root/usr/lib/os-release"
18
19ln -s busybox "$root/bin/sh"
20ln -s busybox "$root/bin/cat"
21ln -s busybox "$root/bin/tr"
22ln -s busybox "$root/bin/ps"
23ln -s busybox "$root/bin/ip"
24ln -s busybox "$root/bin/seq"
25ln -s busybox "$root/bin/sleep"
26ln -s busybox "$root/bin/usleep"
27ln -s busybox "$root/bin/test"
28
29mkdir -p "$root/sbin"
30cat <<'EOF' >"$root/sbin/init"
31#!/bin/sh
32
33printf "ps aufx:\n"
34ps aufx
35
36printf "/proc/1/cmdline:\n"
37printf "%s\n\n" "$(tr '\0' ' ' </proc/1/cmdline)"
38
39printf "/proc/1/environ:\n"
40printf "%s\n\n" "$(tr '\0' '\n' </proc/1/environ)"
41
42printf "/proc/1/mountinfo:\n"
43cat /proc/self/mountinfo
44printf "\n"
45
46printf "/proc/1/cgroup:\n"
47printf "%s\n\n" "$(cat /proc/1/cgroup)"
48
49printf "/proc/1/uid_map:\n"
50printf "%s\n\n" "$(cat /proc/1/uid_map)"
51
52printf "/proc/1/setgroups:\n"
53printf "%s\n\n" "$(cat /proc/1/setgroups)"
54
55printf "/proc/1/gid_map:\n"
56printf "%s\n\n" "$(cat /proc/1/gid_map)"
57
58printf "ip link:\n"
59ip link
60EOF
61chmod +x "$root/sbin/init"
62