X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=scripts%2Fgrml-udev-rebuildfstab;h=40d80789d543da1319340f9aa465de1eca86004c;hb=b2080fafcb8624b8061936a54c6f500934def44d;hp=123f8f734a6b6102a464ace83bce4f9191b1488e;hpb=bcb6b08212da6aa3097015f8fa10ad0c6de181fd;p=grml-udev-config.git diff --git a/scripts/grml-udev-rebuildfstab b/scripts/grml-udev-rebuildfstab index 123f8f7..40d8078 100755 --- a/scripts/grml-udev-rebuildfstab +++ b/scripts/grml-udev-rebuildfstab @@ -1,17 +1,17 @@ #!/bin/bash -# Filename: rebuildfstab -# Purpose: calls scanpartitions as root and adds entries to /etc/fstab -# Authors: grml-team (grml.org), (c) Klaus Knopper Nov 2002, (c) Michael Prokop +# Filename: scripts/grml-udev-rebuildfstab +# Purpose: udev script to update /etc/fstab +# Authors: grml-team (grml.org) # Bug-Reports: see http://grml.org/bugs/ -# License: This file is licensed under the GPL v2. +# License: This file is licensed under the GPL v2+. ################################################################################ PATH="/bin:/sbin:/usr/bin:/usr/sbin" TMP=$(mktemp 2>/dev/null) TMPFILE=$(mktemp 2>/dev/null) ADDEDBYGRML="# Added by GRML" -MNTFILE="/mnt/.grml-auto-created_do-not-delete-this-file" -MOUNTPOINT_PREFIX=/mnt/ +MOUNTPOINT_PREFIX=/media +MNTFILE="$MOUNTPOINT_PREFIX/.grml-auto-created_do-not-delete-this-file" logit() { @@ -53,20 +53,44 @@ if grep -q " nofstab" /proc/cmdline ; then bailout 0 fi -grep -q 'nolabel' /proc/cmdline && NOLABEL='TRUE' || LABEL='TRUE' - - - if [ "$CONFIG_FSTAB" = "no" ] ; then bailout 0 fi -if grep -q ' /mnt ' /proc/mounts ; then - logit '/mnt is a mounted directory, exiting.' +if grep -q ' $MOUNTPOINT_PREFIX ' /proc/mounts ; then + logit '$MOUNTPOINT_PREFIX is a mounted directory, exiting.' bailout 1 fi +LABEL=true # by default use labels + +if [ -r /etc/grml/rebuildfstab.conf ] ; then + logit 'Reading /etc/grml/rebuildfstab.conf' + . /etc/grml/rebuildfstab.conf + + if [ "$LABEL" = "false" ] ; then + logit 'Disabling LABEL=... in /etc/fstab as requested via LABEL=false' + fi +fi + +# support overriding via boot option +if grep -q ' nolabel' /proc/cmdline ; then + LABEL=false +fi + +if grep -q ' label' /proc/cmdline ; then + LABEL=true +fi + +# default directories {{{ +if [ -d "$MOUNTPOINT_PREFIX" ] ; then + [ -d "$MOUNTPOINT_PREFIX/floppy" ] || mkdir "$MOUNTPOINT_PREFIX/floppy" + [ -d "$MOUNTPOINT_PREFIX/cdrom" ] || mkdir "$MOUNTPOINT_PREFIX/cdrom" + [ -d "$MOUNTPOINT_PREFIX/test" ] || mkdir "$MOUNTPOINT_PREFIX/test" +fi +# }}} + # make sure we have the $MNTFILE before reading/writing into it if [ -z "$NO_AUTO_FILE" ] ; then [ -r $MNTFILE ] || touch $MNTFILE @@ -84,22 +108,21 @@ proc /proc proc rw,nosuid,nodev,noexec 0 none /proc/bus/usb usbfs defaults,noauto 0 0 sysfs /sys sysfs rw,nosuid,nodev,noexec 0 0 devpts /dev/pts devpts noauto,mode=0622 0 0 -/dev/fd0 /mnt/floppy auto user,noauto,exec 0 0 -/dev/external /mnt/external auto user,noauto,exec,rw,uid=grml,gid=grml 0 0 -/dev/external1 /mnt/external1 auto user,noauto,exec,rw,uid=grml,gid=grml 0 0 -/dev/cdrom /mnt/cdrom auto user,noauto,exec,ro 0 0 -/dev/dvd /mnt/dvd auto user,noauto,exec,ro 0 0 +/dev/external ${MOUNTPOINT_PREFIX}/external auto user,noauto,exec,rw,uid=grml,gid=grml 0 0 +/dev/external1 ${MOUNTPOINT_PREFIX}/external1 auto user,noauto,exec,rw,uid=grml,gid=grml 0 0 +/dev/cdrom ${MOUNTPOINT_PREFIX}/cdrom auto user,noauto,exec,ro 0 0 +/dev/dvd ${MOUNTPOINT_PREFIX}/dvd auto user,noauto,exec,ro 0 0 # some other examples: -# /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2 +# /dev/sda1 /Grml ext3 dev,suid,user,noauto 0 2 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0 # linux:/pub /beer nfs defaults 0 0 # tmpfs /tmp tmpfs size=300M 0 0 # none /proc/bus/usb usbfs defaults,nodev,noexec,nosuid,noauto,devgid=1001,devmode=664 0 0 -# 192.168.1.101:/backups /mnt/nfs nfs defaults,user,wsize=8192,rsize=8192 0 0 +# 192.168.1.101:/backups ${MOUNTPOINT_PREFIX}/nfs nfs defaults,user,wsize=8192,rsize=8192 0 0 # -# Warning! Please do *not* change any lines below because they are auto-generated by rebuildfstab! +# Warning! Please do *not* change any lines below because they are auto-generated. # If you want to disable rebuildfstab set CONFIG_FSTAB='no' in /etc/grml/autoconfig! -# See 'man grml-rebuildfstab' for more details about the following entries. +# See 'man grml-udev-rebuildfstab' for more details about the following entries. EOF fi ) 200>/var/run/rebuildfstab.lock @@ -138,19 +161,17 @@ iso9660) break; ;; *) -if [ -n "$LABEL" ] && [ -n "$ID_FS_LABEL_ENC" ] ; then +if "$LABEL" && [ -n "$ID_FS_LABEL_ENC" ] ; then # see check_for_label() in scanpartitions for details case $ID_FS_LABEL_ENC in - *\ *|*\x20*) - addinfo=" # space char inside label ($ID_FS_LABEL_ENC) not supported" - break ;; - /) - addinfo=" # label '/' not supported" + *\x*) + logit "special char in label ($ID_FS_LABEL_ENC) not supported, skipping label for $DEVNAME" break ;; + *) + echo "LABEL=$ID_FS_LABEL_ENC" + return + break; esac - - echo "LABEL=$ID_FS_LABEL_ENC" - return fi ;; esac @@ -159,7 +180,7 @@ esac NAME="$DEVNAME" for name in $DEVLINKS ; do case $name in - *usb*|*cdrom*|*dvd*) + *usb-sd*|*cdrom*|*dvd*) NAME="$name" break; ;; @@ -172,7 +193,7 @@ get_mount_point() { device="$1" mountpoint="${device##*/}" mountpoint="${mountpoint#*=}" - echo /mnt/$mountpoint + echo "$MOUNTPOINT_PREFIX/$mountpoint" } append_fstab() { @@ -228,13 +249,18 @@ done # if entry is already present ignore it stringinfile $device $TMPFILE && bailout 0 +if [ "$ID_FS_USAGE" != "filesystem" -a "$ID_FS_TYPE" != "swap" ]; then + # blockdevice in question won't be mountable in this case + bailout 0 +fi + options=noauto,user,dev,suid,exec case $ID_FS_TYPE in ntfs) - options=$options,ro,umask=000 + options=$options,dmask=000,fmask=111 ;; vfat|msdos) - options=$options,umask=000 + options=$options,dmask=000,fmask=111 ;; ufs) options=$options,ro @@ -250,19 +276,27 @@ ntfs|vfat|msdos) ;; esac +# when we don't use labels then write the label information into the comment +if ! "$LABEL" && [ -n "$ID_FS_LABEL_ENC" ] ; then + addinfo="# LABEL=$ID_FS_LABEL_ENC" + devinfo="" +else # otherwise (when using labels) write the device name into the comment + devinfo="# $DEVNAME" +fi + case $ACTION in add|change) ( flock -x 200 - echo $ADDEDBYGRML $DEVNAME >> /etc/fstab - echo $device $mountpoint $ID_FS_TYPE $options 0 0 $addinfo >> /etc/fstab + echo "$ADDEDBYGRML $DEVNAME" >> /etc/fstab + echo "$device $mountpoint $ID_FS_TYPE $options 0 0 ${addinfo}${devinfo}" >> /etc/fstab ) 200>/var/run/rebuildfstab.lock ;; esac -# Clean /mnt/... according to info $MNTFILE +# Clean $MOUNTPOINT_PREFIX according to info $MNTFILE if [ -r "$MNTFILE" ] ; then for directory in $(cat $MNTFILE) ; do rmdir $directory 2>/dev/null && sed -i "s#$directory##" $MNTFILE @@ -271,7 +305,7 @@ if [ -r "$MNTFILE" ] ; then cat $TMPFILE > $MNTFILE fi -# Make sure we have all /mnt/* directories +# Make sure we have all directories in $MOUNTPOINT_PREFIX while read p m f relax; do case "$m" in *none*|*proc*|*sys*|'') continue ;; esac if ! grep -q "$m" /proc/mounts ; then