Chameleon

Chameleon Svn Source Tree

Root/branches/rewrite/package/Scripts/Standard/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
3
4diskloader="boot0"
5partitionloader="boot1h"
6filesystemloader="boot"
7
8diskmicrocodetype[1]="GRUB,47525542"
9diskmicrocodetype[2]="LILO,4c494c4f"
10
11start ()
12{
13# 1 volume
14
15bootvolume="${@}"
16bootresources="${0%/*}"
17
18if [ -z "${bootvolume}" ]; then
19echo
20echo "Cannot find the volume. Exiting."
21echo
22exit
23fi
24
25bootdev=$( df "${bootvolume}" | sed -n '2p' | awk '{print $1}' )
26bootrdev=${bootdev/disk/rdisk}
27
28if [ "${bootdev}" = "${bootdev#*disk*s}" ]; then
29echo
30echo "ERROR Volume does not use slices."
31echo
32exit
33fi
34
35bootdisk=${bootdev%s*}
36bootrdisk=${bootdisk/disk/rdisk}
37bootslice=${bootdev#*disk*s}
38
39echo "Volume is ${bootvolume}"
40echo "Volume device is ${bootdev}"
41echo "Volume raw device is ${bootrdev}"
42echo "Volume slice is ${bootslice}"
43echo "Disk device is ${bootdisk}"
44echo "Disk raw device is ${bootrdisk}"
45echo "Disk loader is ${diskloader}"
46echo "Partition loader is ${partitionloader}"
47echo "Filesystem loader is ${filesystemloader}"
48echo "Boot Resources is ${bootresources}"
49
50}
51
52checkdiskmicrocodetype ()
53{
54diskmicrocode=$( 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}' )
55
56diskmicrocodetypecounter=0
57while [ ${diskmicrocodetypecounter} -lt ${#diskmicrocodetype[@]} ]; do
58 diskmicrocodetypecounter=$(( ${diskmicrocodetypecounter} + 1 ))
59 diskmicrocodetypeid=${diskmicrocodetype[${diskmicrocodetypecounter}]#*,}
60 if [ ! "${diskmicrocode}" = "${diskmicrocode/${diskmicrocodetypeid}/}" ]; then
61 echo "${diskmicrocodetype[${diskmicrocodetypecounter}]%,*} found."
62 fi
63done
64}
65
66checkdiskmicrocode ()
67{
68# 1 action ( check or set )
69
70diskmicrocode=$( 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}' )
71diskmicrocodemd5=$( dd 2>/dev/null if=${bootdisk} count=1 | dd 2>/dev/null count=1 bs=437 | md5 )
72
73if [ $( echo "${diskmicrocode}" | awk -F0 '{print NF-1}' ) = 874 ]; then
74if [ "${1}" = "set" ]; then
75echo "No disk microcode found. Updating."
76diskupdate=true
77else
78echo "No disk microcode found."
79fi
80else
81if [ ${1} = set ]; then
82echo "Disk microcode found. Preserving."
83else
84echo "Disk microcode found."
85fi
86echo "Disk microcode MD5 is ${diskmicrocodemd5}"
87fi
88}
89
90checkdisksignature ()
91{
92disksignature=$( 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}' )
93
94if [ $( echo "${disksignature}" | awk -F0 '{print NF-1}' ) = 8 ]; then
95echo "No disk signature found."
96else
97echo "Disk signature found."
98echo "Disk signature is 0x${disksignature}"
99fi
100}
101
102checkpartitionbootcode ()
103{
104# 1 action ( check or set )
105
106partitionbootcode=$( dd if=${bootrdev} count=1 2>/dev/null | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
107partitionbootcodeextended=$( dd if=${bootrdev} count=1 skip=1 2>/dev/null | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
108
109if [ $( echo "${partitionbootcode}" | awk -F0 '{print NF-1}' ) = 1024 ]; then
110if [ "${1}" = "set" ]; then
111echo "No partition bootcode found. Updating."
112else
113echo "No partition bootcode found."
114fi
115else
116if [ "${1}" = "set" ]; then
117echo "Partition bootcode found. Overwriting."
118else
119echo "Partition bootcode found."
120fi
121if [ $( echo "${partitionbootcodeextended}" | awk -F0 '{print NF-1}' ) = 1024 ]; then
122partitionbootcodemd5=$( dd 2>/dev/null if=${bootrdev} count=1 | md5 )
123else
124partitionbootcodemd5=$( dd 2>/dev/null if=${bootrdev} count=2 | md5 )
125echo "Partition bootcode is dual sector."
126fi
127echo "Partition bootcode MD5 is ${partitionbootcodemd5}"
128fi
129}
130
131checkpartitionactive ()
132{
133partitionactive=$( fdisk -d ${bootrdisk} | grep -n "*" | awk -F: '{print $1}')
134
135if [ -n "${partitionactive}" ]; then
136echo "Partition flagged active is ${partitionactive}"
137else
138echo "No partition flagged active."
139fi
140
141}
142
143start ${3}
144
145#partitiontable=$( diskutil list ${bootdisk} | sed -n '3p' | awk '{print $2}' )
146#[ "${partitiontable}" = "GUID_partition_scheme" ] && echo "GPT found."
147#[ "${partitiontable}" = "FDisk_partition_scheme" ] && echo "MBR found."
148#[ "${partitiontable}" = "Apple_partition_scheme" ] && echo "APT found." && exit
149
150partitiontable=$( dd 2>/dev/null if=${bootdisk} count=1 skip=1 | dd 2>/dev/null count=8 bs=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
151if [ "${partitiontable:0:16}" == "4546492050415254" ]; then
152partitiontable=$( dd 2>/dev/null if=${bootdisk} count=1 | dd 2>/dev/null count=64 bs=1 skip=446 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
153if [ "${partitiontable:8:2}" == "ee" ]; then
154if [ "${partitiontable:40:2}" == "00" ] && [ "${partitiontable:72:2}" == "00" ] && [ "${partitiontable:104:2}" == "00" ]; then
155partitiontable="GPT"
156 else
157partitiontable="GPT/MBR"
158fi
159fi
160else
161partitiontable="MBR"
162fi
163
164echo "${partitiontable} found."
165
166diskupdate=false
167
168checkdiskmicrocodetype
169checkdiskmicrocode set
170checkdisksignature
171checkpartitionbootcode set
172checkpartitionactive
173
174if ${diskupdate}; then
175echo "Executing command: fdisk -u -f /usr/standalone/i386/${diskloader} -y ${bootdisk}"
176fdisk -u -f "${bootvolume}/usr/standalone/i386/${diskloader}" -y ${bootdisk}
177fi
178
179echo "Executing command: dd if=/usr/standalone/i386/${partitionloader} of=${bootrdev}"
180dd if="${bootvolume}/usr/standalone/i386/${partitionloader}" of=${bootrdev}
181
182echo "Executing command: cp /usr/standalone/i386/${filesystemloader} ${bootvolume}"
183cp "${bootvolume}/usr/standalone/i386/${filesystemloader}" "${bootvolume}"
184
185echo "Executing command: ${bootresources}/Tools/SetFile -a V ${bootvolume}/${filesystemloader}"
186"${bootresources}/Tools/SetFile" -a V "${bootvolume}/${filesystemloader}"
187
188# If table is GPT make the first partition active (BadAxe compatibility).
189[ "${partitiontable}" = "GPT" ] && bootslice=1
190fdisk -e ${bootdisk} <<-MAKEACTIVE
191print
192flag ${bootslice}
193write
194y
195quit
196MAKEACTIVE
197
198checkdiskmicrocode check
199checkdisksignature
200checkpartitionbootcode check
201checkpartitionactive
202
203if ! [ -d "${bootvolume}/Extra/Extensions" ]; then
204echo "Executing command: mkdir -p ${bootvolume}/Extra/Extensions"
205mkdir -p "${bootvolume}/Extra/Extensions"
206fi
207# unpack any existing Extensions.mkext already on the booter volume
208if [ -f "${2}/Extra/Extensions.mkext" ]; then
209echo "Executing command: mkextunpack -d ${2}/Extra/Extensions ${2}/Extra/Extensions.mkext"
210mkextunpack -d "${2}/Extra/Extensions" "${2}/Extra/Extensions.mkext"
211echo "Executing command: rm -R -f ${2}/Extra/Extensions.mkext"
212rm -R -f "${2}/Extra/Extensions.mkext"
213fi
214
215# setup link for extras
216[ -h "${2}/.Chameleon" ] && unlink "${2}/.Chameleon"
217echo "Executing command: ln -s . ${2}/.Chameleon"
218ln -s "." "${2}/.Chameleon"
219
220exit
221

Archive Download this file

Revision: 1166