previously on this list Hugo Pompougnac contributed:

> As a
> student, I'm discovering OpenBSD. I'm trying to automount USB keys with
> hotplug, 
> but it's quite difficult. That's why I ask to you.

Hi,

This mounts FFS, ext2fs, NTFS, MSDOS but not cd at the moment and falls
back to ro mode giving a message saying so on a single user X11 session
with places to add logging via logger.

You can put /etc/hotplug/attach-user in /etc/hotplug/attach and it
should work (if not strip out the sudo usage) or use the various files
to only run the mounting as root via sudo.

The one which runs via sudo requires attach, attach-user,
sudoers.include. Both should have logging and comments added but I
haven't the time right now but it should be easy enough to follow. Let
me know if you have any issues.

If you have problems with it inlined I'll attach them and send them
privately. Just let me know.

ntfs-3g is set to remove_hiberfile. If you dual boot you may want to
change that.

_______________________________________________________________________

/etc/hotplug/attach
_______________________________________________________________________
#!/bin/sh
#exec >> /tmp/logfile 2>&1
#set -x
/usr/bin/su _automount -m -c "/usr/local/mybin/attach-oesys $1 $2"

_______________________________________________________________________

/usr/local/mybin/attach-user - put where you like just edit above and
must executable by _automount
_______________________________________________________________________

#!/bin/sh
# Author: Kevin Chadwick
# License: BSD
#________________________ 
#
#       CONFIG 
#________________________
#exec >> /tmp/logfile 2>&1
#set -x

MOUNTLOCATION="/mnt/usb"
#Maybe useful to grab a username running a single xsession
#USER=$(/usr/bin/w | /usr/bin/grep xinit | /usr/bin/cut -d " " -f 1)
USER="username"
GROUP="mntaccess"

#________________________

USERID=$(/usr/bin/id -u "$USER")
GROUPID=$(/usr/bin/id -g "$GROUP")
DEVCLASS=$1
DEVNAME=$2
echo "$DEVCLASS" > /tmp/devclass
FREEPOINT=0
        case $DEVCLASS in
        2)
        if [ -f /usr/local/bin/gxmessage ]; then
        XMESSAGE="/usr/local/bin/gxmessage -title 'Automount Info'
-name 'Automount Info'" else
        XMESSAGE='/usr/X11R6/bin/xmessage'
        fi
        getfreepoint() {
                until ! /sbin/mount | /usr/bin/grep -q
"$MOUNTLOCATION""$FREEPOINT" do
                let FREEPOINT=FREEPOINT+1
                done
        }
#IFS=" ";export IFS
        /usr/bin/sudo /sbin/disklabel $DEVNAME | /usr/bin/grep "^ " |
while read PARTLETTER pad pad PARTTYPE do
        getfreepoint
        PARTLETTER=$(echo "$PARTLETTER" | /usr/bin/cut -d ":" -f 1)
        PARTTYPE=$(echo "$PARTTYPE" | /usr/bin/cut -d " " -f 1)
                case $PARTTYPE in
                4.2BSD)
                        if /usr/bin/sudo /sbin/mount -o
nodev,nosuid,noexec,softdep /dev/"$DEVNAME""$PARTLETTER"
"$MOUNTLOCATION""$FREEPOINT" then echo ""
                        else
                        /usr/bin/sudo /sbin/mount -o
ro,nodev,nosuid,noexec /dev/"$DEVNAME""$PARTLETTER"
"$MOUNTLOCATION""$FREEPOINT" && /usr/bin/sudo /usr/bin/su "$USER" -c
"/usr/bin/env DISPLAY=:0 $XMESSAGE -file /usr/local/mybin/romessage.txt
&" fi ;; ext2fs) if /usr/bin/sudo /sbin/mount_ext2fs -o
nodev,nosuid,noexec /dev/"$DEVNAME""$PARTLETTER"
"$MOUNTLOCATION""$FREEPOINT" then echo ""
                        else
                        /usr/bin/sudo /sbin/mount_ext2fs -o
