diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/parted-usb.sh | 81 |
1 files changed, 58 insertions, 23 deletions
diff --git a/src/parted-usb.sh b/src/parted-usb.sh index fff003c..af56c8c 100755 --- a/src/parted-usb.sh +++ b/src/parted-usb.sh | |||
@@ -234,6 +234,38 @@ boot_vm() | |||
234 | -drive file="$installer_target",format=raw | 234 | -drive file="$installer_target",format=raw |
235 | } | 235 | } |
236 | 236 | ||
237 | do_build() | ||
238 | { | ||
239 | if [ -b "$target" ] | ||
240 | then | ||
241 | globalize | ||
242 | individualize | ||
243 | release_target_block_devices | ||
244 | elif [ -f "$target" -o ! -e "$target" ] | ||
245 | then | ||
246 | template=${target%.img}.template.img | ||
247 | final=$target | ||
248 | ( | ||
249 | target=$target.tmp | ||
250 | if [ ! -e "$template" ] | ||
251 | then | ||
252 | target="$template".tmp globalize | ||
253 | release_target_block_devices | ||
254 | mv -T "$template".tmp "$template" | ||
255 | fi | ||
256 | |||
257 | cp -T --reflink=always "$template" "$target" | ||
258 | acquire_target_block_devices | ||
259 | individualize | ||
260 | release_target_block_devices | ||
261 | |||
262 | mv -T "$target" "$final" | ||
263 | ) | ||
264 | else | ||
265 | die "Target must be a file or block device." | ||
266 | fi | ||
267 | } | ||
268 | |||
237 | . samizdat-paths.sh || die 'samizdat-paths.sh not found' | 269 | . samizdat-paths.sh || die 'samizdat-paths.sh not found' |
238 | samizdat_linux_dir=/ | 270 | samizdat_linux_dir=/ |
239 | 271 | ||
@@ -270,33 +302,36 @@ fi | |||
270 | sanity_checks | 302 | sanity_checks |
271 | set -e | 303 | set -e |
272 | 304 | ||
273 | if [ "$1" = boot ] | 305 | if [ "$1" = -n ] |
274 | then | ||
275 | boot_vm boot-disk.img | ||
276 | elif [ "$1" ] | ||
277 | then | 306 | then |
278 | [ -b "$1" ] || die "Not a block device: $1" | 307 | shift |
279 | target=$1 | 308 | DO_BUILD= |
280 | globalize | ||
281 | individualize | ||
282 | release_target_block_devices | ||
283 | else | 309 | else |
284 | template=boot-disk.template.img | 310 | DO_BUILD=y |
285 | if [ ! -e "$template" ] | 311 | fi |
312 | |||
313 | default_target=boot-disk.img | ||
314 | |||
315 | if [ "$1" ] | ||
316 | then | ||
317 | |||
318 | if [ "$1" = USB ] | ||
286 | then | 319 | then |
287 | target="$template".tmp globalize | 320 | target=$(./src/usb.sh) || exit 1 |
288 | release_target_block_devices | 321 | elif [ -f "$1" ] |
289 | mv -T "$template".tmp "$template" | 322 | then |
323 | case "$1" in | ||
324 | *.img) ;; | ||
325 | *) die "Invalid image filename. Use *.img";; | ||
326 | esac | ||
290 | fi | 327 | fi |
328 | target=$1 | ||
329 | else | ||
330 | target=$default_target | ||
331 | fi | ||
291 | 332 | ||
292 | target=boot-disk.img.tmp | 333 | if [ "$DO_BUILD" ] |
293 | cp -T --reflink=always "$template" "$target" | 334 | then |
294 | acquire_target_block_devices | 335 | do_build |
295 | individualize | ||
296 | release_target_block_devices | ||
297 | |||
298 | final=${target%.tmp} | ||
299 | mv -T "$target" "$final" | ||
300 | target=$final | ||
301 | fi | 336 | fi |
302 | boot_vm "$target" | 337 | boot_vm "$target" |