This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Original code from http://l0b0.wordpress.com/2008/03/15/iso-mount-scr…
- Loading branch information
0 parents
commit 5c99505
Showing
2 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/bin/sh | ||
# | ||
# NAME | ||
# mountiso.sh - Mount ISO files in Nautilus or the shell | ||
# | ||
# SYNOPSIS | ||
# mountiso.sh [filenames] | ||
# | ||
# DESCRIPTION | ||
# Copy script to ~/.gnome2/nautilus-scripts/ and either: | ||
# - right-click one / several ISO files and select Scripts -> mountiso.sh | ||
# - run it in a shell as described above | ||
# | ||
# In addition to mounting the ISO files, it will create a symlink from | ||
# /path/to/iso (without file extension) to the mount point, for easy access. | ||
# | ||
# COPYRIGHT AND LICENSE | ||
# Copyright (C) 2008-2010 Victor Engmark | ||
# | ||
# 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 3 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, see <http://www.gnu.org/licenses/>. | ||
# | ||
################################################################################ | ||
|
||
ifs_original=$IFS # Reset when done | ||
IFS=' | ||
' # Make sure paths with spaces don't make any trouble when looping | ||
|
||
PATH='/usr/bin:/bin' | ||
cmdname=$(basename $0) | ||
description='ISO Mounter' | ||
|
||
mount_dir='/media' | ||
|
||
# Exit codes from /usr/include/sysexits.h, as recommended by | ||
# http://www.faqs.org/docs/abs/HTML/exitcodes.html | ||
EX_OK=0 # successful termination | ||
EX_SOFTWARE=70 # internal software error | ||
EX_CANTCREAT=73 # can't create (user) output file | ||
|
||
# Custom errors | ||
EX_UNKNOWN=1 | ||
|
||
error() | ||
{ | ||
if [ -z "$2" ] | ||
then | ||
error_code=$EX_UNKNOWN | ||
else | ||
error_code=$2 | ||
fi | ||
zenity --error --title $description --text $1 | ||
exit $error_code | ||
} | ||
|
||
warning() | ||
{ | ||
zenity --warning --title $description --text $1 | ||
} | ||
|
||
for iso_path in $* | ||
do | ||
# Check the file type before continuing | ||
if [ -z "$(file -b $iso_path | grep 'ISO 9660\|UDF filesystem')" ] | ||
then | ||
warning "'${iso_path}' appears not to be an ISO file. Skipping." | ||
continue | ||
fi | ||
|
||
iso_filename=$(basename $iso_path) | ||
iso_mount_path=${mount_dir}/${iso_filename} | ||
|
||
# Create mount directory | ||
if [ ! -d $iso_mount_path ] | ||
then | ||
gksudo --description $description -- mkdir -p $iso_mount_path || \ | ||
error "Couldn't create mount directory '${iso_mount_path}'." $EX_CANTCREAT | ||
fi | ||
|
||
# Skip if the file is already mounted | ||
if [ $(ls -A $iso_mount_path | wc -l) -ne 0 ] | ||
then | ||
warning "'${iso_path}' is already mounted at '${iso_mount_path}'." | ||
continue | ||
fi | ||
|
||
# Mount file | ||
gksudo --description $description -- mount -o loop -t iso9660 $iso_path $iso_mount_path || \ | ||
error "Couldn't mount ISO file '${iso_path}' at '${iso_mount_path}'." $EX_SOFTWARE | ||
|
||
# Create shortcut from the ISO location | ||
link_path=$(dirname $iso_path)/${iso_filename%.*} | ||
if [ ! -e $link_path ] | ||
then | ||
gksudo --description $description -- ln -s $iso_mount_path $link_path || \ | ||
error "Couldn't create symbolic link '${link_path}'." $EX_CANTCREAT | ||
fi | ||
done | ||
|
||
# Cleanup | ||
IFS=$ifs_original |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/bin/sh | ||
# | ||
# NAME | ||
# unmountiso.sh - Unmount ISO files in Nautilus or the shell | ||
# | ||
# SYNOPSIS | ||
# unmountiso.sh [filenames] | ||
# | ||
# DESCRIPTION | ||
# Copy script to ~/.gnome2/nautilus-scripts/ and either: | ||
# - right-click one / several ISO files and select Scripts -> unmountiso.sh | ||
# - run it in a shell as described above | ||
# | ||
# See mountiso.sh for more information. | ||
# | ||
# COPYRIGHT AND LICENSE | ||
# Copyright (C) 2008-2010 Victor Engmark | ||
# | ||
# 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 3 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, see <http://www.gnu.org/licenses/>. | ||
# | ||
################################################################################ | ||
|
||
ifs_original="$IFS" # Reset when done | ||
IFS=' | ||
' # Make sure paths with spaces don't make any trouble when looping | ||
|
||
PATH='/usr/bin:/bin' | ||
cmdname=$(basename $0) | ||
description='ISO Mounter' | ||
|
||
mount_dir='/media' | ||
|
||
# Exit codes from /usr/include/sysexits.h, as recommended by | ||
# http://www.faqs.org/docs/abs/HTML/exitcodes.html | ||
EX_OK=0 # successful termination | ||
EX_OSERR=71 # system error (e.g., can't fork) | ||
|
||
# Custom errors | ||
EX_UNKNOWN=1 | ||
|
||
error() | ||
{ | ||
if [ -z "$2" ] | ||
then | ||
error_code=$EX_UNKNOWN | ||
else | ||
error_code=$2 | ||
fi | ||
zenity --error --title "$description" --text "$1" | ||
exit $error_code | ||
} | ||
|
||
warning() | ||
{ | ||
zenity --warning --title "$description" --text "$1" | ||
} | ||
|
||
for iso_path in $* | ||
do | ||
# Check the file type before continuing | ||
if [ -z "$(file -b $iso_path | grep 'ISO 9660\|UDF filesystem')" ] | ||
then | ||
warning "'${iso_path}' appears not to be an ISO file. Skipping." | ||
continue | ||
fi | ||
|
||
iso_filename=$(basename $iso_path) | ||
|
||
# Remove shortcut | ||
link_path=$(dirname $iso_path)/${iso_filename%.*} | ||
if [ -L $link_path ] | ||
then | ||
gksudo --description $description -- rm $link_path || \ | ||
warning "Couldn't remove symbolic link '${link_path}'." | ||
fi | ||
|
||
# Abort if the file is already unmounted | ||
iso_mount_path=$mount_dir/${iso_filename} | ||
if [ ! -d $iso_mount_path ] | ||
then | ||
warning "'${iso_path}' is not mounted." | ||
continue | ||
fi | ||
|
||
# Unmount file | ||
gksudo --description $description -- umount $iso_mount_path || \ | ||
error "Couldn't unmount '${iso_mount_path}'." $EX_OSERR | ||
|
||
# Remove mount directory | ||
if [ -d $iso_mount_path ] | ||
then | ||
gksudo --description $description -- rmdir $iso_mount_path || \ | ||
warning "Couldn't remove mount directory '${iso_mount_path}'." | ||
fi | ||
done | ||
|
||
# Cleanup | ||
IFS=$ifs_original |