LDP/LDP/guide/docbook/abs-guide/usrmnt.sh

55 lines
1.7 KiB
Bash
Raw Normal View History

2003-09-15 14:31:01 +00:00
#!/bin/bash
# usrmnt.sh, written by Anthony Richardson
2012-11-27 14:56:18 +00:00
# Used in ABS Guide with permission.
2003-09-15 14:31:01 +00:00
# usage: usrmnt.sh
# description: mount device, invoking user must be listed in the
# MNTUSERS group in the /etc/sudoers file.
2004-03-15 13:47:54 +00:00
# ----------------------------------------------------------
# This is a usermount script that reruns itself using sudo.
# A user with the proper permissions only has to type
2003-09-15 14:31:01 +00:00
# usermount /dev/fd0 /mnt/floppy
# instead of
# sudo usermount /dev/fd0 /mnt/floppy
# I use this same technique for all of my
#+ sudo scripts, because I find it convenient.
2004-03-15 13:47:54 +00:00
# ----------------------------------------------------------
2003-09-15 14:31:01 +00:00
# If SUDO_COMMAND variable is not set we are not being run through
#+ sudo, so rerun ourselves. Pass the user's real and group id . . .
if [ -z "$SUDO_COMMAND" ]
then
mntusr=$(id -u) grpusr=$(id -g) sudo $0 $*
exit 0
fi
2004-03-15 13:47:54 +00:00
# We will only get here if we are being run by sudo.
2003-09-15 14:31:01 +00:00
/bin/mount $* -o uid=$mntusr,gid=$grpusr
exit 0
# Additional notes (from the author of this script):
# -------------------------------------------------
2003-11-03 16:25:16 +00:00
# 1) Linux allows the "users" option in the /etc/fstab
2003-09-15 14:31:01 +00:00
# file so that any user can mount removable media.
# But, on a server, I like to allow only a few
2004-03-15 13:47:54 +00:00
# individuals access to removable media.
# I find using sudo gives me more control.
2003-09-15 14:31:01 +00:00
# 2) I also find sudo to be more convenient than
# accomplishing this task through groups.
# 3) This method gives anyone with proper permissions
# root access to the mount command, so be careful
2004-03-15 13:47:54 +00:00
# about who you allow access.
# You can get finer control over which access can be mounted
# by using this same technique in separate mntfloppy, mntcdrom,
2003-09-15 14:31:01 +00:00
# and mntsamba scripts.