Last active
April 21, 2018 17:05
-
-
Save AttilaFueloep/958a746ee623a9e58a9fd2c95bbe370f to your computer and use it in GitHub Desktop.
Make history_event-zfs-list-cacher.s h manually callable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- history_event-zfs-list-cacher.sh.orig 2018-04-19 22:44:25.000000000 +0200 | |
+++ history_event-zfs-list-cacher.sh 2018-04-21 13:49:50.033360793 +0200 | |
@@ -10,11 +10,20 @@ | |
# If the pool specific cache file is not writeable, abort | |
[ -w "${FSLIST}" ] || exit 0 | |
-[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc" | |
-. "${ZED_ZEDLET_DIR}/zed-functions.sh" | |
- | |
-zed_exit_if_ignoring_this_event | |
-zed_check_cmd "${ZFS}" sort diff grep | |
+if [ ${#} -eq 0 ]; then | |
+ [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc" | |
+ . "${ZED_ZEDLET_DIR}/zed-functions.sh" | |
+ | |
+ zed_exit_if_ignoring_this_event | |
+ zed_check_cmd "${ZFS}" sort diff grep | |
+else | |
+ if [ ${#} -ne 1 ]; then | |
+ echo "To many arguments" 1>&2 | |
+ exit 1 | |
+ fi | |
+ ZEVENT_POOL=$1 | |
+ ZFS="$(which zfs)" | |
+fi | |
# If we are acting on a snapshot, we have nothing to do | |
printf '%s' "${ZEVENT_HISTORY_DSNAME}" | grep '@' && exit 0 | |
@@ -52,13 +61,17 @@ | |
;; | |
*) | |
- # Ignore all other events. | |
+ # Ignore all other events unless called manually. | |
+ if [ ${#} -eq 0 ]; then | |
exit 0 | |
+ fi | |
;; | |
esac | |
-zed_lock zfs-list | |
-trap abort_alter EXIT | |
+if [ ${#} -eq 0 ]; then | |
+ zed_lock zfs-list | |
+ trap abort_alter EXIT | |
+fi | |
"${ZFS}" list -H -tfilesystem -oname,mountpoint,canmount -r "${ZEVENT_POOL}" \ | |
>"${FSLIST_TMP}" | |
@@ -66,8 +79,14 @@ | |
# Sort the output so that it is stable | |
sort "${FSLIST_TMP}" -o "${FSLIST_TMP}" | |
-# Don't modify the file if it hasn't changed | |
-diff -q "${FSLIST_TMP}" "${FSLIST}" || mv "${FSLIST_TMP}" "${FSLIST}" | |
-rm -f "${FSLIST_TMP}" | |
-finished | |
+if [ ${#} -eq 0 ]; then | |
+ # Don't modify the file if it hasn't changed | |
+ diff -q "${FSLIST_TMP}" "${FSLIST}" || mv "${FSLIST_TMP}" "${FSLIST}" | |
+ rm -f "${FSLIST_TMP}" | |
+ | |
+ finished | |
+else | |
+ cat "${FSLIST_TMP}" | |
+ rm -f "${FSLIST_TMP}" | |
+fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment