summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/abslibre-tools/libredbdiff33
-rw-r--r--src/abslibre-tools/libredbdiff.conf7
-rw-r--r--test/libredbdiff-test.sh29
-rw-r--r--test/libredbdiff.d/expected.txt1
-rw-r--r--test/libredbdiff.d/statedir/pacman.archlinux/local/ALPM_DB_VERSION1
-rw-r--r--test/libredbdiff.d/statedir/pacman.archlinux/sync/core.dbbin0 -> 1017 bytes
-rw-r--r--test/libredbdiff.d/statedir/pacman.conf.archlinux6
-rw-r--r--test/libredbdiff.d/statedir/pacman.conf.parabola6
-rw-r--r--test/libredbdiff.d/statedir/pacman.parabola/local/ALPM_DB_VERSION1
-rw-r--r--test/libredbdiff.d/statedir/pacman.parabola/sync/libre.dbbin0 -> 1062 bytes
10 files changed, 63 insertions, 21 deletions
diff --git a/src/abslibre-tools/libredbdiff b/src/abslibre-tools/libredbdiff
index 2617323..50bc78f 100755
--- a/src/abslibre-tools/libredbdiff
+++ b/src/abslibre-tools/libredbdiff
@@ -19,8 +19,12 @@ name="Libredbdiff"
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-baseconfpath="/etc/libredbdiff"
-basedbpath="/var/lib/libredbdiff"
+. "$(librelib messages)"
+. "$(librelib conf)"
+load_files libredbdiff || exit 1
+
+baseconfpath="$statedir"
+basedbpath="$statedir"
conffile="$baseconfpath/pacman.conf.parabola"
conffilearch="$baseconfpath/pacman.conf.archlinux"
@@ -31,17 +35,11 @@ dbpatharch="$basedbpath/pacman.archlinux"
mirrorlist="$baseconfpath/mirrorlist.parabola"
mirrorlistarch="$baseconfpath/mirrorlist.archlinux"
-mirror='http://repo.parabola.nu/$repo/os/$arch'
-mirrorarch='http://mirrors.kernel.org/archlinux/$repo/os/$arch'
-
repos="libre pcr libre-multilib nonprism"
field_pkgname_parabola=30
field_pkgname_arch=30
-
-. "$(librelib messages)"
-
cmd="${0##*/}"
arch_packages_tmp="/tmp/${cmd}.arch-packages"
@@ -276,6 +274,7 @@ main() {
"$name" \
"$cmd"
fi
+ check_vars libredbdiff statedir mirror mirrorarch || exit 1
if ! [[ -e "${conffile}" && \
-e "${conffilearch}" && \
@@ -305,31 +304,23 @@ main() {
createdir "$dbpatharch"
msg "Synchronizing %s pacman databases for Arch" "$name"
- pacman --config "${conffilearch}" -b "${dbpatharch}" -Sy ||
+ pacman --config "${conffilearch}" -Sy ||
die "Failed to synchronize pacman database for Arch. Exiting."
msg "%s pacman databases are updated. %s is ready. Run %q -n to print results." \
"$name" "$name" "$cmd"
return 0
else
- filenotfound "${dbpath}"
- filenotfound "${dbpatharch}"
+ check_vars libredbdiff statedir || exit 1
+
+ filenotfound "${dbpath}/sync/libre.db"
+ filenotfound "${dbpatharch}/sync/core.db"
filenotfound "${conffile}"
filenotfound "${conffilearch}"
- filenotfound "${mirrorlist}"
- filenotfound "${mirrorlistarch}"
unset provides ver verarch
declare -gA provides ver verarch
- if ! [[ -d "$dbpath" && \
- -d "$dbpatharch" ]]; then
- die "At least one %s pacman DB directory is missing. To update %s pacman databases, %s must be run as root. Nothing done." \
- "$name" \
- "$name" \
- "$cmd"
- fi
-
pacman --config "${conffilearch}" -Ss | \
grep -v '^ ' | \
awk -F/ '{print $2}' \
diff --git a/src/abslibre-tools/libredbdiff.conf b/src/abslibre-tools/libredbdiff.conf
new file mode 100644
index 0000000..18bc643
--- /dev/null
+++ b/src/abslibre-tools/libredbdiff.conf
@@ -0,0 +1,7 @@
+#!/hint/bash
+# shellcheck disable=2034
+
+statedir='/var/lib/libredbdiff'
+
+mirror='http://repo.parabola.nu/$repo/os/$arch'
+mirrorarch='http://mirrors.kernel.org/archlinux/$repo/os/$arch'
diff --git a/test/libredbdiff-test.sh b/test/libredbdiff-test.sh
new file mode 100644
index 0000000..1b267e3
--- /dev/null
+++ b/test/libredbdiff-test.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env roundup
+
+describe libredbdiff
+. ./test-common.sh
+
+common_before() {
+ mkdir -p "$XDG_CONFIG_HOME/libretools"
+ printf '%s\n' \
+ 'statedir="$PWD"' \
+ "mirror='http://repo.parabola.nu/\$repo/os/\$arch'" \
+ "mirrorarch='http://mirrors.kernel.org/archlinux/\$repo/os/\$arch'" \
+ > $XDG_CONFIG_HOME/libretools/libredbdiff.conf
+}
+
+it_displays_help() {
+ LC_ALL=C libredbdiff -h >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
+ empty $tmpdir/stderr
+}
+
+it_handles_packages_with_multiple_provides() {
+ cd libredbdiff.d/statedir
+
+ libredbdiff -n libre >$tmpdir/stdout 2>$tmpdir/stderr
+
+ empty $tmpdir/stderr
+ diff -w ../expected.txt $tmpdir/stdout
+}
diff --git a/test/libredbdiff.d/expected.txt b/test/libredbdiff.d/expected.txt
new file mode 100644
index 0000000..8fb89bf
--- /dev/null
+++ b/test/libredbdiff.d/expected.txt
@@ -0,0 +1 @@
+p linux-libre linux 4.10.12_gnu-2 | 4.10.13-1
diff --git a/test/libredbdiff.d/statedir/pacman.archlinux/local/ALPM_DB_VERSION b/test/libredbdiff.d/statedir/pacman.archlinux/local/ALPM_DB_VERSION
new file mode 100644
index 0000000..ec63514
--- /dev/null
+++ b/test/libredbdiff.d/statedir/pacman.archlinux/local/ALPM_DB_VERSION
@@ -0,0 +1 @@
+9
diff --git a/test/libredbdiff.d/statedir/pacman.archlinux/sync/core.db b/test/libredbdiff.d/statedir/pacman.archlinux/sync/core.db
new file mode 100644
index 0000000..b0f737b
--- /dev/null
+++ b/test/libredbdiff.d/statedir/pacman.archlinux/sync/core.db
Binary files differ
diff --git a/test/libredbdiff.d/statedir/pacman.conf.archlinux b/test/libredbdiff.d/statedir/pacman.conf.archlinux
new file mode 100644
index 0000000..d4a9c8d
--- /dev/null
+++ b/test/libredbdiff.d/statedir/pacman.conf.archlinux
@@ -0,0 +1,6 @@
+[options]
+DBPath = ./pacman.archlinux
+Architecture = x86_64
+
+[core]
+Server = https://mirrors.kernel.org/archlinux/$repo/os/$arch
diff --git a/test/libredbdiff.d/statedir/pacman.conf.parabola b/test/libredbdiff.d/statedir/pacman.conf.parabola
new file mode 100644
index 0000000..7b553dd
--- /dev/null
+++ b/test/libredbdiff.d/statedir/pacman.conf.parabola
@@ -0,0 +1,6 @@
+[options]
+DBPath = ./pacman.parabola
+Architecture = x86_64
+
+[libre]
+Server = https://repomirror.parabola.nu/$repo/os/$arch
diff --git a/test/libredbdiff.d/statedir/pacman.parabola/local/ALPM_DB_VERSION b/test/libredbdiff.d/statedir/pacman.parabola/local/ALPM_DB_VERSION
new file mode 100644
index 0000000..ec63514
--- /dev/null
+++ b/test/libredbdiff.d/statedir/pacman.parabola/local/ALPM_DB_VERSION
@@ -0,0 +1 @@
+9
diff --git a/test/libredbdiff.d/statedir/pacman.parabola/sync/libre.db b/test/libredbdiff.d/statedir/pacman.parabola/sync/libre.db
new file mode 100644
index 0000000..1bd5065
--- /dev/null
+++ b/test/libredbdiff.d/statedir/pacman.parabola/sync/libre.db
Binary files differ