This repository has been archived by the owner on Dec 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathredump.sh
executable file
·93 lines (93 loc) · 3.79 KB
/
redump.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
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
#!/usr/bin/env bash
#
# The purposes of redump is to DiskDump each IMG file listed in every disk manifest to a temporary JSON file,
# then DiskDump that back into a temporary IMG file, then hexdump both the original IMG and temporary IMG files,
# diff the dumps, and save the differences in the current log file. Then we want to mount the temporary IMG file
# (which should normally be possible, since we used --forceBPB to create the temporary JSON) and dump all the files
# into an archived subfolder.
#
# After all that, we're ready to delete the temporary JSON and IMG files, as well as the hexdumps, and then redump
# the original JSON file and update the manifest with a list of all the files contained in the corresponding archived
# subfolder.
#
# redump.sh accepts two arguments:
#
# $1 is the directory to search for manifests containing disk images (eg, "."); this is a required argument
# $2 is an optional DiskDump argument (eg, "--forceBPB" if you're sure the boot sector(s) can be safely modified)
#
if [ -z "$1" ]; then
echo "no directory specified"
exit 1
fi
if [ ! -d "$1" ]; then
echo "directory $1 does not exist"
exit 1
fi
log=/Users/Jeff/Sites/pcjs/disks/pcx86/redump.log
find -L $1 -name "manifest.xml" -exec grep -H -e "<disk.*img=" {} \; | sed -E "s/^([^:]*)\/manifest\.xml:.*img=\"([^\"]*)\".*href=\"([^\"]*)\".*/\1;\2;\3/" > disks.lst
while read line; do
dirManifest=`echo ${line} | sed -E "s/;.*//"`
imgFile=`echo ${line} | sed -E "s/.*;(.*);.*/\1/"`
jsonFile=$(basename `echo ${line} | sed -E "s/.*;.*;(.*)/\1/"`)
img="${dirManifest}/${imgFile}"
dir=$(dirname "${img}")
name=$(basename "${img}" ".img")
# log=${dir}/${name}.log
jsonTmp="${dir}/${name}.json"
if [ -f "${jsonTmp}" ]; then
rm "${jsonTmp}"
fi
echo diskdump --disk="${img}" --format=json --output="${jsonTmp}" --forceBPB >> ${log}
node ~/Sites/pcjs/modules/diskdump/bin/diskdump --disk="${img}" --format=json --output="${jsonTmp}" --forceBPB >> ${log}
if [ ! -f "${jsonTmp}" ]; then
echo "WARNING: diskdump failed to create ${jsonTmp}"
continue
fi
imgTmp="${dir}/${name}-TMP.img"
if [ -f "${imgTmp}" ]; then
chmod +w "${imgTmp}"
rm "${imgTmp}"
fi
echo diskdump --disk="${jsonTmp}" --format=img --output="${imgTmp}" >> ${log}
node ~/Sites/pcjs/modules/diskdump/bin/diskdump --disk="${jsonTmp}" --format=img --output="${imgTmp}" >> ${log}
if [ ! -f "${imgTmp}" ]; then
echo "WARNING: diskdump failed to create ${imgTmp}"
break
fi
chmod oga-w "${imgTmp}"
hexdump -C "${img}" > "${dir}/${name}.txt"
hexdump -C "${imgTmp}" > "${dir}/${name}-TMP.txt"
echo diff "${img}" "${imgTmp}" >> ${log}
diff "${dir}/${name}.txt" "${dir}/${name}-TMP.txt" >> ${log}
rm "${dir}/${name}.txt" "${dir}/${name}-TMP.txt"
dirDisk="${dir}/${name}"
if [ -d "${dirDisk}" ]; then
chflags -R nouchg,nohidden "${dirDisk}"
rm -rf "${dirDisk}"
fi
# echo "mounting "${imgTmp}"..."
hdiutil mount "$imgTmp" > disk
if grep -q -e "^/dev" disk; then
echo "mounted $imgTmp"
vol=`grep -o -e "/Volumes/.*" disk`
# subdir=`echo "$vol" | grep -o -e "[^/]*$"`
# subdir=`echo "$img" | grep -o -e "[^/]*$" | sed -E "s/(.*)\.img/\1/"`
# echo cp -Rpv "$vol/" "$dirDisk"
cp -Rp "$vol/" "$dirDisk"
# chmod -R go-w "$dirDisk"
hdiutil unmount "$vol" > /dev/null
# echo "unmounted $imgTmp"
else
echo "WARNING: unable to mount $imgTmp"
break
fi
chmod +w "${imgTmp}"
rm disk "${imgTmp}" "${jsonTmp}"
pushd ${dirManifest} > /dev/null
imgFile=`echo ${imgFile} | sed -E "s/^\.\///"`
jsonFile=`echo ${imgFile} | sed -E "s/(.*)(archive|private).*/\1/"`${jsonFile}
echo diskdump --disk="${imgFile}" --format=json --output="${jsonFile}" --overwrite --manifest $2 >> ${log}
node ~/Sites/pcjs/modules/diskdump/bin/diskdump --disk="${imgFile}" --format=json --output="${jsonFile}" --overwrite --manifest $2 | tee -a ${log}
popd > /dev/null
done < disks.lst
rm disks.lst