Dmitry V. Levin | 868a666 | 2015-01-15 17:01:32 +0000 | [diff] [blame] | 1 | #!/bin/sh -ex |
Denys Vlasenko | 6acf586 | 2012-03-18 23:27:23 +0100 | [diff] [blame] | 2 | |
Dmitry V. Levin | 868a666 | 2015-01-15 17:01:32 +0000 | [diff] [blame] | 3 | mountpoint -q / |
| 4 | [ ! -e hdc.img.dir ] |
Denys Vlasenko | 6acf586 | 2012-03-18 23:27:23 +0100 | [diff] [blame] | 5 | |
Dmitry V. Levin | 868a666 | 2015-01-15 17:01:32 +0000 | [diff] [blame] | 6 | cleanup() |
| 7 | { |
| 8 | trap - EXIT |
| 9 | if mountpoint -q hdc.img.dir; then |
| 10 | umount -d hdc.img.dir |
| 11 | fi |
| 12 | mountpoint -q hdc.img.dir || |
| 13 | rm -rf hdc.img.dir |
| 14 | exit $@ |
| 15 | } |
Denys Vlasenko | 6acf586 | 2012-03-18 23:27:23 +0100 | [diff] [blame] | 16 | |
Dmitry V. Levin | 868a666 | 2015-01-15 17:01:32 +0000 | [diff] [blame] | 17 | trap 'cleanup $?' EXIT |
| 18 | trap 'cleanup 1' HUP PIPE INT QUIT TERM |
| 19 | |
| 20 | size=$(du -ks hdc.dir | sed -rn 's/^([0-9]+).*/\1/p') |
| 21 | [ "$size" -gt 0 ] |
| 22 | |
| 23 | rm -f hdc.img |
| 24 | dd if=/dev/zero of=hdc.img count=1 bs=1024 seek=$(($size*2)) |
| 25 | mkfs.ext3 -q -F -b 1024 -i 4096 hdc.img |
| 26 | tune2fs -c 0 -i 0 hdc.img |
| 27 | mkdir hdc.img.dir |
| 28 | mount -o loop hdc.img hdc.img.dir |
| 29 | cp -a hdc.dir/* hdc.img.dir/ |
| 30 | umount -d hdc.img.dir |