Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/tests/frontend/extract.sh
2065 views
1
#!/usr/bin/env atf-sh
2
3
. $(atf_get_srcdir)/test_environment.sh
4
CLEANUP=chflags_schg
5
tests_init \
6
basic \
7
basic_dirs \
8
setuid \
9
setuid_hardlinks \
10
chflags \
11
chflags_schg \
12
symlinks
13
14
basic_body()
15
{
16
echo "test" > a
17
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
18
cat << EOF >> test.ucl
19
files = {
20
${TMPDIR}/a: ""
21
}
22
EOF
23
24
atf_check \
25
-o empty \
26
-e empty \
27
-s exit:0 \
28
pkg create -M test.ucl
29
30
mkdir ${TMPDIR}/target
31
atf_check \
32
-o empty \
33
-e empty \
34
-s exit:0 \
35
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qy \
36
${TMPDIR}/test-1.pkg
37
38
OUTPUT="${TMPDIR}/target/local.sqlite
39
${TMPDIR}/target${TMPDIR}/a
40
"
41
atf_check \
42
-o inline:"${OUTPUT}" \
43
-e empty \
44
-s exit:0 \
45
find ${TMPDIR}/target -type f -print | sort
46
47
echo "test2" > a
48
atf_check \
49
-o empty \
50
-e empty \
51
-s exit:0 \
52
pkg create -M test.ucl
53
54
# check no leftovers during upgrades/reinstallation
55
atf_check \
56
-o empty \
57
-e empty \
58
-s exit:0 \
59
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy \
60
${TMPDIR}/test-1.pkg
61
62
atf_check \
63
-o inline:"${OUTPUT}" \
64
-e empty \
65
-s exit:0 \
66
find ${TMPDIR}/target -type f -print | sort
67
68
}
69
70
basic_dirs_body()
71
{
72
mkdir ${TMPDIR}/plop
73
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
74
cat << EOF >> test.ucl
75
directories = {
76
${TMPDIR}/plop: y
77
}
78
EOF
79
80
atf_check \
81
-o empty \
82
-e empty \
83
-s exit:0 \
84
pkg create -M test.ucl
85
86
mkdir ${TMPDIR}/target
87
atf_check \
88
-o empty \
89
-e empty \
90
-s exit:0 \
91
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy \
92
${TMPDIR}/test-1.pkg
93
94
test -d ${TMPDIR}/target${TMPDIR}/plop || atf_fail "directory not extracted"
95
}
96
97
setuid_body()
98
{
99
touch ${TMPDIR}/a
100
chmod 04554 ${TMPDIR}/a || atf_fail "Fail to chmod"
101
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
102
cat << EOF >> test.ucl
103
files = {
104
${TMPDIR}/a = ""
105
}
106
EOF
107
atf_check \
108
-o empty \
109
-e empty \
110
-s exit:0 \
111
pkg create -M test.ucl
112
113
atf_check \
114
-o match:"^-r-sr-xr-- " \
115
-e ignore \
116
bsdtar tvf ${TMPDIR}/test-1.pkg
117
118
mkdir ${TMPDIR}/target
119
atf_check \
120
-o empty \
121
-e empty \
122
-s exit:0 \
123
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy \
124
${TMPDIR}/test-1.pkg
125
126
atf_check \
127
-o match:"^-r-sr-xr-- " \
128
-e empty \
129
-s exit:0 \
130
ls -l ${TMPDIR}/target${TMPDIR}/a
131
}
132
133
setuid_hardlinks_body()
134
{
135
touch ${TMPDIR}/a
136
ln ${TMPDIR}/a ${TMPDIR}/b
137
chmod 04554 ${TMPDIR}/a || atf_fail "Fail to chmod"
138
chmod 04554 ${TMPDIR}/b || atf_fail "Fail to chmod"
139
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
140
cat << EOF >> test.ucl
141
files = {
142
${TMPDIR}/a = ""
143
${TMPDIR}/b = ""
144
}
145
EOF
146
atf_check \
147
-o empty \
148
-e empty \
149
-s exit:0 \
150
pkg create -M test.ucl
151
152
atf_check \
153
-o match:"^-r-sr-xr--.*a$" \
154
-o match:"^hr-sr-xr--.*a$" \
155
-e ignore \
156
bsdtar tvf ${TMPDIR}/test-1.pkg
157
158
mkdir ${TMPDIR}/target
159
atf_check \
160
-o empty \
161
-e empty \
162
-s exit:0 \
163
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy \
164
${TMPDIR}/test-1.pkg
165
166
atf_check \
167
-o match:"^-r-sr-xr-- " \
168
-e empty \
169
-s exit:0 \
170
ls -l ${TMPDIR}/target${TMPDIR}/a
171
172
atf_check \
173
-o match:"^-r-sr-xr-- " \
174
-e empty \
175
-s exit:0 \
176
ls -l ${TMPDIR}/target${TMPDIR}/b
177
}
178
179
chflags_body()
180
{
181
test $(id -u) = 0 || atf_skip "Can only be run as root"
182
183
unset INSTALL_AS_USER
184
test -x /bin/chflags || atf_skip "Requires chflags"
185
# use nodump as it is the only one supported as user, by zfs and by
186
# libarchive
187
touch ${TMPDIR}/a
188
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
189
echo "@(,,,nodump) ${TMPDIR}/a" > test.plist
190
atf_check \
191
-o empty \
192
-e empty \
193
-s exit:0 \
194
pkg create -M test.ucl -p test.plist
195
196
mkdir ${TMPDIR}/target
197
atf_check \
198
-o empty \
199
-e empty \
200
-s exit:0 \
201
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy \
202
${TMPDIR}/test-1.pkg
203
204
atf_check \
205
-o match:"nodump" \
206
-e empty \
207
-s exit:0 \
208
ls -ol ${TMPDIR}/target${TMPDIR}/a
209
210
}
211
212
chflags_schg_body()
213
{
214
test -x /bin/chflags || atf_skip "Requires chflags"
215
test $(id -u) = 0 || atf_skip "Can only be run as root"
216
217
unset INSTALL_AS_USER
218
touch ${TMPDIR}/a
219
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
220
echo "@(root,wheel,,schg) ${TMPDIR}/a" > test.plist
221
atf_check \
222
-o empty \
223
-e empty \
224
-s exit:0 \
225
pkg create -M test.ucl -p test.plist
226
227
mkdir ${TMPDIR}/target
228
atf_check \
229
-o empty \
230
-e empty \
231
-s exit:0 \
232
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy \
233
${TMPDIR}/test-1.pkg
234
235
atf_check \
236
-o match:"schg" \
237
-e empty \
238
-s exit:0 \
239
ls -ol ${TMPDIR}/target${TMPDIR}/a
240
241
# reinstall to for removal
242
atf_check \
243
-o empty \
244
-e empty \
245
-s exit:0 \
246
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy \
247
${TMPDIR}/test-1.pkg
248
}
249
250
chflags_schg_cleanup()
251
{
252
test -x /bin/chflags || atf_skip "Requires chflags"
253
chflags -R noschg ${TMPDIR}
254
}
255
256
symlinks_body()
257
{
258
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
259
cat << EOF >> test.ucl
260
files: {
261
${TMPDIR}/a = "";
262
}
263
EOF
264
265
ln -sf nothing a
266
atf_check \
267
-o empty \
268
-e empty \
269
-s exit:0 \
270
pkg create -M test.ucl
271
272
mkdir ${TMPDIR}/target
273
274
atf_check \
275
-o empty \
276
-e empty \
277
-s exit:0 \
278
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy \
279
${TMPDIR}/test-1.pkg
280
}
281
282