summaryrefslogtreecommitdiff
path: root/test/create-busybox-container
blob: 73d8066cc6ba8a23ea3c5edb8e7c026d0baf6dd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later

set -eu
set -o pipefail

root="${1:?Usage: $0 container-root}"
mkdir -p "$root"
mkdir "$root/bin"

# On openSUSE the static linked version of busybox is named "busybox-static".
busybox="$(type -P busybox-static || type -P busybox)"
cp "$busybox" "$root/bin/busybox"

mkdir -p "$root/usr/lib"
touch "$root/usr/lib/os-release"

ln -s busybox "$root/bin/cat"
ln -s busybox "$root/bin/ip"
ln -s busybox "$root/bin/md5sum"
ln -s busybox "$root/bin/ps"
ln -s busybox "$root/bin/seq"
ln -s busybox "$root/bin/sh"
ln -s busybox "$root/bin/sleep"
ln -s busybox "$root/bin/stat"
ln -s busybox "$root/bin/test"
ln -s busybox "$root/bin/touch"
ln -s busybox "$root/bin/tr"
ln -s busybox "$root/bin/usleep"

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"