#!/bin/bash #Company: PowerCraft Technology #Author: Copyright Jelle de Jong #Note: Please send me an email if you enhanced this script #Version: 0.0.7 #Date: 02-09-2006 / 01-04-07 / 16-11-07 / 01-01-08 / 2008-12-27 / 2009-06-21 / 2009-08-29 #System: Ubuntu/Debian GNU/Linux #Information: man mount, man mkdir, man umount #Category Thunar scripts #Name: (U)mount image #Description: Create a directory with the imagename and mount or umount image there #Command: xfce4-terminal --disable-server --hide-toolbars --execute /usr/share/pct-thunar-scripts/scripts/u-mount-image %F #Patterns: *.iso; *.img; *.nrg; *.mds; *.ISO; #Other Files: True # Did the script work for you? # Yes # Yes, but with some errors # Yes, but I had to change some things # Not at all # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. TEXTDOMAINDIR=/usr/share/locale TEXTDOMAIN=${0##*/} NAME=$"(U)mount image" DESCRIPTION=$"Create a directory with the imagename and mount or umount image there" cecho() { case "$1" in "black") echo -ne "\E[30m" ;; "red") echo -ne "\E[31m" ;; "green") echo -ne "\E[32m" ;; "yellow") echo -ne "\E[33m" ;; "blue") echo -ne "\E[34m" ;; "magenta") echo -ne "\E[35m" ;; "cyan") echo -ne "\E[36m" ;; *) echo -ne "\E[30m" exit ;; esac echo "$2" "$3" tput sgr0 } cecho "green" $"program:" echo "$0" cecho "green" $"description:" echo "$DESCRIPTION" cecho "green" $"processing file(s):" for I in "$@" do file=${I##*/} echo "$file" done cecho "green" $"enter current working directory:" echo "$PWD" cd "$PWD" for I in "$@" do filetype=$(file -b "$I" | cut -f 1 -d "'") imagename=$(file -b "$I" | cut -f 2 -d "'" | cut -f 1 -d " ") dirname=${I%/*} file=${I##*/} filename=${I##*/}; filename=${filename%.*} extension=${I##*.} cecho "green" $"starting with:" echo "$file" cecho "green" $"file type is:" echo "$filetype" if [ -n "$filename" ] && [ ! -n "$imagename" ] then imagename+=ISO fi if [ "$imagename" = "$filename" ] then imagename+=_MOUNT fi cecho "green" $"image name is:" echo "$imagename" #sudo mount -f "$I" "$imagename" 2> status.txt #status=$(grep --count --ignore-case "already mounted" status.txt) # http://wooledge.org:8000/BashFAQ/032 # mounted=$(sudo mount -n -f "$I" "$imagename" 2>&1) # status=$(echo "$mounted" | grep --count --ignore-case "already mounted") # echo 'some thing with spaces' | sed 's/ /\\040/g' realpath=$(realpath "$I") string=${realpath%/*} # wierd workaround to get a match for paths with spaces string=$(echo "$string" | sed 's/ /\\\\040/g') string+="/$imagename" status=$(grep --count --ignore-case "$string" /etc/mtab) completed=0 if [ "$status" != 0 ] then cecho "green" $"status: " echo $"$imagename already mounted" cecho "green" $"choose a option within 3 seconds, and press enter:" echo $"[1] umount image (used after 3 seconds)" echo $"[2] remount image" echo $"[3] exit" cecho "green" $"option: " read -t3 option; : ${option:=1} #~ read -t3 -p "pleae make your slection within 3 seconds, and press enter: " option if [ "$option" = "1" ]; then echo "$option" fi if [ "$option" = "1" ] then cecho "green" $"umount image" sudo umount -f -l "$imagename" if [ -d "$imagename" ] then echo $"removing mouting directory when empty" rmdir "$imagename" fi completed=1 fi if [ "$option" = "2" ] then cecho "green" $"umount any previous mounts" sudo umount -l "$imagename" fi if [ "$option" = "3" ] then cecho "green" $"exit after 3 seconds" sleep 3 exit fi fi if [ "$filetype" = "ISO 9660 CD-ROM filesystem data " -a $completed -eq 0 ] then #create directory to mount the image [ ! -e "$imagename" ] && mkdir "$imagename" #mount the image to the created directory sudo mount -t iso9660 -o loop "$I" "$imagename" completed=1 fi if [ $completed -eq 0 ] then #create directory to mount the image [ ! -e "$imagename" ] && mkdir "$imagename" #mount the image to the created directory sudo mount -o loop "$I" "$imagename" completed=1 fi if [ ! $completed -eq 1 ] then cecho "red" $"error nothing completed, exit in 30 seconds without success" sleep 30 exit 1 fi if [ $? -eq 1 ] then cecho "red" $"error mounting, exit in 30 seconds without success" sleep 30 exit 1 fi cecho "green" $"completed with:" echo "$file" done cecho "green" "---------------" echo $"done, closing after 3 seconds" sleep 3 exit