ro,nodev,nosuid,noexec /dev/"$DEVNAME""$PARTLETTER"
"$MOUNTLOCATION""$FREEPOINT" && /usr/bin/sudo /usr/bin/su "$USER" -c
"/usr/bin/env DISPLAY=:0 $XMESSAGE -file /usr/local/mybin/romessage.txt
&" fi ;; NTFS) if /usr/bin/sudo /usr/local/bin/ntfs-3g -o
uid="$USERID",gid="$GROUPID",umask=007,norecover,remove_hiberfile,noatime,show_sys_files,window_names
 /dev/"$DEVNAME""$PARTLETTER"
"$MOUNTLOCATION""$FREEPOINT" then echo ""
                        else
                        /usr/bin/sudo /sbin/mount_ntfs -m 770 -u
"$USER" -g "$GROUP" -o
nodev,nosuid,noexec,ro /dev/"$DEVNAME""$PARTLETTER"
"$MOUNTLOCATION""$FREEPOINT" && /usr/bin/sudo /usr/bin/su "$USER" -c
"/usr/bin/env DISPLAY=:0 $XMESSAGE -file /usr/local/mybin/romessage.txt
&" fi ;; MSDOS) if /usr/bin/sudo /sbin/mount_msdos -m 770 -o
nodev,nosuid,noexec -u "$USER" -g "$GROUP" /dev/"$DEVNAME""$PARTLETTER"
"$MOUNTLOCATION""$FREEPOINT" then echo "" else
                        /usr/bin/sudo /sbin/mount_msdos -m 770 -o
ro,nodev,nosuid,noexec -u "$USER" -g
"$USER" /dev/"$DEVNAME""$PARTLETTER" "$MOUNTLOCATION""$FREEPOINT"
&& /usr/bin/sudo /usr/bin/su "$USER" -c "/usr/bin/env DISPLAY=:0
$XMESSAGE -file /usr/local/mybin/romessage.txt &" fi ;; *) echo ""
                ;;
                esac
done
;;
esac

_______________________________________________________________________

Add to sudoers or a file that is included within sudoers
_______________________________________________________________________

Defaults:_automount !requiretty
_automount ALL=NOPASSWD: NOEXEC: /sbin/mount -o
nodev\,nosuid\,noexec\,softdep /dev/sd[0-9][a-z] /mnt/usb[0-9], /sbin/mount
-o
ro\,nodev\,noexec /dev/sd[0-9][a-z] /mnt/usb[0-9], /sbin/mount_ext2fs
-o
nodev\,nosuid\,noexec /dev/sd[0-9][a-z] /mnt/usb[0-9], /sbin/mount_ext2fs
-o
ro\,nodev\,nosuid\,noexec /dev/sd[0-9][a-z] /mnt/usb[0-9], 
/usr/local/bin/ntfs-3g
-o
uid=3101\,gid=1000\,umask=007\,norecover\,remove_hiberfile\,noatime\,show_sys_files\,window_names
 /dev/sd[0-9][a-z] /mnt/usb[0-9], /sbin/mount_ntfs
-m 770 -u oesys -g mntaccess -o
nodev\,nosuid\,noexec\,ro /dev/sd[0-9][a-z] /mnt/usb[0-9], /usr/bin/su
oesys -c /usr/bin/env DISPLAY=\:0 /usr/local/bin/gxmessage -title
'Automount Info' -name 'Automount Info'
-file /usr/local/mybin/romessage.txt &, /usr/bin/su oesys
-c /usr/bin/env DISPLAY=\:0 /usr/X11R6/bin/xmessage
-file /usr/local/mybin/romessage.txt &, /sbin/mount_msdos -m 770 -o
nodev\,nosuid\,noexec -u oesys -g
mntaccess /dev/sd[0-9][a-z] /mnt/usb[0-9], /sbin/mount_msdos -m 770 -o
ro\,nodev\,nosuid\,noexec -u oesys -g
mntaccess /dev/sd[0-9][a-z] /mnt/usb[0-9], /sbin/disklabel sd[0-9]


_______________________________________________________________________

/usr/local/mybin/romessage.txt
_______________________________________________________________________

  Mounted Device Read-Only due to the filesystem being marked as
  needing checking.

  Perhaps it was unplugged without first being unmounted?
_______________________________________________________________________

_______________________________________________________________________

-- 
_______________________________________________________________________

'Write programs that do one thing and do it well. Write programs to work
together. Write programs to handle text streams, because that is a
universal interface'

(Doug McIlroy)

In Other Words - Don't design like polkit or systemd
_______________________________________________________________________

Reply via email to