Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Mount Unmount secret partitions now with choice of partition
- #Note: Replace X1,X2...etc. respectively
- function checkPartitions(){
- local state=$1
- local dev=$2
- case $state in
- "unmounted")
- mount | grep -q $dev
- if [ $? -eq 1 ]; then
- echo $dev
- fi
- ;;
- "mounted")
- mount | grep -q $dev
- if [ $? -eq 0 ]; then
- echo $dev
- fi
- ;;
- esac
- }
- function safeUnmount() {
- local dev=$1
- mount | grep -q $dev
- if [ $? -eq 0 ]; then
- echo "Device $dev found. Unmounting now"
- sudo umount $dev
- if [ $? -eq 0 ]; then
- echo "Device $dev unmounted successfully."
- else
- echo "You are not root??"
- fi
- else
- echo "Device $dev is already unmounted."
- fi
- }
- function safeMount() {
- local dev=$1
- mount | grep -q $dev
- if [ $? -eq 1 ]; then
- echo "Device $dev not found. Mounting now"
- sudo mount $dev
- if [ $? -eq 0 ]; then
- echo "Device $dev mounted successfully."
- else
- echo "You are not root??"
- fi
- else
- echo "Device $dev is already mounted."
- fi
- }
- echo -e "What you want to do? \n 1. Mount Secret Partitions \n 2. Unmount Secret Partitions"
- read -p "Enter your choice :" choice
- case $choice in
- 1)
- echo -e "You want to Mount your secret partitions"
- echo "-------List of Unmounted secret partitions-------"
- checkPartitions "unmounted" "/dev/sdaX1"
- checkPartitions "unmounted" "/dev/sdaX2"
- checkPartitions "unmounted" "/dev/sdaX3"
- checkPartitions "unmounted" "/dev/sdaX4"
- anythingelse="y"
- #echo -e "\n"
- while [ $anythingelse == y -o $anythingelse == Y ]; do
- read -p "Which partition should be mounted? " partNum
- safeMount "/dev/sda"$partNum
- read -p "Do you want to mount any other partition? [y/n] " anythingelse
- done
- ;;
- 2)
- echo -e "You want to Unmount your secret partitions\n"
- echo "--------List of Mounted secret partitions--------"
- checkPartitions "mounted" "/dev/sdaX1"
- checkPartitions "mounted" "/dev/sdaX2"
- checkPartitions "mounted" "/dev/sdaX3"
- checkPartitions "mounted" "/dev/sdaX4"
- anythingelse="y"
- #echo -e "\n"
- while [ $anythingelse == y -o $anythingelse == Y ]; do
- read -p "Which partition should be unmounted? " partNum
- safeUnmount "/dev/sda"$partNum
- read -p "Do you want to unmount any other partition? [y/n] " anythingelse
- done
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment