#!/bin/bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # A simple u/mount devices script. Fast written for my # Backupserver. Shurely not the best one but it works (= # # If you got problems with this one, send me a PM/Mail # (yokmp@users.sf.net). # Feel free to change the functionnames to whatever. # # Have fun. # # p.s. excuse my bad english ... # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # text formations fat='\e[1m' nf='\e[0m' # u/mount: # the names under which the devices will be mounted # it also sets the loops break # so 5 devices mean 'loop five times' ... er, you got it DEVICE_NAME=(some names here) # the filesystems FS_TYPE=(btrfs ext4 ext3) # path of the devices DEVICE=(/dev/sda /dev/sdb /dev/sdc) # path where they will be mounted # unset for root path (may a bad idea) DEVICE_PATH=(/var/ftp/miranda /home/yokmp/Share /home/yokmp/Backup) # here comes the magical mount thingy function mftp() { echo -e "\n\t${fat}Mounting:${nf}" for (( i=0 ; i<=${#DEVICE_NAME[@]} ; i++ )); do [ $i -eq ${#DEVICE_NAME[@]} ] && break echo -e "\n\tMount ${fat}${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]}/ ${nf} ..." echo -e "\t${fat}${DEVICE[$i]} - (${FS_TYPE[$i]})${nf}" mount -t ${FS_TYPE[$i]} ${DEVICE[$i]} ${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]} [ $? -ne 0 ] && fuser -vu ${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]} done echo -e "\n\t${fat}Done!${nf}\n" } # the same as above but in 'reverse mode' ^^ function uftp() { echo -e "\n\t${fat}Unmounting:${nf}" for (( i=0 ; i<=${#DEVICE_NAME[@]} ; i++ )); do [ $i -eq ${#DEVICE_NAME[@]} ] && break echo -e "\n\tUnmount ${fat}${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]}/ ${nf} ..." echo -e "\t${fat}${DEVICE[$i]} - (${FS_TYPE[$i]})${nf}" umount ${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]} [ $? -ne 0 ] && fuser -vu ${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]} && break done echo -e "\n\t${fat}Done!${nf}\n" }