]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-22-TMPFILES/test-02.sh
tmpfiles: add more tests
[thirdparty/systemd.git] / test / TEST-22-TMPFILES / test-02.sh
1 #! /bin/bash
2 #
3 # Basic tests for types creating directories
4 #
5
6 set -e
7 set -x
8
9 rm -fr /tmp/{d,D,e}
10 mkdir /tmp/{d,D,e}
11
12 #
13 # 'd'
14 #
15 mkdir /tmp/d/2
16 chmod 777 /tmp/d/2
17
18 systemd-tmpfiles --create - <<EOF
19 d /tmp/d/1 0755 daemon daemon - -
20 d /tmp/d/2 0755 daemon daemon - -
21 EOF
22
23 test -d /tmp/d/1
24 test $(stat -c %U:%G:%a /tmp/d/1) = "daemon:daemon:755"
25
26 test -d /tmp/d/2
27 test $(stat -c %U:%G:%a /tmp/d/2) = "daemon:daemon:755"
28
29 #
30 # 'D'
31 #
32 mkdir /tmp/D/2
33 chmod 777 /tmp/D/2
34 touch /tmp/D/2/foo
35
36 systemd-tmpfiles --create - <<EOF
37 D /tmp/D/1 0755 daemon daemon - -
38 D /tmp/D/2 0755 daemon daemon - -
39 EOF
40
41 test -d /tmp/D/1
42 test $(stat -c %U:%G:%a /tmp/D/1) = "daemon:daemon:755"
43
44 test -d /tmp/D/2
45 test $(stat -c %U:%G:%a /tmp/D/2) = "daemon:daemon:755"
46
47 systemd-tmpfiles --remove - <<EOF
48 D /tmp/D/2 0755 daemon daemon - -
49 EOF
50
51 # the content of '2' should be removed
52 test "$(echo /tmp/D/2/*)" = "/tmp/D/2/*"
53
54 #
55 # 'e'
56 #
57 mkdir -p /tmp/e/2/{d1,d2}
58 chmod 777 /tmp/e/2
59 chmod 777 /tmp/e/2/d*
60
61 systemd-tmpfiles --create - <<EOF
62 e /tmp/e/1 0755 daemon daemon - -
63 e /tmp/e/2/* 0755 daemon daemon - -
64 EOF
65
66 ! test -d /tmp/e/1
67
68 test -d /tmp/e/2
69 test $(stat -c %U:%G:%a /tmp/e/2) = "root:root:777"
70
71 test -d /tmp/e/2/d1
72 test $(stat -c %U:%G:%a /tmp/e/2/d1) = "daemon:daemon:755"
73 test -d /tmp/e/2/d2
74 test $(stat -c %U:%G:%a /tmp/e/2/d2) = "daemon:daemon:755"
75
76 # 'e' operates on directories only
77 mkdir -p /tmp/e/3/{d1,d2}
78 chmod 777 /tmp/e/3
79 chmod 777 /tmp/e/3/d*
80 touch /tmp/e/3/f1
81 chmod 644 /tmp/e/3/f1
82
83 ! systemd-tmpfiles --create - <<EOF
84 e /tmp/e/3/* 0755 daemon daemon - -
85 EOF
86
87 # the directories should have been processed although systemd-tmpfiles failed
88 # previously due to the presence of a file.
89 test -d /tmp/e/3/d1
90 test $(stat -c %U:%G:%a /tmp/e/3/d1) = "daemon:daemon:755"
91 test -d /tmp/e/3/d2
92 test $(stat -c %U:%G:%a /tmp/e/3/d2) = "daemon:daemon:755"
93
94 test -f /tmp/e/3/f1
95 test $(stat -c %U:%G:%a /tmp/e/3/f1) = "root:root:644"