summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2017-01-28 01:28:49 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2017-01-28 01:31:49 -0500
commit8b6b170f763a27ff7fa5bff3fb66d09eb3b7a102 (patch)
tree6eebd66653914709173ee76234fcd883c42dc903
parentc05d5042ce2fcb5174e808e6439b624edcc28fb4 (diff)
Initial commit of holo-files integration.
-rwxr-xr-x50pristine-etc-keeper.post-install7
-rw-r--r--Makefile11
-rwxr-xr-xdrain65
-rw-r--r--zz-pristine-etc-keeper-post-install.hook14
4 files changed, 64 insertions, 33 deletions
diff --git a/50pristine-etc-keeper.post-install b/50pristine-etc-keeper.post-install
deleted file mode 100755
index 757beba..0000000
--- a/50pristine-etc-keeper.post-install
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2016 Luke Shumaker
-# This work is free. You can redistribute it and/or modify it under the
-# terms of the Do What The Fuck You Want To Public License, Version 2,
-# as published by Sam Hocevar. See the COPYING file for more details.
-
-/etc/etckeeper/pristine/fill 'etckeeper post-install'
diff --git a/Makefile b/Makefile
index ef6a552..fbde21c 100644
--- a/Makefile
+++ b/Makefile
@@ -10,14 +10,11 @@ include $(topsrcdir)/build-aux/Makefile.head.mk
# The core of pristine-etc-keeper
std.sys_files += /etc/etckeeper/pristine/drain
std.sys_files += /etc/etckeeper/pristine/fill
-std.sys_files += /etc/etckeeper/post-install.d/50pristine-etc-keeper
-std.sys_files += /var/lib/pristine-etc/etc.lock
+std.sys_files += /var/lib/pristine-etc/chroot.lock
std.sys_files += /var/lib/pristine-etc/spool.lock
$(DESTDIR)/etc/etckeeper/pristine/%: $(srcdir)/%
install -Dm755 $< $@
-$(DESTDIR)/etc/etckeeper/post-install.d/%: $(srcdir)/%.post-install
- install -Dm755 $< $@
$(DESTDIR)/var/lib/pristine-etc/%.lock:
mkdir -p $(@D)
touch $@
@@ -29,6 +26,12 @@ $(DESTDIR)/usr/bin/pristine-etc-keeper: $(DESTDIR)/etc/etckeeper/pristine/fill
mkdir -p $(@D)
ln -srfT $< $@
+# pacman integration
+std.sys_files += /usr/share/libalpm/hooks/zz-pristine-etc-keeper-post-install.hook
+
+$(DESTDIR)/usr/share/libalpm/hooks/%.hook: %.hook
+ install -Dm644 $< $@
+
# systemd integration
std.sys_files += /usr/lib/systemd/system/pristine-etc-keeper.service
diff --git a/drain b/drain
index c739b12..c557823 100755
--- a/drain
+++ b/drain
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
-# Copyright 2016 Luke Shumaker
+# Copyright 2016-2017 Luke Shumaker
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See the COPYING file for more details.
@@ -8,48 +8,69 @@
declare -r workdir=/var/lib/pristine-etc
-pacman-etc-name-ver() {
- LC_ALL=C pacman -Qo /etc | sed 's|^/etc/ is owned by ||'
+watchdirs=(
+ /etc
+ /usr/share/holo/files
+)
+readonly dirs
+
+pacman-watched-name-ver-dirs() {
+ local dir dirs
+ dirs=()
+ for dir in "${watchdirs[@]}"; do
+ if [[ -d "$dir" ]]; then
+ dirs+=("$dir")
+ fi
+ done
+ LC_ALL=C pacman -Qo "${dirs[@]}" | sed -r 's| is owned by | |' |
+ awk '{i=$2" "$3; a[i]=a[i]" "$1} END{for(i in a){print i " " a[i]}}'
}
pacman-all-name-arch() {
LC_ALL=C pacman -Qni | tr $'\n' $'\r' | sed 's/\r\r/\n/g' | sed -r 's|(.*\r)?Name\s*:\s*(\S+)(\r.*)?\rArchitecture\s*:\s*(\S+)\r.*|\2 \4|'
}
+pacman-watched-name-arch-ver-dirs() {
+ join <(pacman-all-name-arch|sort) <(pacman-watched-name-ver-dirs|sort)
+}
+
commit() (
- local msg="$1"
+ msg="$1"
cd "$workdir"
if ! [[ -d etc.git ]]; then
- mkdir -p etc
- (cd etc && etckeeper init -d "$PWD")
- mv etc/.git etc.git
+ mkdir -p chroot/etc
+ (cd chroot/etc && etckeeper init -d "$PWD")
+ mv chroot/etc/.git etc.git
ln -sr etc.git etc/.git
fi
-
- rm -rf etc/
-
- local err=false
- local files=()
- while IFS=' ' read -r pkgname pkgver arch; do
- local file=("/var/cache/pacman/pkg/$pkgname-$pkgver-$arch".pkg.tar.*)
+ rm -rf chroot
+ mkdir chroot
+ cd chroot
+
+ err=false
+ files=()
+ while IFS=' ' read -r pkgname arch pkgver dirs; do
+ file=("/var/cache/pacman/pkg/$pkgname-$pkgver-$arch".pkg.tar.*)
if ! test -f "$file"; then
printf "ERROR: no cached package for %s %s %s\n" "$pkgname" "$pkgver" "$arch"
err=true
fi
- files+=("$file")
- done < <(join <(pacman-etc-name-ver|sort) <(pacman-all-name-arch|sort))
+ files+=("$file $dirs")
+ done < <(pacman-watched-name-arch-ver-dirs
if $err; then
return 1
fi
- local file
- for file in "${files[@]}"; do
+ for filespec in "${files[@]}"; do
+ read file dirs_str <<<"$filespec"
+ read -a dirs <<<"$dirs_str"
printf " -> %s\n" "$file"
- bsdtar xpvf "$file" etc
+ bsdtar xpvf "$file" "${dirs[@]#/}"
done
- ln -sr etc.git etc/.git
+ ln -sr ../etc.git etc/.git
+ HOLO_ROOT_DIR=. holo apply
cd etc/
etckeeper update-ignore -d "$PWD"
if etckeeper unclean -d "$PWD"; then
@@ -59,7 +80,7 @@ commit() (
pull() (
cd /etc
- git remote add pristine "${workdir}/etc" &>/dev/null || true
+ git remote add pristine "${workdir}/chroot/etc" &>/dev/null || true
git fetch pristine
)
@@ -79,7 +100,7 @@ main() {
set -e -o pipefail
umask 0022
- if ! lock 7 "${workdir}/etc.lock" -n; then
+ if ! lock 7 "${workdir}/chroot.lock" -n; then
return 0
fi
while true; do
diff --git a/zz-pristine-etc-keeper-post-install.hook b/zz-pristine-etc-keeper-post-install.hook
new file mode 100644
index 0000000..24b4190
--- /dev/null
+++ b/zz-pristine-etc-keeper-post-install.hook
@@ -0,0 +1,14 @@
+# pristine-etc-keeper post-install hook for Pacman 5 and newer
+
+[Trigger]
+Operation = Install
+Operation = Upgrade
+Operation = Remove
+Type = File
+Target = etc/* usr/share/holo/files/*
+
+[Action]
+Description = pristine-etc-keeper: post-transaction commit
+When = PostTransaction
+Exec = /etc/etckeeper/pristine/fill 'pacman post-install'
+Depends = holo-files pristine-etc-keeper