[pacman-dev] [PATCH 4/4] add example hooks

Andrew Gregory andrew.gregory.8 at gmail.com
Sat Jul 4 10:11:04 UTC 2015


Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
 hooks/checkboot.hook  | 17 +++++++++++++++++
 hooks/checkmount      | 13 +++++++++++++
 hooks/checkmount.conf |  1 +
 hooks/checkmount.hook | 17 +++++++++++++++++
 hooks/sync.hook       | 16 ++++++++++++++++
 5 files changed, 64 insertions(+)
 create mode 100644 hooks/checkboot.hook
 create mode 100644 hooks/checkmount
 create mode 100644 hooks/checkmount.conf
 create mode 100644 hooks/checkmount.hook
 create mode 100644 hooks/sync.hook

diff --git a/hooks/checkboot.hook b/hooks/checkboot.hook
new file mode 100644
index 0000000..d1736de
--- /dev/null
+++ b/hooks/checkboot.hook
@@ -0,0 +1,17 @@
+# Make sure /boot is mounted before we modify it
+
+[Trigger]
+Operation = Sync
+Type = File
+Target = boot/*
+
+[Trigger]
+Operation = Remove
+Type = File
+Target = boot/*
+
+[Action]
+AbortOnFail
+Depends = util-linux
+When = PreTransaction
+Exec = /usr/lib/alpm/hooks/checkmount
diff --git a/hooks/checkmount b/hooks/checkmount
new file mode 100644
index 0000000..00fff7f
--- /dev/null
+++ b/hooks/checkmount
@@ -0,0 +1,13 @@
+#!/usr/bin/bash
+
+[[ -f /etc/checkmount ]] || exit 0
+
+source /etc/checkmount
+ret=0
+for mp in "${mountpoints[@]}"; do
+    if ! findmnt "$mp" &>/dev/null; then
+        printf "error: $mp not mounted\n" >&2
+        ret=1
+    fi
+done
+exit $ret
diff --git a/hooks/checkmount.conf b/hooks/checkmount.conf
new file mode 100644
index 0000000..7ac515b
--- /dev/null
+++ b/hooks/checkmount.conf
@@ -0,0 +1 @@
+mountpoints=( /boot )
diff --git a/hooks/checkmount.hook b/hooks/checkmount.hook
new file mode 100644
index 0000000..21c4127
--- /dev/null
+++ b/hooks/checkmount.hook
@@ -0,0 +1,17 @@
+# Make sure all our filesystems are mounted
+
+[Trigger]
+Operation = Sync
+Type = File
+Target = *
+
+[Trigger]
+Operation = Remove
+Type = File
+Target = *
+
+[Action]
+AbortOnFail
+Depends = util-linux
+When = PreTransaction
+Exec = /usr/lib/alpm/hooks/checkmount
diff --git a/hooks/sync.hook b/hooks/sync.hook
new file mode 100644
index 0000000..43c2869
--- /dev/null
+++ b/hooks/sync.hook
@@ -0,0 +1,16 @@
+# Force disks to sync to prevent data corruption
+
+[Trigger]
+Operation = Sync
+Type = Package
+Target = *
+
+[Trigger]
+Operation = Remove
+Type = Package
+Target = *
+
+[Action]
+Depends = coreutils
+When = PostTransaction
+Exec = /usr/bin/sync
-- 
2.4.5


More information about the pacman-dev mailing list