blob: e1dab98d9a988dd7c1d31e834c7cfa14093b7580 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
#/bin/bash
#
# The test assumes you are running Slackware on a 64 bit system.
#
# Packages are copied here on successful download.
export PACKAGE_DIR="${PACKAGE_DIR:-/var/spool/slack-autoupdate}"
# Packages are temperarily stored here until success.
export STAGING_DIR="${STAGING_DIR:-/var/cache/slack-autoupdate/staging}"
# Use fake chmod and chown commands to avoid errors when making packages.
BIN_DIR="$(realpath $(dirname "${BASH_SOURCE[0]}"))/bin"
TEST_DIR="$(
mktemp \
--directory \
--tmpdir="$TMP" \
slack-autoupdate.XXXXXX
)" || exit 1
trap "rm -fr $TEST_DIR" EXIT
mkdir -p \
"$TEST_DIR/tmp" \
"$TEST_DIR/etc/sbotools" \
"$TEST_DIR/etc/slackpkg" \
"$TEST_DIR/root" \
"$TEST_DIR/tmp" \
"$TEST_DIR/usr/sbo" \
"$TEST_DIR/var/cache" \
"$TEST_DIR/var/lib" \
"$TEST_DIR/var/lock" \
"$TEST_DIR/var/log" \
"$TEST_DIR/var/spool"
if ! command -v bwrap &> /dev/null
then
echo "bwrap could not be found. The 'bubblewrap' application must be installed to run this test."
exit 1
fi
# Slackpkg etc. require a fake root user and filesystem.
export INSTANCE="\
bwrap \
--unshare-user --uid 0 --gid 0 \
--setenv "HOME" "/root" \
--ro-bind / / \
--dev /dev \
--bind "$TEST_DIR/tmp" "/tmp" \
--bind "$TEST_DIR/etc/sbotools" /etc/sbotools \
--bind "$TEST_DIR/etc/slackpkg" /etc/slackpkg \
--bind "$TEST_DIR/root" /root \
--bind "$BIN_DIR" /usr/local/bin \
--bind "$TEST_DIR/usr/sbo" /usr/sbo \
--bind "$TEST_DIR/var" /var \
--"
$INSTANCE ln -s ../lib/pkgtools/packages "/var/log/packages"
$INSTANCE mkdir --parents "/var/lib/pkgtools/packages"
echo "Preparing slackpkg test case"
(
mkdir --parents "$TEST_DIR/etc"
cp --recursive /etc/slackpkg "$TEST_DIR/etc/"
echo http://mirrors.slackware.com/slackware/slackware64-15.0/ > "$TEST_DIR/etc/slackpkg/mirrors"
echo "WGETFLAGS=\"-4 --quiet\"" >> "$TEST_DIR/etc/slackpkg/slackpkg.conf" # REMOVE ME
yes | $INSTANCE slackpkg update gpg
$INSTANCE slackpkg -batch=on -default_answer=y update
touch "$TEST_DIR/var/lib/pkgtools/packages/xpdf-4.00-x86_64-3"
touch "$TEST_DIR/var/lib/pkgtools/packages/xz-5.0.0-x86_64-4_slack15.0"
)
echo "Preparing sbotools test case"
(
$INSTANCE sboconfig --pkg-dir "$STAGING_DIR" >/dev/null
touch "$TEST_DIR/var/lib/pkgtools/packages/bubblewrap-0.7.0-x86_64-1_SBo"
$INSTANCE sbosnap fetch
)
echo ""
echo "Running slack-autoupdate..."
echo ""
# Display a helpful message and successful exit code by tracking total success.
TESTS_PASS=true
if ! $INSTANCE bash $(dirname "${BASH_SOURCE[0]}")/../slack-autoupdate; then
TESTS_PASS=false
echo "slack-autoupdate failed"
cat "$TEST_DIR/$PACKAGE_DIR/error.txt"
elif [ -f "$TEST_DIR/$PACKAGE_DIR/error.txt" ]; then
TESTS_PASS=false
cat "$TEST_DIR/$PACKAGE_DIR/error.txt"
fi
if [ ! -f "$TEST_DIR/$PACKAGE_DIR/info.txt" ]; then
TESTS_PASS=false
echo "expected '$PACKAGE_DIR/info.txt' file to be created"
fi
if [ -z "$(find "$TEST_DIR/$PACKAGE_DIR" -name 'xpdf-*.t*z')" ] \
|| [ -z "$(find "$TEST_DIR/$PACKAGE_DIR" -name 'xz-*.t*z')" ]; then
TESTS_PASS=false
echo "slackpkg: expected to have xpdf and xz package update"
else
echo "slackpkg: ok"
fi
if [ -f "$TEST_DIR/etc/sbotools/sbotools.conf" ] \
&& [ -z "$(find "$TEST_DIR/$PACKAGE_DIR" -name 'bubblewrap-*.t*z')" ]; then
TESTS_PASS=false
echo "sbotools: expected to have bubblewrap package update"
else
echo "sbotools: ok"
fi
if [ "$TESTS_PASS" = true ]; then
echo "all tests pass"
else
exit 1
fi
|