/[clonezilla-sysresccd]/trunk/create-clonezilla-sysresccd/files/what-cd
ViewVC logotype

Contents of /trunk/create-clonezilla-sysresccd/files/what-cd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (show annotations)
Thu May 20 12:12:53 2010 UTC (13 years, 10 months ago) by sng
File size: 5072 byte(s)
adding release scripts

1 #!/bin/bash
2 ###########################################################################
3 # Copyright (C) 2007-2008 by Spiros Georgaras <sng@hellug.gr> #
4 # what-cd: get info about CDs/DVDs #
5 # #
6 # This program is free software; you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation; either version 2 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program; if not, write to the #
18 # Free Software Foundation, Inc., #
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
20 ###########################################################################
21
22 versionNumber=1.0.2
23
24 function printDevice(){
25 local count=0
26 while [ ! -z "${dev[$count]}" ];do
27 if [ ${property[$count]} -eq 1 ];then
28 echo /dev/"${dev[$count]}"
29 break
30 fi
31 ((count++))
32 done
33 if [ $ejectDevice -eq 1 ];then
34 if [ $ejectDev -eq -1 ];then ejectDev=$count;fi
35 if [ ! -z "${dev[$count]}" ];then
36 eject /dev/"${dev[$ejectDev]}"
37 fi
38 fi
39 }
40
41 function printResults(){
42 # Display results
43 set -x
44 local count=0
45 while [ ! -z "${dev[$count]}" ];do
46 if [ $findWriter -eq 1 ] && [ ${property[$count]} -eq 1 ];then
47 echo -n "Device "
48 setterm -foreground magenta
49 echo -n "/dev/${dev[$count]}"
50 setterm -foreground white
51 echo -n " (id=$count) "
52 else
53 echo -n "Device /dev/${dev[$count]} (id=$count) "
54 fi
55 if [ ${property[$count]} -eq 1 ];then
56 echo -n "can "
57 if [ $findWriter -eq 1 ] && [ "$ejectDev" = "-1" ]; then
58 ejectDev=$count
59 fi
60 else
61 echo -n "can not "
62 fi
63
64 if [ $findWriter -eq 0 ];then
65 echo -n "read "
66 else
67 echo -n "write "
68 fi
69 if [ $findDVD -eq 0 ];then
70 echo "CDs"
71 else
72 echo "DVDs"
73 fi
74 ((count++))
75 done
76 if [ $ejectDevice -eq 1 ];then
77 #if [ $ejectDev -eq -1 ];then ejectDev=0;fi
78 eject /dev/"${dev[$ejectDev]}"
79 fi
80 }
81
82 function getDevices(){
83 local count=0
84 local theDevs=$(cat /proc/sys/dev/cdrom/info | grep 'drive name' |sed 's|drive name:[ \t]*||' | awk '{for(i=1;i<=NF;i++) print $i}')
85 if [ -z "$theDevs" ];then
86 echo "No CD-ROM Device found on this mashine"
87 exit 1
88 fi
89 local sortedDevs=$(echo "$theDevs" | sort)
90 if [ "$theDevs" != "$sortedDevs" ];then needsSorting=1;fi
91 for n in $(echo "$theDevs")
92 # for n in hde hdd hdc hdb
93 do
94 dev[$count]=$n
95 numOfDev=$count
96 ((count++))
97 done
98 }
99
100 function version(){
101 echo "$(basename "$0") - v $versionNumber - S. Georgaras <sng@hellug.gr>"
102 echo
103 }
104
105 function getDeviceType(){
106 local count=0
107 found=0
108
109 if [ -z "$checkType" ];then
110 property[0]=1
111 property[1]=1
112 found=2
113 else
114 for n in $(cat /proc/sys/dev/cdrom/info | grep "$checkType" |sed "s|$checkType[ \t]*||" | awk '{for(i=1;i<=NF;i++) print $i}')
115 # for n in 1 1 1 1
116 do
117 property[$count]=$n
118 if [ $n -eq 1 ];then ((found++));fi
119 ((count++))
120 done
121 fi
122 }
123
124 function help(){
125 version
126 echo "$(basename "$0") will try to identify your CD/DVDs
127 You can use it to the device name of your CD-Reader (default),
128 CD-Writer, DVD-Reader, and DVD-Writer.
129
130 Usage: $(basename "$0") [options]
131 Availabe options are:
132 d Print info about DVDs
133 w Print info about writes
134 b Batch mode. Only print one device name.
135 If more than one device is found, print
136 nothing. For use with scripts
137 e deviceID Eject device deviceID
138 Accecpable values: -1...num of devices
139 Use -1 when in batch mode
140 v Print version info and exit
141 h Print this screen and exit
142 "
143 }
144
145 #########################################
146 #
147 # Script starts here
148 #
149 #########################################
150 ejectDevice=0
151 ejectDev=-1
152 batch=0
153 findWriter=0
154 findDVD=0
155 needsSorting=0
156 while getopts ":vhe:bwd" Option
157 do
158 case $Option in
159 d)
160 findDVD=1;;
161 w)
162 findWriter=1;;
163 b)
164 batch=1;;
165 e)
166 if [ ! -z "$OPTARG" ];then
167 ejectDev="$OPTARG"
168 fi
169 ejectDevice=1;;
170 h) # show help
171 help
172 exit 0;;
173 v) # show version
174 version
175 exit 0
176 esac
177 done
178 shift $(($OPTIND - 1))
179 # set -x
180 if [ $findDVD -eq 0 ];then
181 if [ $findWriter -eq 0 ];then
182 checkType=''
183 else
184 checkType='Can write CD-R:'
185 fi
186 else
187 if [ $findWriter -eq 0 ];then
188 checkType='Can read DVD:'
189 else
190 checkType='Can write DVD-R:'
191 fi
192 fi
193 getDevices
194 getDeviceType
195 # if [ $needsSorting -eq 1 ];then echo needs sorting;fi
196 if [ $batch -eq 0 ];then
197 printResults
198 else
199 # found=''
200 if [ $found -eq 1 ];then printDevice; fi
201 fi
202
203

Properties

Name Value
svn:executable *

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26