/usr/bin/lockfs-notify is in bilibop-lockfs 0.4.20.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | #!/bin/sh
# /usr/bin/lockfs-notify
#
# Notify the user that changes on filesystems are allowed or not. This script
# should be called from /etc/xdg/autostart/bilibop-lockfs.desktop or something
# like, but can be run manually too.
# TODO: translations and gettext support.
PATH="/bin:/usr/bin"
short_usage() {
cat <<EOF
Usage: ${0##*/} --help
EOF
}
usage() {
cat <<EOF
${0##*/}: send a notification on the desktop to show, for each local
mountpoint, if changes will be lost or kept at shutdown.
OPTIONS:
-a, --always Show status of both locked and no-locked filesystems.
-h, --help Print this message on standard output and exit.
-l, --lockfs Show status of locked filesystems only.
-n, --nolockfs Show status of non-locked filesystems only.
EOF
}
# Load functions and get other variables:
. /lib/bilibop/lockfs.sh
get_udev_root
# The behaviour of this script depends on the admin settings:
case "${BILIBOP_LOCKFS_NOTIFY_POLICY}" in
never)
exit 0
;;
lockfs|nolockfs)
;;
*)
# This is the default and the fallback:
BILIBOP_LOCKFS_NOTIFY_POLICY="always"
;;
esac
# Parse options with getopt.
ARGS="$(getopt -o ahlnt: --long always,help,lockfs,nolockfs,expire-time: -n "${0##*/}" -- "${@}")"
if [ "${?}" = "0" ]
then eval set -- "$ARGS"
else short_usage >&2
exit 1
fi
# This admin's defined behaviour can be overriden from the commandline.
# This can be useful for the user (by copying lockfs-notify.desktop from
# /etc/xdg/autostart to ~/.config/autostart, and modifying the 'Exec='
# line, or setting 'Hidden=true')
while true
do
case "${1}" in
-a|always)
BILIBOP_LOCKFS_NOTIFY_POLICY="always"
shift
;;
-h|--help)
usage
exit 0
;;
-l|--lockfs)
BILIBOP_LOCKFS_NOTIFY_POLICY="lockfs"
shift
;;
-n|--nolockfs)
BILIBOP_LOCKFS_NOTIFY_POLICY="nolockfs"
shift
;;
-t|--expire-time)
if echo "${2}" | grep -q '^[0-9]\+$'
then EXPIRE_TIME="${2}"
[ ${2} -lt 1000 ] &&
EXPIRE_TIME="0"
else EXPIRE_TIME="-1"
fi
shift 2
;;
--)
break
;;
*)
unknown_argument "${arg}" >&2
short_usage >&2
exit 1
;;
esac
done
# If this script is not called in a graphical environment, nothing to do:
if [ -z "${DISPLAY}" ]
then echo "${0##*/}: no DISPLAY found." >&2
exit 99
else
case "$(tty)" in
${udev_root}/console|${udev_root}/tty?*)
echo "${0##*/}: must be run from X." >&2
exit 99
;;
esac
fi
# If the tool to send notification is missing, nothing else to do:
if [ ! -x /usr/bin/notify-send ]
then echo "${0##*/}: '/usr/bin/notify-send' not found: you should install 'libnotify-bin'." >&2
exit 2
fi
locked=
unlocked=
perm_or_temp_fs=
this_fs=
# 1. bilibop-lockfs is disabled:
if ! is_aufs_mountpoint -q / &&
[ ! -f "${BILIBOP_RUNDIR}/lock" ]
then
case "${BILIBOP_LOCKFS_NOTIFY_POLICY}" in
always|nolockfs)
notify-send ${EXPIRE_TIME:+--expire-time=${EXPIRE_TIME}} \
--urgency="normal" \
--icon="changes-allow" \
"bilibop-lockfs is disabled" \
"All informations about the actual\nsession can be written on the disk."
;;
esac
# Nothing else to do:
exit 0
fi
# 2. bilibop-lockfs is enabled
# 2.1. Send notification for locked fs:
case "${BILIBOP_LOCKFS_NOTIFY_POLICY}" in
always|lockfs)
for fs in $(aufs_mountpoints)
do
locked="${locked:+${locked}, }'${fs}'"
done
if [ -z "${locked}" ]
then
notify-send \
--urgency="critical" \
--icon="error" \
"*** BILIBOP LOCKFS - ERROR ***" \
"Unknown error"
exit 3
elif echo "${locked}" | grep -q ', '
then
locked="$(echo ${locked} | sed "s;, \('/[^,' ]\+'\)$; and \1 are;")"
perm_or_temp_fs="volatile filesystems"
this_fs="these filesystems"
else
locked="${locked} is"
perm_or_temp_fs="a volatile filesystem"
this_fs="this filesystem"
fi
notify-send ${EXPIRE_TIME:+--expire-time=${EXPIRE_TIME}} \
--urgency="normal" \
--icon="changes-prevent" \
"bilibop-lockfs is enabled" \
"${locked} mounted as ${perm_or_temp_fs} (aufs).\nAll changes on ${this_fs} will be lost at shutdown."
;;
esac
# 2.1. Send notification for non-locked fs:
case "${BILIBOP_LOCKFS_NOTIFY_POLICY}" in
always|nolockfs)
BILIBOP_DISK="$(physical_hard_disk /)"
for fs in $(grep '^/' /proc/mounts | grep -v '^[^ ]\+\s/aufs/' | sed 's;^[^ ]\+\s\(/[^ ]*\)\s.*;\1;')
do
[ "$(physical_hard_disk ${fs})" = "${BILIBOP_DISK}" ] &&
unlocked="${unlocked:+${unlocked}, }'${fs}'"
done
if [ -z "${unlocked}" ]
then exit 0
elif echo "${unlocked}" | grep -q ', '
then
unlocked="$(echo ${unlocked} | sed "s;, \('/[^,' ]\+'\)$; and \1 are;")"
perm_or_temp_fs="persistent filesystems"
this_fs="these filesystems"
else
unlocked="${unlocked} is"
perm_or_temp_fs="a persistent filesystem"
this_fs="this filesystem"
fi
notify-send ${EXPIRE_TIME:+--expire-time=${EXPIRE_TIME}} \
--urgency="normal" \
--icon="changes-allow" \
"bilibop-lockfs whitelist" \
"${unlocked} mounted as ${perm_or_temp_fs}.\nAll changes on ${this_fs} will be kept at shutdown."
esac
|