Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #--[ This is a utility to copy/list files on a drive in cases ]--#
- #--[ where there is only one USB port that a keyboard/mouse ]--#
- #--[ is utilizing. ]--#
- #--[ ]--#
- #--[ Is open source and such, definately edit it as needed. ]--#
- #--[ Written by Lucas C. ]--#
- #--------------[ Various variables assigned here ]---------------#
- waitTime=10
- userIn=$@
- timeCount=$waitTime
- currentDir=$(pwd)
- #--------------[ Functions defined here ]---------------#
- function mountDrive(){
- echo "Mounting drive..."
- mkdir -p /tmp/usbDrive
- mount /dev/sdb /tmp/usbDrive
- }
- function unmountDrive(){
- echo "Unmounting drive..."
- umount /dev/sdb
- echo "Drive unmounted."
- }
- function timer(){
- echo "You have $waitTime seconds to eject keyboard/enter USB drive"
- while [ "$timeCount" != "0" ]
- do
- echo "$timeCount"
- sleep 1
- (( timeCount-- ))
- done
- }
- function helpPl0x(){
- echo "Help section for the delay_copy utility"
- echo ""
- echo "Syntax: delay_copy [option]"
- echo "Or if root permissions are needed: sudo delay_copy [option]"
- echo ""
- echo "Command line arguments are:"
- echo " -cp or --copy - Copy files from the drive to the current working directory"
- echo " -ls or --list - List files from the drive"
- echo " -h or --help - This help page"
- echo " -ct or --copyto - copy file(s) to the USB drive"
- echo ""
- echo "This utility mounts the USB drive at /tmp/usbDrive."
- }
- function reconnectAlert(){
- echo "Devices such as mouse/keyboard can now be reconnected."
- }
- #---------------[ Program starts here ]--------------#
- if [ "$(whoami)" != "root" ]
- then
- echo "Note: You may need to run this utility as root for it to function properly."
- fi
- if [ "$userIn" = "-cp" ] || [ "$userIn" = "--copy" ]
- then
- echo "Enter a filename to copy"
- read -p "> " copyUsbDrive
- timer
- mountDrive
- echo "Copying files..."
- cd /tmp/usbDrive/
- cp $copyUsbDrive "$currentDir"
- cd "$currentDir"
- echo "Files copied."
- unmountDrive
- reconnectAlert
- elif [ "$userIn" = "-ct" ] || [ "$userIn" = "--copyto" ]
- then
- echo "Enter file(s) to copy to the drive"
- read -p "> " copyToDrive
- echo "Enter location on drive to copy files to"
- read -p "> " copyToLocation
- timer
- mountDrive
- echo "Copying files..."
- cp $copyToDrive /tmp/usbDrive/"$copyToLocation"
- echo "Files copied."
- unmountDrive
- reconnectAlert
- elif [ "$userIn" = "-ls" ] || [ "$userIn" = "--list" ]
- then
- echo "Enter a location on the drive to list, leave blank to list contents of drive"
- read -p "> " listUsbDrive
- timer
- mountDrive
- echo "Contents: [" ; echo ""
- ls /tmp/usbDrive/"$listUsbDrive"
- echo "" ; echo "]" ; echo ""
- unmountDrive
- reconnectAlert
- elif [ "$userIn" = "-h" ] || [ "$userIn" = "--help" ]
- then
- helpPl0x
- else
- helpPl0x
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement