-
Notifications
You must be signed in to change notification settings - Fork 11
/
cdrwmgr5.ksh
370 lines (317 loc) · 7.97 KB
/
cdrwmgr5.ksh
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#!/bin/ksh
# Add for debug mode -x
#######################################################################
# Program: cdrwmgr.sh
# Author: Greg Kranz
# Date: 05/11/2001
# Version: 1.0
# Purpose: This script helps manage the imaging and burning
# of data (ONLY!) CDRWs. If you have a large quantity
# to make, it loops you thru it. The resulting CDs are
# readable on Unix systems, and NT but not Windows 3.1,
# 95, or 98. Basically full support for long file names
# is required.
#
# It can be used to make copies of data CDs. CDRW supports
# this capability directly but it is extremely slow. It is
# 20x faster to image the CD, then burn the CDRW.
#
# It does not check for disk space issues. A little du -sk
# action could fix this but it will add time.
#
#
# Notes: cdrw can make audio CDs but this script is not set up for it.
# ksh was used so I could use the select function.
#
#
#
#
#
#
#######################################################################
# Change history:
#
# Verion Date Name Change
# 1.0 051101 PGK First cut
# 1.1 040202 PGK Switch from .img to the standard .iso for file names
#
#
#
#
#######################################################################
#
# Setup initial variables
#------------------------ Functions ----------------------------------
make_image()
{
while true
do
#
# Get a name to use as the author of the CD
#
echo
echo " Enter your name (${oldusername}): \c"
read username
# Store the input for reuse later
if [ -z "${username}" ]; then
username=${oldusername}
else
oldusername=${username}
fi
#
if [ "${username}" = "q" ]; then
return
fi
#
if [ "X${username}" = "X" ]; then
echo "Error: You must enter a name."
else
break
fi
done
while true
do
#
# Get the system name to use as the origin of the CD
#
echo
echo " Enter the system name where the data originated (${oldsysname}): \c"
read sysname
# Store the input for reuse later
if [ -z "${sysname}" ]; then
username=${oldsysname}
else
oldsysname=${sysname}
fi
#
if [ "${sysname}" = "q" ]; then
return
fi
#
if [ "X${sysname}" = "X" ]; then
echo "Error: You must enter a system name."
else
break
fi
done
while true
do
#
#
echo
echo " Enter the path to the parent directory (${oldbulkpath}): \c"
read bulkpath
# Store the input for reuse later
if [ -z "${bulkpath}" ]; then
bulkpath=${oldbulkpath}
else
oldbulkpath=${bulkpath}
fi
#
if [ "${bulkpath}" = "q" ]; then
return
fi
#
if [ "X${bulkpath}" = "X" ]; then
echo "Error: You must enter a directory name."
else
if [ -d ${bulkpath} ]; then
break
else
echo "Error: ${bulkpath} does not exist"
fi
fi
done
LIST="quit all `ls -1 ${bulkpath} | grep -v lost+found`"
PS3="Select a directory to image or 1 to quit or 2 for ALL (${oldname}): "
select NAME in $LIST ; do
case "$NAME" in
quit ) return ;;
QUIT ) $NAME=quit
return ;;
all ) break ;;
ALL ) $NAME=all
break ;;
* ) if [ -z "${NAME}" ]; then
NAME=${oldname}
else
oldname=${NAME}
fi
echo "$NAME selected."
break ;;
esac
done
while true
do
#
#
# Where should the image file be create (ie written)
echo
echo "Enter the directory name where the image file will be written (${oldimagepath}): \c"
read imagepath
# Store the input for reuse later
if [ -z "${imagepath}" ]; then
imagepath=${oldimagepath}
else
oldimagepath=${imagepath}
fi
if [ -d ${imagepath} ]; then
break
else
echo "Error: ${imagepath} does not exist"
return
fi
done
if [ ${NAME} = "all" ]; then
echo "*** Runing in LOOP mode: all subdirectories will be imaged."
#
# running in loop mode.
#
for each_name in `ls -1 ${bulkpath} | grep -v lost+found`
do
echo "Create image of: ${bulkpath}/${each_name}"
mkisofs -A "${each_name}" -P "Tyco Electronics Inc, Copywrite Protected" \
-l -r -d -L -p "${username}" -sysid "${sysname}" -V "${each_name}" \
-o ${imagepath}/${each_name}.iso ${bulkpath}/${each_name}
done
else
echo
echo "Creating cdrw image file. This will take a while (5-10 min)."
echo "Warning: Up to 650 MB of disk could be consumed."
echo "Create image of: ${bulkpath}/${NAME}"
echo "Image file name: ${imagepath}/${NAME}.iso"
echo "Imaging command used: mkisofs -A ${NAME}"
echo " -P Tyco Electronics Inc, Copy Write Protected"
echo " -l -r -d -L -p ${username} -sysid ${sysname} -V ${NAME}"
echo " -o ${imagepath}/${NAME}.iso ${bulkpath}/${NAME}"
echo
mkisofs -A "${NAME}" -P "Tyco Electronics Inc, Copy Write Protected" \
-l -r -d -L -p "${username}" -sysid "${sysname}" -V "${NAME}" \
-o ${imagepath}/${NAME}.iso ${bulkpath}/${NAME}
fi
}
# -----------------------------------------------------------------
burn_prep ()
{
while true
do
echo
echo "Enter the directory name (${oldimagepath}) or q for quit: \c"
read imagepath
# Store the input for reuse later
if [ -z "${imagepath}" ]; then
imagepath=${oldimagepath}
else
oldimagepath=${imagepath}
fi
#
if [ "${imagepath}" = "q" ]; then
return
fi
#
if [ -d ${imagepath} ]; then
break
else
echo "Error: ${imagepath} does not exist"
fi
done
#
# What device will we be using
while true
do
echo
cdrw -l
echo
echo "Enter the device name as shown above (${olddevice}) or q for quit: \c"
read device
# Store the input for reuse later
if [ -z "${device}" ]; then
device=${olddevice}
else
olddevice=${device}
fi
#
if [ "${device}" = "q" ]; then
return
fi
#
devexists=`ls -1 ${device} | wc -l`
if [ "${devexists}" -ne "0" ]; then
break
else
echo "Error: device ${device} does not exist"
fi
done
burn_image
}
# -----------------------------------------------------------------
burn_image ()
{
# All the error checking was done in burn_prep, so just do it.
orghome=`pwd`
cd ${imagepath}
# This while-do is here just so we can get the menu redisplayed the
# second time thru the loop (select-do-case).
while true
do
PS3="Enter image selection number or 1 to quit (${oldimagename}): "
select imagename in quit `ls -1 *.iso` ; do
case "${imagename}" in
quit ) cd ${orghome}
return ;;
* ) if [ -f ${imagename} ]; then
# Store the input for reuse later
if [ -z "${imagename}" ]; then
imagename=${oldimagename}
else
oldimagename=${imagename}
fi
#
echo
echo "Burning cdrw image ${imagepath}/${imagename}"
echo " to device ${device}. This will take a while (5-10 min)."
echo
cdrw -d ${device} -i ${imagename}
eject ${device}
else
echo "Unknown error."
cd ${orghome}
return
fi
echo "CD burn of image ${imagename} completed."
break ;;
esac
done
done
}
#------------------------ Main ----------------------------------
while true
do
#
# Display menu
#
echo "
Select a task:
1) Create an image file
2) Burn an image to CD
3) Exit
Selection: \c"
read choice
case "$choice" in
1) make_image ;;
2) burn_prep;;
3) exit 0;;
*) echo "Bad selection\007";;
esac
done
##############################################################################
### This script is submitted to BigAdmin by a user of the BigAdmin community.
### Sun Microsystems, Inc. is not responsible for the
### contents or the code enclosed.
###
###
### Copyright 2006 Sun Microsystems, Inc. ALL RIGHTS RESERVED
### Use of this software is authorized pursuant to the
### terms of the license found at
### http://www.sun.com/bigadmin/common/berkeley_license.html
##############################################################################