Chameleon

Chameleon Svn Source Tree

Root/branches/rewrite/package/Scripts/HFS/postinstall.sh

  • Property svn:executable set to *
Source at commit 1166 created 13 years 10 days ago.
By meklort, Fixed recent Makefile changes. Please do not use /Users/evan/SourceCode/tmp/chameleon/trunk or VPATH. the *only* time you should use /Users/evan/SourceCode/tmp/chameleon/trunk is when setting the SRCROOT variable. Also note that very soon make pkg is going to be removed. The pkg build script in trunk is very out of date. Instead please use the package maker at http://forge.voodooprojects.org/p/chameleonApplications/. Once this is ready for trunk it will be merged.
1#!/bin/bash
2
3diskloader="/usr/standalone/i386/boot0"
4partitionloader="/usr/standalone/i386/boot1h"
5filesystemloader="/usr/standalone/i386/boot"
6bootervolumename="EFI"
7booterextensions="Extra/Extensions"
8
9bootresources="${0%/*}"
10
11diskmicrocodetype[1]="GRUB,47525542"
12diskmicrocodetype[2]="LILO,4c494c4f"
13
14start ()
15{
16# $1 volume
17
18osxvolume="${@}"
19
20if [ -z "${osxvolume}" ]; then
21echo
22echo "Cannot find the volume. Exiting."
23exit
24fi
25
26bootdev=$( df "${osxvolume}" | sed -n '2p' | awk '{print $1}' )
27
28if [ "${bootdev}" = "${bootdev#*disk*s}" ]; then
29echo
30echo "ERROR Volume does not use slices."
31echo "Volume may be stored on a RAID array."
32echo
33exit
34fi
35
36partitiontable=$( dd 2>/dev/null if=${bootdev%s*} count=1 skip=1 | dd 2>/dev/null count=8 bs=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
37if [ "${partitiontable:0:16}" == "4546492050415254" ]; then
38partitiontable=$( dd 2>/dev/null if=${bootdev%s*} count=1 | dd 2>/dev/null count=64 bs=1 skip=446 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
39if [ "${partitiontable:8:2}" == "ee" ]; then
40if [ "${partitiontable:40:2}" == "00" ] && [ "${partitiontable:72:2}" == "00" ] && [ "${partitiontable:104:2}" == "00" ]; then
41partitiontable="GPT"
42 else
43partitiontable="GPT/MBR"
44fi
45fi
46else
47echo
48echo "ERROR Volume is not on a GPT partitioned disc."
49echo
50exit
51fi
52
53echo "${partitiontable} found."
54
55echo "OS X Volume is ${osxvolume}"
56echo "OX X Volume device is ${bootdev}"
57
58bootvolume="/Volumes/$bootervolumename"
59bootdev=${bootdev%s*}s1
60bootrdev=${bootdev/disk/rdisk}
61bootdisk=${bootdev%s*}
62bootrdisk=${bootdisk/disk/rdisk}
63bootslice=${bootdev#*disk*s}
64
65echo "EFI Volume device is ${bootdev}"
66echo "EFI Volume raw device is ${bootrdev}"
67echo "EFI Volume slice is ${bootslice}"
68echo "Disk device is ${bootdisk}"
69echo "Disk raw device is ${bootrdisk}"
70echo "Disk loader is ${diskloader}"
71echo "Partition loader is ${partitionloader}"
72echo "Filesystem loader is ${filesystemloader}"
73
74}
75
76checkdiskmicrocodetype ()
77{
78diskmicrocode=$( dd 2>/dev/null if=${bootdisk} count=1 | dd 2>/dev/null count=1 bs=437 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
79
80diskmicrocodetypecounter=0
81while [ ${diskmicrocodetypecounter} -lt ${#diskmicrocodetype[@]} ]; do
82 diskmicrocodetypecounter=$(( ${diskmicrocodetypecounter} + 1 ))
83 diskmicrocodetypeid=${diskmicrocodetype[${diskmicrocodetypecounter}]#*,}
84 if [ ! "${diskmicrocode}" = "${diskmicrocode/${diskmicrocodetypeid}/}" ]; then
85 echo "${diskmicrocodetype[${diskmicrocodetypecounter}]%,*} found."
86 fi
87done
88}
89
90checkdiskmicrocode ()
91{
92# 1 action ( check or set )
93
94diskmicrocode=$( dd 2>/dev/null if=${bootdisk} count=1 | dd 2>/dev/null count=1 bs=437 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
95diskmicrocodemd5=$( dd 2>/dev/null if=${bootdisk} count=1 | dd 2>/dev/null count=1 bs=437 | md5 )
96
97if [ $( echo "${diskmicrocode}" | awk -F0 '{print NF-1}' ) = 874 ]; then
98if [ "${1}" = "set" ]; then
99echo "No disk microcode found. Updating."
100diskupdate=true
101else
102echo "No disk microcode found."
103fi
104else
105if [ ${1} = set ]; then
106echo "Disk microcode found. Preserving."
107else
108echo "Disk microcode found."
109fi
110echo "Disk microcode MD5 is ${diskmicrocodemd5}"
111fi
112}
113
114checkdisksignature ()
115{
116disksignature=$( dd 2>/dev/null if=${bootdisk} count=1 | dd 2>/dev/null count=4 bs=1 skip=440 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
117
118if [ $( echo "${disksignature}" | awk -F0 '{print NF-1}' ) = 8 ]; then
119echo "No disk signature found."
120else
121echo "Disk signature found."
122echo "Disk signature is 0x${disksignature}"
123fi
124}
125
126checkpartitionbootcode ()
127{
128# 1 action ( check or set )
129
130partitionbootcode=$( dd if=${bootrdev} count=1 2>/dev/null | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
131partitionbootcodeextended=$( dd if=${bootrdev} count=1 skip=1 2>/dev/null | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
132
133if [ $( echo "${partitionbootcode}" | awk -F0 '{print NF-1}' ) = 1024 ]; then
134if [ "${1}" = "set" ]; then
135echo "No partition bootcode found. Updating."
136else
137echo "No partition bootcode found."
138fi
139else
140if [ "${1}" = "set" ]; then
141echo "Partition bootcode found. Overwriting."
142else
143echo "Partition bootcode found."
144fi
145if [ $( echo "${partitionbootcodeextended}" | awk -F0 '{print NF-1}' ) = 1024 ]; then
146partitionbootcodemd5=$( dd 2>/dev/null if=${bootrdev} count=1 | md5 )
147else
148partitionbootcodemd5=$( dd 2>/dev/null if=${bootrdev} count=2 | md5 )
149echo "Partition bootcode is dual sector."
150fi
151echo "Partition bootcode MD5 is ${partitionbootcodemd5}"
152fi
153}
154
155checkpartitionactive ()
156{
157partitionactive=$( fdisk -d ${bootrdisk} | grep -n "*" | awk -F: '{print $1}')
158
159if [ -n "${partitionactive}" ]; then
160echo "Partition flagged active is ${partitionactive}"
161else
162echo "No partition flagged active."
163fi
164
165}
166
167start ${3}
168
169if [ "$( df | grep ${bootdev} )" ]; then
170umount -f ${bootdev}
171fi
172
173if ! [ "$( fstyp ${bootdev} | grep hfs )" ]; then
174echo "${bootdev} isn't a HFS partition"
175echo "Executing command: newfs_hfs -v ${bootervolumename} ${bootdev}"
176newfs_hfs -v "${bootervolumename}" "${bootdev}"
177else
178echo "${bootdev} is already a HFS partition (skipping)"
179fi
180
181diskupdate=false
182checkdiskmicrocodetype
183checkdiskmicrocode set
184checkdisksignature
185checkpartitionbootcode set
186checkpartitionactive
187
188if ${diskupdate}; then
189echo "Executing command: fdisk -u -f ${diskloader} -y ${bootdisk}"
190fdisk -u -f "${osxvolume}/${diskloader}" -y ${bootdisk}
191fi
192
193echo "Executing command: dd if=${partitionloader} of=${bootrdev}"
194dd if="${osxvolume}/${partitionloader}" of=${bootrdev}
195
196# If table is GPT make the first partition active (BadAxe compatibility).
197[ "${partitiontable}" = "GPT" ] && bootslice=1
198if [[ "${partitiontable}" = "GPT" ]]; then
199fdisk -e ${bootdisk} <<-MAKEACTIVE
200print
201flag ${bootslice}
202write
203y
204quit
205MAKEACTIVE
206fi
207
208checkdiskmicrocode check
209checkdisksignature
210checkpartitionbootcode check
211checkpartitionactive
212
213[ -d "${bootvolume}" ] || mkdir -p "${bootvolume}"
214echo "Executing command: mount_hfs ${bootdev} ${bootvolume}"
215mount_hfs "${bootdev}" "${bootvolume}"
216
217echo "Executing command: cp ${osxvolume}${filesystemloader} ${bootvolume}/boot"
218cp "${osxvolume}${filesystemloader}" "${bootvolume}/boot"
219
220if ! [ -d "${bootvolume}/Extra/Extensions" ]; then
221echo "Executing command: mkdir -p ${bootvolume}/Extra/Extensions"
222mkdir -p "${bootvolume}/Extra/Extensions"
223fi
224# unpack any existing Extensions.mkext already on the booter volume
225if [ -e "${bootvolume}/Extra/Extensions.mkext" ]; then
226echo "Executing command: mkextunpack -d ${bootvolume}/Extra/Extensions ${bootvolume}/Extra/Extensions.mkext"
227mkextunpack -d "${bootvolume}/Extra/Extensions" "${bootvolume}/Extra/Extensions.mkext"
228echo "Executing command: rm -R -f ${bootvolume}/Extra/Extensions.mkext"
229rm -R -f "${bootvolume}/Extra/Extensions.mkext"
230fi
231
232# copy existing /Extra
233if [ -d "${2}/Extra" ]; then
234[ -d "${bootvolume}/Extra/Extensions" ] || mkdir -p "${bootvolume}/Extra/Extensions"
235echo "Executing command: find ${2}/Extra -name '*.plist' -depth 1 -exec cp -f {} ${bootvolume}/Extra \;"
236find "${2}/Extra" -name '*.plist' -depth 1 -exec cp -f {} "${bootvolume}/Extra/" \;
237if [ -f "${2}/Extra/Extensions.mkext" ]; then
238echo "Executing command: mkextunpack -d ${2}/Extra/Extensions ${2}/Extra/Extensions.mkext"
239mkextunpack -d "${bootvolume}/Extra/Extensions" "${2}/Extra/Extensions.mkext"
240fi
241if [ -d "${2}/Extra/Extensions" ]; then
242echo "Executing command: find ${2}/Extra/Extensions -name '*.kext' -depth 1 -exec cp -R {} ${bootvolume}/Extra/Extensions \;"
243find "${2}/Extra/Extensions" -name '*.kext' -depth 1 -exec cp -R {} "${bootvolume}/Extra/Extensions" \;
244fi
245fi
246
247# setup link for extras
248[ -h "${2}/.Chameleon" ] && unlink "${2}/.Chameleon"
249echo "Executing command: ln -s /Volumes/${bootervolumename} ${2}/.Chameleon"
250ln -s "/Volumes/${bootervolumename}" "${2}/.Chameleon"
251
252exit
253

Archive Download this file

Revision: 1166