Mount and unmount USB drives with simple commands+xmount
#!/bin/sh # # xmount # Mount or unmount a filesystem defined in /etc/fstab and display any # error messages generated in a dialog box. Useful for one-click # buttons and customized desktop pop-up menus in not-so-popular desktop # environments. # # Author: Ariel Millennium Thornton # Copyright: 2016. License is BSD 3-clause at end of file. # # Requires: Xdialog # # Prerequisite: # # Configure a filesystem for mounting/unmounting by the user, such as a # USB disk or flash drive. For Linux, add a line to /etc/fstab like: # # UUID=1234-ABCD /disk/me/my-flashdrive vfat user,noauto 0 0 # # where "1234-ABCD" is the drive's UUID listed in /dev/disk/by-uuid and # where "/disk/me/my-flashdrive" is what you want the drive's mountpoint # to be. (And assuming a DOS/Windows FAT filesystem.) # # For FreeBSD, add a line to /etc/fstab like: # # /dev/diskid/[string]s1 /disk/me/my-flashdrive msdosfs rw,noauto,-l 0 0 # # where "/dev/diskid/[string]s1" is the long string of letters and # numbers in /dev/diskid that starts with "DISK-" and ends with "s1" (or # "s2" for the second partition/slice of a multi-partition USB disk) and # where "/disk/me/my-flashdrive" is what you want the drive's mountpoint # to be. (And likewise assuming a DOS/Windows FAT filesystem.) # # The mountpoint directory must exist already, and in FreeBSD, it must # be owned by the user who will mount the USB disk. # # Once configured, the following commands should mount and unmount the # filesystem (with "/disk/me/my-flashdrive" replaced with your actual # mountpoint): # # mount /disk/me/my-flashdrive # umount /disk/me/my-flashdrive # # Without needing to be root, without needing to specify the device, and # without needing to pass any other options at all. # # Usage: # # To mount the defined mountpoint /disk/me/my-flashdrive: # # xmount m /disk/me/my-flashdrive # # To unmount the filesystem mounted at /disk/me/my-flashdrive: # # xmount u /disk/me/my-flashdrive # # Silence GTK and related log messages. XDIALOG_NO_GMSGS=1 gotime=1 # Is it go time? 1 for go, 0 for abort. # Program usage message, in case we need to abort. u="Usage: xmount { m | u } mountpoint" # If we need to abort, $t is also the reason title and $m is also the # reason message for the dialog box. # Do we have a mountpoint? if [ -z "$2" ] then t="Not enough parameters" m="Where is the mountpoint?\n" gotime=0 fi # Do we even have a mount/unmount flag? if [ -z "$1" ] then t="Not enough parameters" m="Am I mounting or unmounting?\n" gotime=0 fi # Is the mount/unmount flag actually "m" or "u"? if [ $1 != "m" -a $1 != "u" ] then t="First parameter is wrong" m="The first parameter must be 'm' or 'u'\nfor mount or unmount.\n" gotime=0 fi # If we need to abort, show the dialog box explaining what went wrong, # then quit with an error. if [ $gotime -eq 0 ] then Xdialog --title "xmount: $t" \ --msgbox "$m\n$u" \ 8 40 exit 1 fi # Mount the filesystem and quit successfully. if [ "$1" = "m" ] then message=$( mount $2 2>&1 ) # # If the mount command was noisy (such as the USB drive not inserted # or it's already mounted), show its output. if [ ! -z "${message}" ] then echo "${message}" | \ Xdialog --title "xmount: mounting $2" \ --no-cancel \ --textbox - 8 40 fi exit 0 fi # Unmount the filesystem and quit successfully. if [ "$1" = "u" ] then message=$( umount $2 2>&1 ) # # If the umount command was noisy (such as being busy or not even # mounted to begin with), show its output. if [ ! -z "${message}" ] then echo "${message}" | \ Xdialog --title "xmount: unmounting $2" \ --no-cancel \ --textbox - 8 40 fi exit 0 fi # # Copyright (C) 2016 Ariel Millennium Thornton. All rights reserved. # # Developed by: Ariel Millennium Thornton # http://thornton2.com/ArielMT # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal with the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimers. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimers in # the documenation and/or other materials provided with the # distribution. # # 3. The name of Ariel Millennium Thornton may not be used to endorse # or promote products derived from this Software without specific # prior written permission. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR # ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #

 

Journals

2110 medium
Full list of journal entries