Debian Codegraph @

debian/tests/mirrorbits-basic-redis

raw
1 #!/bin/bash
2
3 set -eu
4
5 cleanup() {
6 if systemctl is-active --quiet mirrorbits; then
7 systemctl stop mirrorbits
8 fi
9
10 journalctl -u mirrorbits | tail -n 100
11
12 if [ -e /var/log/mirrorbits/daemon.log ]; then
13 tail -n 100 /var/log/mirrorbits/daemon.log
14 fi
15
16 rm -fr /var/log/mirrorbits
17 rm -f /etc/mirrorbits/mirrorbits.conf
18
19 if [ "$DATADIR" ]; then
20 rm -fr "$DATADIR"
21 fi
22 }
23
24 trap cleanup EXIT
25
26 # Check and remember if a database is installed (we'll make
27 # use of that later).
28 DB=""
29 pkg_installed() {
30 dpkg -s "$1" 2>/dev/null | grep -q "ok installed"
31 }
32 for db in redis valkey; do
33 pkg_installed $db-server || continue
34 DB=$db-server && break
35 done
36
37 # Prepare directories --- Note that we run mirrorbits via a
38 # systemd service, with various hardening settings enabled.
39 # Thus the mirrorbits daemon has limited access to the root
40 # filesystem, in particular /tmp is not available. For this
41 # reason we don't use AUTOPKGTEST_TMP.
42 DATADIR=$(mktemp -d /srv/mirrorbits-XXXXXX)
43 chmod 0755 $DATADIR
44 mkdir $DATADIR/repo
45
46 # Prepare mirrorbits config --- Either we have access to the
47 # GeoIP databases, either we define fallbacks in the config.
48 # We go for the later for simplicity.
49 cat <<EOF >/etc/mirrorbits/mirrorbits.conf
50 Repository: $DATADIR/repo
51 Fallbacks:
52 - URL: http://foobar.example.org
53 EOF
54
55 # Disabled --- Use GeoIP test databases.
56 if false; then
57 gitrepo=https://github.com/maxmind/MaxMind-DB
58 path=raw/main/test-data
59 for db in ASN City; do
60 wget $gitrepo/$path/GeoLite2-$db-Test.mmdb \
61 -O $DATADIR/GeoLite2-$db.mmdb
62 done
63 echo "GeoipDatabasePath: $DATADIR" >> \
64 /etc/mirrorbits/mirrorbits.conf
65 fi
66
67 # Start the mirrorbits daemon
68 systemctl start mirrorbits
69
70 # We should be able to print the version
71 mirrorbits version
72
73 # Bail out if there's no database installed
74 if [ -z "$DB" ]; then
75 echo "No database installed, end of the tests"
76 exit 0
77 else
78 echo "$DB is installed, keep testing"
79 fi
80
81 # Try a few more commands
82 mirrorbits refresh
83 mirrorbits list