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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#!/bin/bash
usage() {
cat << EOF
Usage: $0 [OPTIONS]...
Dumping Mac files into MacBinary format
There are 2 operation modes. Direct MacBinary encoding (Mac-only) and dumping ISO
contents with hfsutils.
Mode 1:
$0 macbinary
Operate in MacBinary encoding mode
Mode 2:
$0 <file.iso>
Operate in disk dumping mode
Miscellaneous:
-h, --help display this help and exit
EOF
}
path=
macbinarydump() {
mypath=`realpath $0`
for i in *
do
if test -d "$i" ; then
cd "$i"
if [ "$(ls -A .)" ] ; then # directory is not empty
bash $mypath macbinary-phase2 "$path/$i"
fi
cd ..
else
echo -ne "$path/$i... \r"
macbinary encode "$i"
touch -r "$i" "$i.bin"
mv "$i.bin" "$i"
fi
done
}
hfsdump() {
IFS=$'\n'
mypath=`realpath $0`
for i in `hls -F1a`
do
if [[ "$i" =~ ":" ]] ; then
dir="${i%?}"
hcd "$dir"
mkdir "$dir"
cd "$dir"
bash $mypath hfsutils-phase2 "$path:$i"
hcd ::
cd ..
else
echo -ne "$path$i... \r"
# Executable files have star at their end. Strip it
if [[ "$i" =~ \*$ ]] ; then
file="${i%?}"
else
file="$i"
fi
fileunix="$file"
# Files count contain stars
file="${file//\*/\\*}"
hcopy -m "$file" "./$fileunix"
fi
done
}
for parm in "$@" ; do
if test "$parm" = "--help" || test "$parm" = "-help" || test "$parm" = "-h" ; then
usage
exit 0
fi
done # for parm in ...
if [[ $1 == "macbinary" ]] ; then
if test ! `type macbinary >/dev/null 2>/dev/null` ; then
echo "macbinary not found. Exiting"
exit 1
fi
macbinarydump
echo
exit 0
fi
if [[ $1 == "macbinary-phase2" ]] ; then
path=$2
macbinarydump
exit 0
fi
###########
# hfsutils mode
if [ "$#" -lt 1 ] ; then
usage
exit 1
fi
if [[ $1 == "hfsutils-phase2" ]] ; then
path=$2
hfsdump
exit 0
fi
if ! `type hmount >/dev/null 2>/dev/null` ; then
echo "hfsutils not found. Exiting"
exit 1
fi
isofile="$1"
echo -n "Mounting ISO..."
hmount "$isofile" >/dev/null 2>/dev/null
if test -z $? ; then
echo error
exit 1
fi
echo done
echo "Dumping..."
hfsdump
echo
echo -n "Unmounting ISO..."
humount >/dev/null 2>/dev/null
if test -z $? ; then
echo error
exit 1
fi
echo done
|