CD Images mit einem Skript einbinden


CDs werden über das sogenannte Loopback-Device eingebunden. Mit diesem Skript wird es ganz komfortabel ohne die Mount-Paramenter erledigt.

Quelltext: bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
 
# (c) 2006 by Julian Fleischer aka Warhog
# License: GPLv2 (See http://www.gnu.org/licenses/gpl.html)
# visit http://www.warhog.info/
 
# CDs werden ueber das sogenannte loopback-Device eingebunden. Mit diesem Skript wird es ganz komfortabel
# ohne die mount-Paramenter erledigt.
# Usage:
# ohne Parameter:                                 gibt die eingehaengten Devices aus.
# mountiso  []            bindet das Image am angegebenen Punkt(optional) ein.
# mountiso -d         speichert einen neuen Default mountpoint in /etc/mountiso.default
# mountiso -c                                     loescht /etc/mountiso.default
# mountiso -u                unmount des Images
 
 
mountiso_version="2006-10-18"
mountiso_cfg_file="/etc/mountiso.default"
mountiso_default_mountpoint="/media/cdrom0"
 
do_mount()
{
  if [ ! -e $1 ]; then
    echo "Image file not found, aborting."
  else
    if [ "$2" == "ro" ]; then
      param="-r "
    fi
    mount $param -o loop -t iso9660 "$1" "$where"
  fi
}
 
show_help()
{
  echo "mountiso [-w]  []"
  echo " mounts an iso9660-image  to mountpoint ."
  echo "If no mountpoint is specified, $default_mountpoint will be assumed."
  echo "If no arguments are given, all mounted iso9660 images will be listed."
  echo " Options:"
  echo "  -w, --writable  boot the image writable, default is readonly"
  echo " Alternatives:"
  echo "  -u       unmounts the image at "
  echo "  -d, --default   print the default mount point"
  echo "  -d       set the default mount point to "
  echo "  -c, --clean     remove the configuration-file (if there is any)"
  echo "  -v, --version   print version information"
  echo "  -h, --help      show this message"
}
 
read_config()
{
  default_mountpoint=$mountiso_default_mountpoint
  if [ -e "$mountiso_cfg_file" ]; then
    default_mountpoint="`cat $mountiso_cfg_file`"
  fi
 
  where="$1"
  if [ ! -e "$where" ]; then
    where="$default_mountpoint"
  fi
}
 
save_config()
{
  echo "$1" > "$mountiso_cfg_file"
}
 
do_execute()
{
  read_config "$2"
 
  case $1 in
  "")
    mount | grep iso9660
  ;;
 
  "--help"|"-h")
    show_help
  ;;
 
  "-v"|"--version")
    echo $mountiso_version
  ;;
 
  "-d"|"--default")
    if [ "$2" == "" ]; then
      echo $default_mountpoint
    else
      default_mountpoint="$2";
      save_config "$default_mountpoint"
    fi
  ;;
 
  "-u"|"--umount"|"--unmount")
    umount "$where"
  ;;
 
  "-c"|"--clean")
    unlink "$mountiso_cfg_file"
  ;;
 
  "-w"|"--writable"|"--writeable")
    read_config "$3"
    do_mount "$2" rw
  ;;
 
  *)
    do_mount "$1" ro
  ;;
 
  esac
 
}
 
do_execute "$1" "$2" "$3"
Erstellt von gravedigga am 23.01.2008 um 19:15:02.
Zuletzt bearbeitet von Redaktion am 07.10.2008 um 10:16:38.
Schlagworte: Script, mounten, loopback, CD, Bash

Kommentare

Keine Kommentare vorhanden.