Waybar config ide vonatkozó részlete:
"custom/unmount": {
"exec": "~/.config/waybar/modules/unmount.sh check",
"return-type": "json",
"interval": "once", // Erre változik a megadott másodperc polling helyett
"signal": 10, // A kívánt szignál száma
"format": "{icon}",
"on-click": "~/.config/waybar/modules/unmount.sh",
"format-icons": {
"none": "",
"many": "",
"default": ""
},
"tooltip": true,
},
Umount script a waybarhoz (~/.config/waybar/modules/umount.sh):
#!/usr/bin/env bash
entries=$(lsblk -Jo NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT | jq -r '.blockdevices[] | select(.name != "sda") as $dev | $dev.children[]? | select(.mountpoint | type == "string") as $mp | [ $mp.name, $mp.mountpoint ] | @tsv')
count=$(echo -e "$entries" | grep -c '.')
if [ -z $1 ] && [ $count -gt 0 ]; then
selected=$(echo -e "$entries"| wofi --dmenu -H 200 -W 240 -n -p " Unmount devices" -D "hide_search=true" --cache-file /dev/null | cut -f 1)
if [ ! -z $selected ]; then
sudo systemctl stop usb-mount@$selected.service
# notify-send "Mounting" "Umount /dev/$selected device"
pkill -SIGRTMIN+10 waybar
fi
fi
if [[ "$count" -gt 0 ]]; then
class="many"
else
class="none"
fi
printf '{"text":"%d", "class":"%s", "alt":"%s", "tooltip":"%d mounted"}\n' "$count" "$class" "$class" "$count"
Látható, hogy umount után kap szignált a waybar róla, hogy valami történt, frissíteni kell.
Természetesen van még egy systemd script és egy udev script is a teljesség igénye miatt.
Systemd script (/etc/systemd/system/usb-mount@.service):
[Unit]
Description=Mount USB Drive on %i
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/local/bin/usb-mount.sh add %i
ExecStop=/usr/local/bin/usb-mount.sh remove %i
Udev script a felcsatoláshoz (/etc/udev/rules.d/99_local.rules):
KERNEL=="sd[a-z][0-9]", SUBSYSTEMS=="usb", ACTION=="add", RUN+="/bin/systemctl start usb-mount@%k.service"
KERNEL=="sd[a-z][0-9]", SUBSYSTEMS=="usb", ACTION=="remove", RUN+="/bin/systemctl stop usb-mount@%k.service"
KERNEL=="mmcblk[0-9]p[0-9]", SUBSYSTEMS=="block", ACTION=="add", RUN+="/bin/systemctl start usb-mount@%k.service"
KERNEL=="mmcblk[0-9]p[0-9]", SUBSYSTEMS=="block", ACTION=="remove", RUN+="/bin/systemctl stop usb-mount@%k.service"
Csatoló script (/usr/local/bin/usb-mount.sh):
#!/usr/bin/env bash
ACTION=$1
DEVBASE=$2
DEVICE="/dev/${DEVBASE}"
# See if this drive is already mounted
MOUNT_POINT=$(/bin/mount | /bin/grep ${DEVICE} | /usr/bin/awk '{ print $3 }')
do_clean()
{
# Cleanup montpoint
/bin/rmdir ${MOUNT_POINT}
exit 1
}
do_mount()
{
if [[ -n ${MOUNT_POINT} ]]; then
# Already mounted, exit
exit 1
fi
# Get info for this drive: $ID_FS_LABEL, $ID_FS_UUID, and $ID_FS_TYPE
eval $(/sbin/blkid -o udev ${DEVICE})
# Figure out a mount point to use
LABEL=${ID_FS_LABEL}
if [[ -z "${LABEL}" ]]; then
LABEL=${DEVBASE}
elif /bin/grep -q " /media/${LABEL} " /etc/mtab; then
# Already in use, make a unique one
LABEL+="-${DEVBASE}"
fi
MOUNT_POINT="/media/${LABEL}"
/bin/mkdir -p ${MOUNT_POINT}
# Global mount options
OPTS="rw,relatime,users"
# File system type specific mount options
if [[ ${ID_FS_TYPE} == "vfat" ]]; then
OPTS+=",gid=100,umask=000,shortname=mixed,utf8=1,flush"
elif [[ ${ID_FS_TYPE} == "luks" ]]; then
do_clean
fi
if ! /bin/mount -o ${OPTS} ${DEVICE} ${MOUNT_POINT}; then
do_clean
fi
# Bonus track: send desktop notification to user
sudo -u laci DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send "Mounting" "Device ${DEVICE} mounted at ${MOUNT_POINT}"
}
do_unmount()
{
if [[ -n ${MOUNT_POINT} ]]; then
/bin/umount -l ${DEVICE}
sudo -u laci DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send "Mounting" "Device ${DEVICE} umount at ${MOUNT_POINT}"
fi
# Delete all empty dirs in /media that aren't being used as mount points.
for f in /media/* ; do
if [[ -n $(/usr/bin/find "$f" -maxdepth 0 -type d -empty) ]]; then
if ! /bin/grep -q " $f " /etc/mtab; then
/bin/rmdir "$f"
fi
fi
done
}
case "${ACTION}" in
add)
do_mount
;;
remove)
do_unmount
;;
esac
pkill -SIGRTMIN+10 waybar
- CzLaci blogja
- A hozzászóláshoz be kell jelentkezni
- 147 megtekintés