1 | #!/bin/bash␊ |
2 | ␊ |
3 | echo "==============================================="␊ |
4 | echo "CheckFatType: Do we have FAT16 or FAT32?"␊ |
5 | echo "****************************************"␊ |
6 | ␊ |
7 | # Looks for the following in the partition boot sector␊ |
8 | # Byte number 19 to see if it's either 00 or 02␊ |
9 | # Byte number 22 to see if it's either F8 or F0␊ |
10 | # Byte number 25 to see if it's either 3F or 20␊ |
11 | #␊ |
12 | # Exit with value 1 for FAT16, 2 for FAT32 ␊ |
13 | # Exit with value 0 if nothing is found - this shouldn't happen.?␊ |
14 | ␊ |
15 | # Receives targetDeviceRaw: for example, /dev/rdisk0s2.␊ |
16 | # Receives targetVolume: Volume to install to.␊ |
17 | # Receives scriptDir: The location of the main script dir.␊ |
18 | ␊ |
19 | ␊ |
20 | if [ "$#" -eq 3 ]; then␊ |
21 | ␉targetDeviceRaw="$1"␊ |
22 | ␉targetVolume="$2"␊ |
23 | ␉scriptDir="$3"␊ |
24 | ␉echo "DEBUG: passed argument = $targetDeviceRaw"␊ |
25 | ␉echo "DEBUG: passed argument for targetVolume = $targetVolume"␊ |
26 | ␉echo "DEBUG: passed argument for scriptDir = $scriptDir"␊ |
27 | else␊ |
28 | ␉echo "Error - wrong number of values passed"␊ |
29 | ␉exit 9␊ |
30 | fi␊ |
31 | ␊ |
32 | ␊ |
33 | partitionBootSector=$( dd 2>/dev/null if="$targetDeviceRaw" count=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )␊ |
34 | if [ "${partitionBootSector:36:2}" == "00" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "3f" ]; then␊ |
35 | ␉echo "Found a FAT32 device formatted by Windows Explorer"␊ |
36 | ␉echo "--------------------------------------------------"␊ |
37 | ␉echo ""␊ |
38 | ␉"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT32 volume formatted by Windows Explorer"␊ |
39 | ␉exit 2␊ |
40 | fi␊ |
41 | if [ "${partitionBootSector:36:2}" == "02" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "3f" ]; then␊ |
42 | ␉echo "Found a FAT16 device formatted by Windows Explorer"␊ |
43 | ␉echo "--------------------------------------------------"␊ |
44 | ␉echo ""␊ |
45 | ␉"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT16 volume formatted by Windows Explorer"␊ |
46 | ␉exit 1␊ |
47 | fi␊ |
48 | if [ "${partitionBootSector:36:2}" == "00" ] && [ "${partitionBootSector:42:2}" == "f0" ] && [ "${partitionBootSector:48:2}" == "20" ]; then␊ |
49 | ␉echo "Found a FAT32 device formatted by OS X Snow Leopard Disk Utility"␊ |
50 | ␉echo "----------------------------------------------------------------"␊ |
51 | ␉echo ""␊ |
52 | ␉"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT32 volume formatted by OS X Snow Leopard Disk Utility"␊ |
53 | ␉exit 2␊ |
54 | fi␊ |
55 | if [ "${partitionBootSector:36:2}" == "02" ] && [ "${partitionBootSector:42:2}" == "f0" ] && [ "${partitionBootSector:48:2}" == "20" ]; then␊ |
56 | ␉echo "Found a FAT16 device formatted by OS X Snow Leopard Disk Utility"␊ |
57 | ␉echo "----------------------------------------------------------------"␊ |
58 | ␉echo ""␊ |
59 | ␉"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT16 volume formatted by OS X Snow Leopard Disk Utility"␊ |
60 | ␉exit 1␊ |
61 | fi␊ |
62 | if [ "${partitionBootSector:36:2}" == "00" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "20" ]; then␊ |
63 | ␉echo "Found a FAT32 device formatted by OS X Lion Disk Utility"␊ |
64 | ␉echo "--------------------------------------------------------"␊ |
65 | ␉echo ""␊ |
66 | ␉"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT32 volume formatted by OS X Lion Disk Utility"␊ |
67 | ␉exit 2␊ |
68 | fi␊ |
69 | if [ "${partitionBootSector:36:2}" == "02" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "20" ]; then␊ |
70 | ␉echo "Found a FAT16 device formatted by OS X Lion Disk Utility"␊ |
71 | ␉echo "--------------------------------------------------------"␊ |
72 | ␉echo ""␊ |
73 | ␉"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT16 volume formatted by OS X Lion Disk Utility"␊ |
74 | ␉exit 1␊ |
75 | fi␊ |
76 | echo "-----------------------------------------------"␊ |
77 | echo ""␊ |
78 | exit 0 |