]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/create-busybox-container
test: add test cases for RuntimeDirectoryPreserve=yes
[thirdparty/systemd.git] / test / create-busybox-container
1 #!/usr/bin/env bash
2
3 set -e
4 set -u
5 set -o pipefail
6
7 root="${1:?Usage $0 container-root}"
8 mkdir -p "$root"
9 mkdir "$root/bin"
10 cp $(type -P busybox) "$root/bin"
11
12 os_release=$(test -e /etc/os-release && echo /etc/os-release || echo /usr/lib/os-release)
13 ID_LIKE=$(awk -F= '$1=="ID_LIKE" { print $2 ;}' $os_release)
14 if [[ "$ID_LIKE" = *"suse"* ]]; then
15 mkdir -p "$root/lib"
16 mkdir -p "$root/lib64"
17 for lib in $(find /lib*/ld*); do
18 [[ -d $root/$(dirname $lib) ]] || mkdir -p $root/$(dirname $lib)
19 cp $lib $root/$lib
20 done
21 fi
22
23 mkdir -p "$root/usr/lib"
24 touch "$root/usr/lib/os-release"
25
26 ln -s busybox "$root/bin/sh"
27 ln -s busybox "$root/bin/cat"
28 ln -s busybox "$root/bin/tr"
29 ln -s busybox "$root/bin/ps"
30 ln -s busybox "$root/bin/ip"
31
32 mkdir -p "$root/sbin"
33 cat <<'EOF' >"$root/sbin/init"
34 #!/bin/sh
35
36 printf "ps aufx:\n"
37 ps aufx
38
39 printf "/proc/1/cmdline:\n"
40 printf "%s\n\n" "$(tr '\0' ' ' </proc/1/cmdline)"
41
42 printf "/proc/1/environ:\n"
43 printf "%s\n\n" "$(tr '\0' '\n' </proc/1/environ)"
44
45 printf "/proc/1/mountinfo:\n"
46 cat /proc/self/mountinfo
47 printf "\n"
48
49 printf "/proc/1/cgroup:\n"
50 printf "%s\n\n" "$(cat /proc/1/cgroup)"
51
52 printf "/proc/1/uid_map:\n"
53 printf "%s\n\n" "$(cat /proc/1/uid_map)"
54
55 printf "/proc/1/setgroups:\n"
56 printf "%s\n\n" "$(cat /proc/1/setgroups)"
57
58 printf "/proc/1/gid_map:\n"
59 printf "%s\n\n" "$(cat /proc/1/gid_map)"
60
61 printf "ip link:\n"
62 ip link
63 EOF
64 chmod +x "$root/sbin/init"