linux-live/Slax/debian/rootcopy/sbin/slax-automount

56 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Recreate fstab entries in /etc/fstab and make /media directories
# This script is called by udev rules, see /lib/udev/rules.d/
#
# Author: Tomas M <http://slax.linux-live.org/>
# Variables available in udev environment:
# $ACTION (eg: add, remove)
# $DEVNAME (full device node name including path)
# $DEVTYPE (eg: disk)
# $ID_FS_TYPE (eg: ext3)
# $MAJOR and $MINOR numbers
# $SUBSYSTEM (eg: block)
PATH=$PATH:/usr/bin:/usr/sbin:/bin:/sbin
BOOKMARKS="/root/.gtk-bookmarks"
BAS="$(basename "$DEVNAME")"
UNIT="media-$BAS.mount"
MNT="/media/$BAS"
TARGET="/etc/systemd/system/$UNIT"
if [ "$ACTION" = "add" -o "$ACTION" = "change" ]; then
if [ ! -r "$TARGET" ]; then # skip if exists
if [ "$ID_FS_TYPE" != "" -a "$(cat /proc/filesystems | grep "$ID_FS_TYPE")" != "" ]; then
mkdir -p "$MNT"
echo "[Unit]" >$TARGET
echo "Description=Disk $BAS" >>$TARGET
echo "" >>$TARGET
echo "[Mount]" >>$TARGET
echo "What=$DEVNAME" >>$TARGET
echo "where=$MNT" >>$TARGET
echo "Type=$ID_FS_TYPE" >>$TARGET
echo "Options=defaults" >>$TARGET
echo "" >>$TARGET
echo "[Install]" >>$TARGET
echo "WantedBy=multi-user.target" >>$TARGET
systemctl enable $UNIT
systemctl start $UNIT
echo "file://$MNT" "$BAS" >>$BOOKMARKS
fi
fi
fi
if [ "$ACTION" = "remove" ]; then
systemctl disable $UNIT
rm $TARGET
sed -i -r "\\;^file://$MNT;d" $BOOKMARKS
fi