-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze_images.sh
executable file
·56 lines (44 loc) · 1.48 KB
/
analyze_images.sh
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
#!/bin/sh
set -x
set -e
visualize_image () {
image_path="$1"
block_size=512
floppy_size=`expr $block_size '*' 2 '*' 1440`
image_width=$block_size
image_height=`expr $floppy_size / $image_width`
PAD_PATH=`mktemp -t --suffix=.img padded.XXX`
cp "$image_path" "$PAD_PATH"
chmod +w "$PAD_PATH"
truncate -s $floppy_size "$PAD_PATH"
convert -verbose -size ${image_width}x${image_height} -depth 8 gray:"$PAD_PATH" "${image_basename}/${image_basename}.gray.png"
}
extract_image_files () {
image_path="$1"
mount_options="loop,ro,nosuid,nodev,relatime,uid=$(id -u),gid=$(id -g),fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2"
mount_dir=`mktemp -t -d floppy.XXX`
sudo mount -t vfat -o "$mount_options" "$image_path" "$mount_dir" || return 0
cp -r "$mount_dir" "$image_basename/fat"
sudo umount "$mount_dir"
rmdir "$mount_dir"
}
run_foremost () {
image_path="$1"
foremost -v -b 512 -o "$image_basename/foremost" -i "$image_path"
}
if [ $# -eq 0 ] ; then
image_paths=*.img
else
image_paths=$@
fi
for image_path in $image_paths ; do
if [ ! -f "$image_path" ] ; then
echo "$image_path not found"
continue
fi
image_basename=`basename "$image_path" .img`
if [ ! -d "$image_basename" ]; then mkdir "$image_basename" ; fi
visualize_image "$image_path"
extract_image_files "$image_path"
run_foremost "$image_path"
done