metalx1000

script for mounting and unmounting drives

May 15th, 2020
550
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2019  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. function mount(){
  21.   drive="$((echo "quit";lsblk -nro name,mountpoint | awk '$1~/[[:digit:]]/ && $2 == ""')|fzf)"
  22.   if [ "$drive" != "quit" ];then
  23.     label="$(lsblk -nro name,label,uuid|grep "$drive"|awk '{print $2}')"
  24.     sudo mkdir -p /media/$USER/$label
  25.     sudo mount -o umask=000 /dev/$drive /media/USER/$label
  26.   fi
  27.   exit 0
  28. }
  29.  
  30. function unmount(){
  31.   drive="$((echo "quit";lsblk -nro name,mountpoint | awk '$1~/[[:digit:]]/ && $2 != ""')|fzf)"
  32.   if [ "$drive" != "quit" ];then
  33.     #label="$(lsblk -nro name,label,uuid|grep "$drive"|awk '{print $2}')"
  34.     drive="$(echo $drive|awk '{print $1}')"
  35.     sudo umount /dev/$drive
  36.     #sudo rm /media/$label
  37.   fi
  38.   exit 0
  39. }
  40.  
  41. if [ "$1" = "u" ];then
  42.   unmount
  43. else
  44.   mount
  45. fi
RAW Paste Data