1#!/usr/bin/env bash
2# SPDX-License-Identifier: LGPL-2.1-or-later
3# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
4# ex: ts=8 sw=4 sts=4 et filetype=sh
5set -eux
6set -o pipefail
7
8cat >/etc/systemd/system/testservice.service <<EOF
9[Service]
10ConfigurationDirectory=testservice
11RuntimeDirectory=testservice
12StateDirectory=testservice
13CacheDirectory=testservice
14LogsDirectory=testservice
15RuntimeDirectoryPreserve=yes
16ExecStart=/bin/sleep infinity
17Type=exec
18EOF
19
20systemctl daemon-reload
21
22test ! -e /etc/testservice
23test ! -e /run/testservice
24test ! -e /var/lib/testservice
25test ! -e /var/cache/testservice
26test ! -e /var/log/testservice
27
28systemctl start testservice
29
30test -d /etc/testservice
31test -d /run/testservice
32test -d /var/lib/testservice
33test -d /var/cache/testservice
34test -d /var/log/testservice
35
36systemctl clean testservice && { echo 'unexpected success'; exit 1; }
37
38systemctl stop testservice
39
40test -d /etc/testservice
41test -d /run/testservice
42test -d /var/lib/testservice
43test -d /var/cache/testservice
44test -d /var/log/testservice
45
46systemctl clean testservice --what=configuration
47
48test ! -e /etc/testservice
49test -d /run/testservice
50test -d /var/lib/testservice
51test -d /var/cache/testservice
52test -d /var/log/testservice
53
54systemctl clean testservice
55
56test ! -e /etc/testservice
57test ! -e /run/testservice
58test -d /var/lib/testservice
59test ! -e /var/cache/testservice
60test -d /var/log/testservice
61
62systemctl clean testservice --what=logs
63
64test ! -e /etc/testservice
65test ! -e /run/testservice
66test -d /var/lib/testservice
67test ! -e /var/cache/testservice
68test ! -e /var/log/testservice
69
70systemctl clean testservice --what=all
71
72test ! -e /etc/testservice
73test ! -e /run/testservice
74test ! -e /var/lib/testservice
75test ! -e /var/cache/testservice
76test ! -e /var/log/testservice
77
78cat >/etc/systemd/system/testservice.service <<EOF
79[Service]
80DynamicUser=yes
81ConfigurationDirectory=testservice
82RuntimeDirectory=testservice
83StateDirectory=testservice
84CacheDirectory=testservice
85LogsDirectory=testservice
86RuntimeDirectoryPreserve=yes
87ExecStart=/bin/sleep infinity
88Type=exec
89EOF
90
91systemctl daemon-reload
92
93test ! -e /etc/testservice
94test ! -e /run/testservice
95test ! -e /var/lib/testservice
96test ! -e /var/cache/testservice
97test ! -e /var/log/testservice
98
99systemctl restart testservice
100
101test -d /etc/testservice
102test -d /run/private/testservice
103test -d /var/lib/private/testservice
104test -d /var/cache/private/testservice
105test -d /var/log/private/testservice
106test -L /run/testservice
107test -L /var/lib/testservice
108test -L /var/cache/testservice
109test -L /var/log/testservice
110
111systemctl clean testservice && { echo 'unexpected success'; exit 1; }
112
113systemctl stop testservice
114
115test -d /etc/testservice
116test -d /run/private/testservice
117test -d /var/lib/private/testservice
118test -d /var/cache/private/testservice
119test -d /var/log/private/testservice
120test -L /run/testservice
121test -L /var/lib/testservice
122test -L /var/cache/testservice
123test -L /var/log/testservice
124
125systemctl clean testservice --what=configuration
126
127test ! -d /etc/testservice
128test -d /run/private/testservice
129test -d /var/lib/private/testservice
130test -d /var/cache/private/testservice
131test -d /var/log/private/testservice
132test -L /run/testservice
133test -L /var/lib/testservice
134test -L /var/cache/testservice
135test -L /var/log/testservice
136
137systemctl clean testservice
138
139test ! -d /etc/testservice
140test ! -d /run/private/testservice
141test -d /var/lib/private/testservice
142test ! -d /var/cache/private/testservice
143test -d /var/log/private/testservice
144test ! -L /run/testservice
145test -L /var/lib/testservice
146test ! -L /var/cache/testservice
147test -L /var/log/testservice
148
149systemctl clean testservice --what=logs
150
151test ! -d /etc/testservice
152test ! -d /run/private/testservice
153test -d /var/lib/private/testservice
154test ! -d /var/cache/private/testservice
155test ! -d /var/log/private/testservice
156test ! -L /run/testservice
157test -L /var/lib/testservice
158test ! -L /var/cache/testservice
159test ! -L /var/log/testservice
160
161systemctl clean testservice --what=all
162
163test ! -d /etc/testservice
164test ! -d /run/private/testservice
165test ! -d /var/lib/private/testservice
166test ! -d /var/cache/private/testservice
167test ! -d /var/log/private/testservice
168test ! -L /run/testservice
169test ! -L /var/lib/testservice
170test ! -L /var/cache/testservice
171test ! -L /var/log/testservice
172
173cat >/etc/systemd/system/tmp-hoge.mount <<EOF
174[Mount]
175What=tmpfs
176Type=tmpfs
177ConfigurationDirectory=hoge
178RuntimeDirectory=hoge
179StateDirectory=hoge
180CacheDirectory=hoge
181LogsDirectory=hoge
182EOF
183
184systemctl daemon-reload
185
186test ! -e /etc/hoge
187test ! -e /run/hoge
188test ! -e /var/lib/hoge
189test ! -e /var/cache/hoge
190test ! -e /var/log/hoge
191
192systemctl start tmp-hoge.mount
193
194test -d /etc/hoge
195test -d /run/hoge
196test -d /var/lib/hoge
197test -d /var/cache/hoge
198test -d /var/log/hoge
199
200systemctl clean tmp-hoge.mount && { echo 'unexpected success'; exit 1; }
201
202test -d /etc/hoge
203test -d /run/hoge
204test -d /var/lib/hoge
205test -d /var/cache/hoge
206test -d /var/log/hoge
207
208systemctl stop tmp-hoge.mount
209
210test -d /etc/hoge
211test ! -d /run/hoge
212test -d /var/lib/hoge
213test -d /var/cache/hoge
214test -d /var/log/hoge
215
216systemctl clean tmp-hoge.mount --what=configuration
217
218test ! -d /etc/hoge
219test ! -d /run/hoge
220test -d /var/lib/hoge
221test -d /var/cache/hoge
222test -d /var/log/hoge
223
224systemctl clean tmp-hoge.mount
225
226test ! -d /etc/hoge
227test ! -d /run/hoge
228test -d /var/lib/hoge
229test ! -d /var/cache/hoge
230test -d /var/log/hoge
231
232systemctl clean tmp-hoge.mount --what=logs
233
234test ! -d /etc/hoge
235test ! -d /run/hoge
236test -d /var/lib/hoge
237test ! -d /var/cache/hoge
238test ! -d /var/log/hoge
239
240systemctl clean tmp-hoge.mount --what=all
241
242test ! -d /etc/hoge
243test ! -d /run/hoge
244test ! -d /var/lib/hoge
245test ! -d /var/cache/hoge
246test ! -d /var/log/hoge
247
248cat >/etc/systemd/system/testservice.socket <<EOF
249[Socket]
250ListenSequentialPacket=/run/testservice.socket
251RemoveOnStop=yes
252ExecStartPre=true
253ConfigurationDirectory=testsocket
254RuntimeDirectory=testsocket
255StateDirectory=testsocket
256CacheDirectory=testsocket
257LogsDirectory=testsocket
258EOF
259
260systemctl daemon-reload
261
262test ! -e /etc/testsocket
263test ! -e /run/testsocket
264test ! -e /var/lib/testsocket
265test ! -e /var/cache/testsocket
266test ! -e /var/log/testsocket
267
268systemctl start testservice.socket
269
270test -d /etc/testsocket
271test -d /run/testsocket
272test -d /var/lib/testsocket
273test -d /var/cache/testsocket
274test -d /var/log/testsocket
275
276systemctl clean testservice.socket && { echo 'unexpected success'; exit 1; }
277
278systemctl stop testservice.socket
279
280test -d /etc/testsocket
281test ! -d /run/testsocket
282test -d /var/lib/testsocket
283test -d /var/cache/testsocket
284test -d /var/log/testsocket
285
286systemctl clean testservice.socket --what=configuration
287
288test ! -e /etc/testsocket
289test ! -d /run/testsocket
290test -d /var/lib/testsocket
291test -d /var/cache/testsocket
292test -d /var/log/testsocket
293
294systemctl clean testservice.socket
295
296test ! -e /etc/testsocket
297test ! -e /run/testsocket
298test -d /var/lib/testsocket
299test ! -e /var/cache/testsocket
300test -d /var/log/testsocket
301
302systemctl clean testservice.socket --what=logs
303
304test ! -e /etc/testsocket
305test ! -e /run/testsocket
306test -d /var/lib/testsocket
307test ! -e /var/cache/testsocket
308test ! -e /var/log/testsocket
309
310systemctl clean testservice.socket --what=all
311
312test ! -e /etc/testsocket
313test ! -e /run/testsocket
314test ! -e /var/lib/testsocket
315test ! -e /var/cache/testsocket
316test ! -e /var/log/testsocket
317
318echo OK >/testok
319
320exit 0
321