Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/tests/frontend/install.sh
2065 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
12
test_setup()
13
{
14
# Do a local config to avoid permissions-on-system-db errors.
15
cat > ${TMPDIR}/pkg.conf << EOF
16
PKG_CACHEDIR=${TMPDIR}/cache
17
PKG_DBDIR=${TMPDIR}
18
REPOS_DIR=[
19
${TMPDIR}/reposconf
20
]
21
repositories: {
22
local: { url : file://${TMPDIR} }
23
}
24
EOF
25
mkdir -p ${TMPDIR}/reposconf
26
cat << EOF > ${TMPDIR}/reposconf/repo.conf
27
local: {
28
url: file:///$TMPDIR,
29
enabled: true
30
}
31
EOF
32
}
33
34
metalog_body()
35
{
36
atf_skip_on Linux Test fails on Linux
37
38
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1 / || atf_fail "Failed to create the ucl file"
39
touch ${TMPDIR}/testfile1 || atf_fail "Failed to create the temp file"
40
echo "@(root,wheel,640,) testfile1" > test.plist
41
echo "test123" > ${TMPDIR}/testfile2 || atf_fail "Failed to create the temp file"
42
echo "@(daemon,nobody,644,) testfile2" >> test.plist
43
ln -s ${TMPDIR}/testfile1 ${TMPDIR}/testlink1
44
echo "@ testlink1" >> test.plist
45
ln ${TMPDIR}/testfile2 ${TMPDIR}/testhlink2
46
echo "@ testhlink2" >> test.plist
47
mkdir ${TMPDIR}/testdir1 || atf_fail "Failed to create the temp dir"
48
echo "@dir testdir1" >> test.plist
49
mkdir ${TMPDIR}/testdir2 || atf_fail "Failed to create the temp dir"
50
chmod 750 ${TMPDIR}/testdir2 || atf_fail "Failed to chmod the temp dir"
51
echo "@dir(daemon) testdir2" >> test.plist
52
53
atf_check \
54
-o ignore \
55
-e empty \
56
-s exit:0 \
57
pkg create -r ${TMPDIR} -M test.ucl -p test.plist
58
59
atf_check \
60
-o ignore \
61
-e empty \
62
-s exit:0 \
63
pkg repo .
64
65
mkdir reposconf
66
cat << EOF > reposconf/repo.conf
67
local: {
68
url: file:///${TMPDIR},
69
enabled: true
70
}
71
EOF
72
73
atf_check \
74
-o ignore \
75
-e empty \
76
-s exit:0 \
77
mkdir ${TMPDIR}/root
78
79
atf_check \
80
-o ignore \
81
-s exit:0 \
82
pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o METALOG=${TMPDIR}/METALOG -r ${TMPDIR}/root install -y test
83
84
atf_check \
85
-o match:"./testfile1 type=file uname=root gname=wheel mode=640" \
86
-o match:"./testfile2 type=file uname=daemon gname=nobody mode=644" \
87
-o match:"./testlink1 type=link uname=root gname=wheel mode=755 link=${TMPDIR}/testfile1" \
88
-o match:"./testhlink2 type=file uname=root gname=wheel mode=644" \
89
-o match:"./testdir1 type=dir uname=root gname=wheel mode=755" \
90
-o match:"./testdir2 type=dir uname=daemon gname=wheel mode=750" \
91
-e empty \
92
-s exit:0 \
93
cat ${TMPDIR}/METALOG
94
}
95
96
reinstall_body()
97
{
98
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1 /usr/local
99
100
atf_check \
101
-o ignore \
102
-e empty \
103
-s exit:0 \
104
pkg register -M test.ucl
105
106
atf_check \
107
-o ignore \
108
-e empty \
109
-s exit:0 \
110
pkg create -M test.ucl
111
112
atf_check \
113
-o ignore \
114
-e empty \
115
-s exit:0 \
116
pkg repo .
117
118
mkdir reposconf
119
cat << EOF > reposconf/repo.conf
120
local: {
121
url: file:///$TMPDIR,
122
enabled: true
123
}
124
EOF
125
126
atf_check \
127
-o ignore \
128
-s exit:0 \
129
pkg -o REPOS_DIR="${TMPDIR}/reposconf" install -y test
130
}
131
132
pre_script_fail_body()
133
{
134
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
135
cat << EOF >> test.ucl
136
scripts: {
137
pre-install: "exit 1"
138
}
139
EOF
140
141
atf_check \
142
-o ignore \
143
-e empty \
144
-s exit:0 \
145
pkg create -M test.ucl
146
147
atf_check -o ignore \
148
-e inline:"${PROGNAME}: PRE-INSTALL script failed\n" \
149
-s exit:3 \
150
pkg -o REPOS_DIR="/dev/null" install -y ${TMPDIR}/test-1.pkg
151
}
152
153
post_script_ignored_body()
154
{
155
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
156
cat << EOF >> test.ucl
157
scripts: {
158
post-install: "exit 1"
159
}
160
EOF
161
162
atf_check \
163
-o ignore \
164
-e empty \
165
-s exit:0 \
166
pkg create -M test.ucl
167
168
atf_check -o ignore \
169
-e inline:"${PROGNAME}: POST-INSTALL script failed\n" \
170
-s exit:0 \
171
pkg -o REPOS_DIR="/dev/null" install -y ${TMPDIR}/test-1.pkg
172
}
173
174
install_missing_dep_body()
175
{
176
test_setup
177
178
# Create one package so we at least have a repo.
179
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg ${TMPDIR}/test test 1 /usr/local
180
cat << EOF >> ${TMPDIR}/test.ucl
181
deps: {
182
b: {
183
origin: "wedontcare",
184
version: "1"
185
}
186
}
187
EOF
188
atf_check \
189
-o ignore \
190
-e empty \
191
-s exit:0 \
192
pkg -C "${TMPDIR}/pkg.conf" create -o ${TMPDIR} -M ${TMPDIR}/test.ucl
193
194
atf_check \
195
-o ignore \
196
-e empty \
197
-s exit:0 \
198
pkg -C "${TMPDIR}/pkg.conf" repo ${TMPDIR}
199
200
mkdir -p ${TMPDIR}/reposconf
201
cat << EOF > ${TMPDIR}/reposconf/repo.conf
202
local: {
203
url: file:///$TMPDIR,
204
enabled: true
205
}
206
EOF
207
208
atf_check \
209
-o ignore \
210
-e not-empty \
211
-s not-exit:0 \
212
pkg -C "${TMPDIR}/pkg.conf" install -y test
213
}
214
215