Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/tests/frontend/install.sh
2645 views
1
#! /usr/bin/env atf-sh
2
3
. $(atf_get_srcdir)/test_environment.sh
4
5
tests_init \
6
metalog \
7
reinstall \
8
pre_script_fail \
9
post_script_ignored \
10
install_missing_dep \
11
install_register_only
12
13
test_setup()
14
{
15
# Do a local config to avoid permissions-on-system-db errors.
16
cat > ${TMPDIR}/pkg.conf << EOF
17
PKG_CACHEDIR=${TMPDIR}/cache
18
PKG_DBDIR=${TMPDIR}
19
REPOS_DIR=[
20
${TMPDIR}/reposconf
21
]
22
repositories: {
23
local: { url : file://${TMPDIR} }
24
}
25
EOF
26
mkdir -p ${TMPDIR}/reposconf
27
cat << EOF > ${TMPDIR}/reposconf/repo.conf
28
local: {
29
url: file:///$TMPDIR,
30
enabled: true
31
}
32
EOF
33
}
34
35
metalog_body()
36
{
37
atf_skip_on Linux Test fails on Linux
38
39
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1 /
40
atf_check touch ${TMPDIR}/testfile1
41
echo "@(root,wheel,640,) testfile1" > test.plist
42
echo "test123" > ${TMPDIR}/testfile2
43
echo "@(daemon,nobody,644,) testfile2" >> test.plist
44
atf_check ln -s ${TMPDIR}/testfile1 ${TMPDIR}/testlink1
45
echo "@ testlink1" >> test.plist
46
ln ${TMPDIR}/testfile2 ${TMPDIR}/testhlink2
47
echo "@ testhlink2" >> test.plist
48
atf_check mkdir -p ${TMPDIR}/testdir1/foo/bar/baz
49
atf_check mkdir -p ${TMPDIR}/testdir1/foo/bar/baz2
50
echo "@dir testdir1/foo/bar/baz" >> test.plist
51
echo "@dir testdir1/foo/bar/baz2" >> test.plist
52
atf_check mkdir ${TMPDIR}/testdir2
53
atf_check chmod 750 ${TMPDIR}/testdir2
54
echo "@dir(daemon) testdir2" >> test.plist
55
56
atf_check \
57
-o ignore \
58
pkg create -r ${TMPDIR} -M test.ucl -p test.plist
59
60
atf_check \
61
-o ignore \
62
pkg repo .
63
64
mkdir reposconf
65
cat << EOF > reposconf/repo.conf
66
local: {
67
url: file:///${TMPDIR},
68
enabled: true
69
}
70
EOF
71
72
atf_check \
73
-o ignore \
74
mkdir ${TMPDIR}/root
75
76
atf_check \
77
-o ignore \
78
pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o METALOG=${TMPDIR}/METALOG -r ${TMPDIR}/root install -y test
79
80
atf_check \
81
-o match:"./testfile1 type=file uname=root gname=wheel mode=640" \
82
-o match:"./testfile2 type=file uname=daemon gname=nobody mode=644" \
83
-o match:"./testlink1 type=link uname=root gname=wheel mode=755 link=${TMPDIR}/testfile1" \
84
-o match:"./testhlink2 type=file uname=root gname=wheel mode=644" \
85
-o match:"./testdir1 type=dir uname=root gname=wheel mode=755" \
86
-o match:"./testdir1/foo type=dir uname=root gname=wheel mode=755" \
87
-o match:"./testdir1/foo/bar type=dir uname=root gname=wheel mode=755" \
88
-o match:"./testdir1/foo/bar/baz type=dir uname=root gname=wheel mode=755" \
89
-o match:"./testdir2 type=dir uname=daemon gname=wheel mode=750" \
90
cat ${TMPDIR}/METALOG
91
}
92
93
reinstall_body()
94
{
95
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1 /usr/local
96
97
atf_check \
98
-o ignore \
99
pkg register -M test.ucl
100
101
atf_check \
102
-o ignore \
103
pkg create -M test.ucl
104
105
atf_check \
106
-o ignore \
107
pkg repo .
108
109
mkdir reposconf
110
cat << EOF > reposconf/repo.conf
111
local: {
112
url: file:///$TMPDIR,
113
enabled: true
114
}
115
EOF
116
117
atf_check \
118
-o ignore \
119
pkg -o REPOS_DIR="${TMPDIR}/reposconf" install -y test
120
}
121
122
pre_script_fail_body()
123
{
124
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
125
cat << EOF >> test.ucl
126
scripts: {
127
pre-install: "exit 1"
128
}
129
EOF
130
131
atf_check \
132
-o ignore \
133
pkg create -M test.ucl
134
135
atf_check -o ignore \
136
-e inline:"${PROGNAME}: PRE-INSTALL script failed\n" \
137
-s exit:3 \
138
pkg -o REPOS_DIR="/dev/null" install -y ${TMPDIR}/test-1.pkg
139
}
140
141
post_script_ignored_body()
142
{
143
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
144
cat << EOF >> test.ucl
145
scripts: {
146
post-install: "exit 1"
147
}
148
EOF
149
150
atf_check \
151
-o ignore \
152
pkg create -M test.ucl
153
154
atf_check -o ignore \
155
-e inline:"${PROGNAME}: POST-INSTALL script failed\n" \
156
pkg -o REPOS_DIR="/dev/null" install -y ${TMPDIR}/test-1.pkg
157
}
158
159
install_missing_dep_body()
160
{
161
test_setup
162
163
# Create one package so we at least have a repo.
164
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg ${TMPDIR}/test test 1 /usr/local
165
cat << EOF >> ${TMPDIR}/test.ucl
166
deps: {
167
b: {
168
origin: "wedontcare",
169
version: "1"
170
}
171
}
172
EOF
173
atf_check \
174
-o ignore \
175
pkg -C "${TMPDIR}/pkg.conf" create -o ${TMPDIR} -M ${TMPDIR}/test.ucl
176
177
atf_check \
178
-o ignore \
179
pkg -C "${TMPDIR}/pkg.conf" repo ${TMPDIR}
180
181
mkdir -p ${TMPDIR}/reposconf
182
cat << EOF > ${TMPDIR}/reposconf/repo.conf
183
local: {
184
url: file:///$TMPDIR,
185
enabled: true
186
}
187
EOF
188
189
atf_check \
190
-o ignore \
191
-e not-empty \
192
-s not-exit:0 \
193
pkg -C "${TMPDIR}/pkg.conf" install -y test
194
}
195
196
install_register_only_body()
197
{
198
test_setup
199
200
touch file1
201
mkdir dir
202
touch dir/file2
203
204
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" "${TMPDIR}"
205
cat << EOF >> test.ucl
206
files: {
207
${TMPDIR}/file1: "",
208
${TMPDIR}/dir/file2: "",
209
}
210
EOF
211
212
mkdir repoconf
213
cat << EOF > repoconf/repo.conf
214
repo: {
215
url: file:///$TMPDIR/repo,
216
enabled: true
217
}
218
EOF
219
220
mkdir repo
221
222
atf_check \
223
-o empty \
224
-e empty \
225
-s exit:0 \
226
pkg create -M test.ucl -o repo
227
228
rm file1
229
rm dir/file2
230
rmdir dir
231
232
ls
233
atf_check \
234
-o ignore \
235
-e empty \
236
-s exit:0 \
237
pkg repo repo
238
239
export REPOS_DIR="${TMPDIR}/repoconf"
240
atf_check \
241
-o ignore \
242
-s exit:0 \
243
pkg install -r repo -y --register-only test
244
245
atf_check \
246
-o inline:"0\n" \
247
-e empty \
248
pkg query "%a" test
249
250
atf_check \
251
-o ignore \
252
-e ignore \
253
-s exit:1 \
254
test -f file1
255
256
atf_check \
257
-o ignore \
258
-e ignore \
259
-s exit:1 \
260
test -d dir
261
}
262
263