Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This script is essentially an automated pmount tool which allows you to
- # drop .key files into a directory and automatically mount any/all of them.
- #Point this at your directory containing .key files used to unlock any device
- keydir=$SECRETSDIR/luks
- # This assigns every keyfile as a usable variable for later
- keyfiles=$(ls -f $keydir | grep key )
- # Strips the ".key" from all keyfiles
- keys=$(ls -f $keydir | grep key | cut -d '.' -f 1)
- # Gets a list of all UUIDs
- devices=$(lsblk -o UUID)
- # Compares all keyfiles with devices, assigning all eligable ones to an array
- identified=(`echo ${keys[@]} ${devices[@]} | tr ' ' '\n' | sort | uniq -d `)
- menu(){
- clear
- while true; do
- read -p $'>> ' input
- case $input in
- exit|quit|end|terminate|kill|back ) return 0;;
- scan|ls|show ) scan;;
- mount|mnt ) mount;;
- unmount|unmnt|umount|un|remove ) unmount;;
- help ) help;;
- cls|clear|clr ) clear;;
- ? ) help;;
- * ) echo 'Input not recognized, please enter "help" or "?" ';;
- esac
- done
- }
- help(){
- echo "help: this menu"
- echo "scan|ls|show: list eligible devices"
- echo "mount|mnt: enter interactive mount menu"
- echo " 0-9 select a mount device "
- echo " cls|clr|clear: clears the screen "
- echo "back|exit|return: return to previous menu and/or exit the program"
- }
- mount(){
- clear
- echo "Enter index number to begin mount process:"
- for (( i=0; i<${#identified[@]}; i++ ));
- do
- echo $i".)" ${identified[$i]}
- done
- # echo pmount -p "$keydir"/"${identified[$input]}"".key" /dev/disk/by-uuid/"${identified[$input]}" "${identified[$input]}"
- while true; do
- read -p $'[mnt] >> ' input
- case $input in
- [Yy]* ) return 1;;
- [Nn]* ) return 1;;
- exit|back|return|cancel ) return 1;;
- scan|ls|show ) scan;;
- mount|mnt ) echo "You are already in the mount menu";;
- cls|clear|clr ) clear;;
- 1|2|3|4|5|6|7|8|9|0 ) mount_prompt $input;;
- help ) help;;
- ? ) help;;
- * ) echo 'Input not recognized, please enter "help" or "?" ';;
- esac
- done
- }
- mount_prompt(){
- clear
- echo "Are you sure you wish to unlock ${identified[$input]}?"
- echo "This will be mounted at /media/${identified[$input]}"
- while true; do
- read -p $'[y/N] >> ' prompt
- case $prompt in
- [Yy]* ) break;;
- [Nn]* ) return 1;;
- * ) echo 'Please enter yes or no. ';;
- esac
- done
- pmount -d -p $keydir/${identified[$input]}".key" /dev/disk/by-uuid/${identified[$input]} ${identified[$input]}
- }
- scan(){
- echo -e "Detected the following eligible devices:"
- mediadir=$(ls /media)
- currentlymounted=(`echo ${currentkeys[@]} ${mediadir[@]} | tr ' ' '\n' | sort | uniq -d `)
- currentkeys=$(ls -f $keydir | grep key | cut -d '.' -f 1)
- identified=(`echo ${keys[@]} ${devices[@]} | tr ' ' '\n' | sort | uniq -d `)
- for (( i=0; i<${#identified[@]}; i++ ));
- do
- echo $i".)" ${identified[$i]}
- done
- echo ""
- echo -e "Detected the following mounted devices:"
- for (( i=0; i<${#currentlymounted[@]}; i++ ));
- do
- echo $i".)" ${currentlymounted[$i]}
- done
- i=0
- mediadir=0
- currentlymounted=0
- curentkeys=0
- }
- unmount(){
- clear
- echo "Enter index number to begin unmount process:"
- for (( i=0; i<${#identified[@]}; i++ ));
- do
- echo $i".)" ${identified[$i]}
- done
- # echo pmount -p "$keydir"/"${identified[$input]}"".key" /dev/disk/by-uuid/"${identified[$input]}" "${identified[$input]}"
- while true; do
- read -p $'[mnt] >> ' input
- case $input in
- [Yy]* ) return 1;;
- [Nn]* ) return 1;;
- exit|back|return|cancel ) return 1;;
- scan|ls|show ) scan;;
- mount|mnt ) echo "You are already in the mount menu";;
- cls|clear|clr ) clear;;
- 1|2|3|4|5|6|7|8|9|0 ) mount_prompt $input;;
- help ) help;;
- ? ) help;;
- * ) echo 'Input not recognized, please enter "help" or "?" ';;
- esac
- done
- }
- unmount_prompt(){
- echo test
- }
- menu
Advertisement
Add Comment
Please, Sign In to add comment