1 |
sng |
84 |
#!/bin/bash |
2 |
|
|
version=3.1.0 |
3 |
|
|
############################################################################## |
4 |
|
|
# # |
5 |
|
|
# continue-multi-cd, (C) 2007-2010 S. Georgaras <sng@hellug.gr> # |
6 |
|
|
# # |
7 |
|
|
# This file is part of Clonezilla-SysRescCD. # |
8 |
|
|
# # |
9 |
|
|
# Clonezilla-SysRescCD is free software: you can redistribute it and/or # |
10 |
|
|
# modify it under the terms of the GNU General Public License as published # |
11 |
|
|
# by the Free Software Foundation, either version 2 of the License, or # |
12 |
|
|
# (at your option) any later version. # |
13 |
|
|
# # |
14 |
|
|
# Clonezilla-SysRescCD is distributed in the hope that it will be useful, # |
15 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
16 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
17 |
|
|
# GNU General Public License for more details. # |
18 |
|
|
# # |
19 |
|
|
# You should have received a copy of the GNU General Public License along # |
20 |
|
|
# with Clonezilla-SysRescCD. If not, see <http://www.gnu.org/licenses/>. # |
21 |
|
|
# # |
22 |
|
|
############################################################################## |
23 |
|
|
|
24 |
|
|
function printVersion(){ |
25 |
sng |
105 |
echo "$(basename "$0") - v $version - S. Georgaras <sng@hellug.gr>" |
26 |
sng |
84 |
} |
27 |
|
|
|
28 |
|
|
function usage(){ |
29 |
|
|
printVersion |
30 |
|
|
echo |
31 |
|
|
echo "Usage: $(basename "$0") [options] <path to be added to CD>" |
32 |
|
|
echo |
33 |
|
|
echo "Available options are: |
34 |
|
|
d Specify write device (in case auto detection does not work) |
35 |
|
|
c Close the CD. No more burning will be possible |
36 |
|
|
Default is to leave it open |
37 |
|
|
l Don't burn the CD after image creation |
38 |
|
|
o <image name> Save the image file as <image name> |
39 |
|
|
r Remove the image file after burning |
40 |
|
|
f On the fly burning of the CD. No image file will be created |
41 |
|
|
v Print version info and exit |
42 |
|
|
h Print this screen and exit |
43 |
|
|
" |
44 |
|
|
|
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
function findCDRECORD(){ |
48 |
|
|
[ -z $(which cdrecord 2>/dev/null) ] && { |
49 |
|
|
echo "Error: cdrecord not found!!!" |
50 |
|
|
exit 1 |
51 |
|
|
} |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
function findMKISOFS(){ |
55 |
|
|
[ -z $(which mkisofs 2>/dev/null) ] && { |
56 |
|
|
echo "Error: mkisofs not found!!!" |
57 |
|
|
exit 1 |
58 |
|
|
} |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
function longHelp(){ |
62 |
|
|
echo longHelp |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
|
66 |
|
|
# while [ ! -z "$1" ];do |
67 |
|
|
# case "$1" in |
68 |
|
|
# --long-help) longHelp |
69 |
|
|
# shift |
70 |
|
|
# exit;; |
71 |
|
|
# esac |
72 |
|
|
# done |
73 |
|
|
|
74 |
|
|
BURN_CD=1 |
75 |
|
|
REMOVE_IMAGE=0 |
76 |
|
|
SAVE_MULTI='-multi' |
77 |
|
|
|
78 |
|
|
while getopts fcrd:lo:hv name |
79 |
|
|
do |
80 |
|
|
case "$name" in |
81 |
|
|
f) output_mode=cdwriter;; |
82 |
|
|
d) dev="$OPTARG";; |
83 |
|
|
r) REMOVE_IMAGE=1;; |
84 |
|
|
c) SAVE_MULTI='';; |
85 |
|
|
l) BURN_CD=0;; |
86 |
|
|
o) img="$OPTARG" |
87 |
|
|
;; |
88 |
|
|
h) usage |
89 |
|
|
exit;; |
90 |
|
|
v) printVersion |
91 |
|
|
exit;; |
92 |
|
|
*) exit;; |
93 |
|
|
esac |
94 |
|
|
done |
95 |
|
|
shift $(($OPTIND - 1)) |
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
[ -z "$1" ] && { |
100 |
|
|
usage |
101 |
|
|
echo "Error: <path to be added to CD> not specified!!!" |
102 |
|
|
exit 1 |
103 |
|
|
} |
104 |
|
|
[ ! -d "$1" ]&& { |
105 |
|
|
usage |
106 |
|
|
echo "Error: <path to be added to CD> is not a directory!!!" |
107 |
|
|
exit 1 |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
pathToAdd="$1" |
111 |
|
|
|
112 |
|
|
[ -d "$img" ] && { |
113 |
|
|
usage |
114 |
|
|
echo "Error: <image name> is a directory!!!" |
115 |
|
|
exit 1 |
116 |
|
|
} |
117 |
|
|
[ -e "$img" ] && { |
118 |
|
|
usage |
119 |
|
|
echo "Error: <image name> already exists!!!" |
120 |
|
|
exit 1 |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
[ ! -w $(dirname "$img") ] && { |
124 |
|
|
usage |
125 |
|
|
echo "Error: No write permission for <image name>!!!" |
126 |
|
|
exit 1 |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
[ -z $(echo "$img" | grep "$pathToAdd") ] || { |
130 |
|
|
usage |
131 |
|
|
echo "Error: <image name> cannot be under <path to be added to CD>!!!" |
132 |
|
|
exit 1 |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
findMKISOFS |
136 |
|
|
if [ $BURN_CD -eq 1 ];then findCDRECORD;fi |
137 |
|
|
|
138 |
|
|
|
139 |
|
|
if [ -z "$dev" ];then |
140 |
|
|
theCD=$(what-cd -wb 2>/dev/null) |
141 |
|
|
# theCD=/dev/hda |
142 |
|
|
else |
143 |
|
|
theCD="$dev" |
144 |
|
|
fi |
145 |
|
|
|
146 |
|
|
|
147 |
|
|
[ -z "$theCD" ] && { |
148 |
|
|
echo " Error: Cannot determine your CD writer!!!" |
149 |
|
|
exit 1 |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
|
153 |
|
|
[ -z "$(mount |grep "$theCD")" ] || { |
154 |
|
|
umount "$theCD" || { |
155 |
|
|
echo |
156 |
|
|
echo |
157 |
|
|
echo " Error: Your CD writer cannot be unmounted!!!" |
158 |
|
|
exit 1 |
159 |
|
|
} |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
cont=$(cdrecord -msinfo dev="$theCD" 2>/dev/null) |
163 |
|
|
[ -z "$cont" ] && { |
164 |
|
|
echo " Error: The media in $theCD is not a CD/RW!!!" |
165 |
|
|
exit 1 |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
[ -z "$img" ] && img="/tmp/multi-session-cd-$$.iso" |
169 |
|
|
|
170 |
|
|
mkisofs -r -J -l -f -M "$theCD" -C "$cont" "$pathToAdd" | \ |
171 |
|
|
{ |
172 |
|
|
case "$output_mode" in |
173 |
|
|
"cdwriter") |
174 |
|
|
cdrecord -v "$SAVE_MULTI" driveropts=burnfree -data -eject dev="$theCD" - |
175 |
|
|
exit |
176 |
|
|
;; |
177 |
|
|
*) |
178 |
|
|
# use /dev/stdout as the bridge |
179 |
|
|
cat - > "$img" && { |
180 |
|
|
# set -x |
181 |
|
|
if [ "$BURN_CD" -eq 1 ];then |
182 |
|
|
cdrecord -v "$SAVE_MULTI" driveropts=burnfree -data -eject dev="$theCD" "$img" && { |
183 |
|
|
if [ "$REMOVE_IMAGE" -eq 0 ];then |
184 |
|
|
echo |
185 |
|
|
echo |
186 |
|
|
echo " The image file has been saved as: $img" |
187 |
|
|
else |
188 |
|
|
rm -r "$img" |
189 |
|
|
fi |
190 |
|
|
} |
191 |
|
|
else |
192 |
|
|
echo |
193 |
|
|
echo |
194 |
|
|
echo " The image file has been saved as: $img" |
195 |
|
|
fi |
196 |
|
|
} || { |
197 |
|
|
printVersion |
198 |
|
|
echo |
199 |
|
|
echo " Error: Image file creation failed!!!" |
200 |
|
|
exit 1 |
201 |
|
|
} |
202 |
|
|
;; |
203 |
|
|
esac |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
# echo "Data to continue: $cont" |
220 |
|
|
# echo "img=$img" |