xref: /illumos-gate/usr/src/test/util-tests/tests/svr4pkg/svr4pkg_test.ksh (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
1#!/usr/bin/ksh
2#
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright 2021 Toomas Soome <tsoome@me.com>
16#
17
18: "${FILEDIR:=/opt/util-tests/tests/files}"
19
20[[ -d "$FILEDIR" ]] || fail "no files directory $FILEDIR"
21
22typeset -i fail=0
23
24function fail {
25	echo "FAIL $@"
26	((fail++))
27}
28
29function pass {
30	echo "PASS $@"
31}
32
33function pkg_test {
34	TD=$(mktemp -d -t)
35
36	if [[ ! -d "$TD" ]]; then
37		fail "couldn't create test directory $TD"
38		return
39	fi
40
41	echo "PKG=svr4pkg" > $TD/pkginfo
42	echo "NAME=\"svr4pkg test package\"" >> $TD/pkginfo
43	echo "ARCH=sparc,i386" >> $TD/pkginfo
44	echo "VERSION=1.0" >> $TD/pkginfo
45	echo "CATEGORY=application" >> $TD/pkginfo
46	echo "BASEDIR=/opt" >> $TD/pkginfo
47
48	(cd $FILEDIR; /usr/bin/pkgproto svr4pkg) > $TD/prototype || \
49	fail "pkgproto svr4pkg"
50	echo "i pkginfo=$TD/pkginfo" >> $TD/prototype
51	/usr/bin/pkgmk -f $TD/prototype -r $FILEDIR -d $TD || \
52	fail "pkgmk svr4pkg"
53	/usr/bin/pkgtrans -s $TD $TD/svr4pkg.pkg svr4pkg || \
54	fail "pkgtrans to stream format"
55
56	mkdir -p $TD/root/opt
57	/usr/sbin/pkgadd -d $TD -R $TD/root svr4pkg || fail "pkgadd svr4pkg"
58	/usr/bin/pkginfo -R $TD/root svr4pkg || fail "pkginfo svr4pkg"
59	/usr/sbin/pkgrm -n -R $TD/root svr4pkg || fail "pkgrm svr4pkg"
60
61	rm -rf "$TD"
62}
63
64pkg_test
65
66(( fail > 0 )) && exit -1
67exit 0
68