virpara

mount-unmount v0.2

May 24th, 2012
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.26 KB | None | 0 0
  1. #!/bin/bash
  2. #Mount Unmount secret partitions now with choice of partition
  3. #Note: Replace X1,X2...etc. respectively
  4. function checkPartitions(){
  5.     local state=$1
  6.     local dev=$2
  7.     case $state in
  8.     "unmounted")
  9.         mount | grep -q $dev
  10.         if [ $? -eq 1 ]; then
  11.             echo $dev
  12.         fi
  13.         ;;
  14.     "mounted")
  15.         mount | grep -q $dev
  16.         if [ $? -eq 0 ]; then
  17.             echo $dev
  18.         fi
  19.         ;;
  20.     esac
  21. }
  22.  
  23. function safeUnmount() {
  24.     local dev=$1
  25.     mount | grep -q $dev
  26.     if [ $? -eq 0 ]; then
  27.         echo "Device $dev found. Unmounting now"
  28.         sudo umount $dev
  29.         if [ $? -eq 0 ]; then
  30.             echo "Device $dev unmounted successfully."
  31.         else
  32.             echo "You are not root??"
  33.         fi
  34.     else
  35.         echo "Device $dev is already unmounted."
  36.     fi
  37. }
  38.  
  39. function safeMount() {
  40.     local dev=$1
  41.     mount | grep -q $dev
  42.     if [ $? -eq 1 ]; then
  43.         echo "Device $dev not found. Mounting now"
  44.         sudo mount $dev
  45.         if [ $? -eq 0 ]; then
  46.             echo "Device $dev mounted successfully."
  47.         else
  48.             echo "You are not root??"
  49.         fi
  50.     else
  51.         echo "Device $dev is already mounted."
  52.     fi
  53. }
  54.  
  55. echo -e "What you want to do? \n 1. Mount Secret Partitions \n 2. Unmount Secret Partitions"
  56. read -p "Enter your choice :" choice
  57.  
  58. case $choice in
  59. 1)
  60.     echo -e "You want to Mount your secret partitions"
  61.     echo "-------List of Unmounted secret partitions-------"
  62.     checkPartitions "unmounted" "/dev/sdaX1"
  63.     checkPartitions "unmounted" "/dev/sdaX2"
  64.     checkPartitions "unmounted" "/dev/sdaX3"
  65.     checkPartitions "unmounted" "/dev/sdaX4"
  66.     anythingelse="y"
  67.     #echo -e "\n"
  68.     while [ $anythingelse == y -o $anythingelse == Y ]; do
  69.         read -p "Which partition should be mounted? " partNum
  70.             safeMount "/dev/sda"$partNum
  71.         read -p "Do you want to mount any other partition? [y/n] " anythingelse
  72.     done
  73.     ;;
  74. 2)
  75.     echo -e "You want to Unmount your secret partitions\n"
  76.     echo "--------List of Mounted secret partitions--------"
  77.     checkPartitions "mounted" "/dev/sdaX1"
  78.     checkPartitions "mounted" "/dev/sdaX2"
  79.     checkPartitions "mounted" "/dev/sdaX3"
  80.     checkPartitions "mounted" "/dev/sdaX4"
  81.     anythingelse="y"
  82.     #echo -e "\n"
  83.     while [ $anythingelse == y -o $anythingelse == Y ]; do
  84.         read -p "Which partition should be unmounted? " partNum
  85.             safeUnmount "/dev/sda"$partNum
  86.         read -p "Do you want to unmount any other partition? [y/n] " anythingelse
  87.     done
  88.     ;;
  89. esac
Advertisement
Add Comment
Please, Sign In to add comment