Chameleon

Chameleon Commit Details

Date:2011-12-22 19:00:20 (8 years 11 months ago)
Author:JrCs
Commit:1740
Parents: 1739
Message:Update postinstall script - Fix a bug where kernel flags are not set properly - Fix indent - Add some comments
Changes:
M/trunk/package/Scripts/Main/postinstall

File differences

trunk/package/Scripts/Main/postinstall
2020
2121
2222
23
23
2424
2525
26
26
2727
2828
2929
......
5151
5252
5353
54
54
5555
5656
5757
......
7878
7979
8080
81
82
83
8481
82
83
84
8585
86
86
8787
8888
8989
......
9696
9797
9898
99
99
100100
101101
102
102
103103
104104
105105
......
108108
109109
110110
111
112
113
114
115
111
112
113
114
115
116116
117
117
118118
119119
120
121
122
123
124
125
126
127
128
129
130
131
132
120
121
122
123
124
125
126
127
128
129
130
131
132
133133
134134
135135
136
136
137137
138138
139139
140
140
141141
142
142
143143
144144
145145
146146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184184
185185
186186
187187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
211210
212211
213212
......
242241
243242
244243
245
244
246245
247246
248247
......
252251
253252
254253
255
256
257
254
255
256
258257
259258
260259
......
266265
267266
268267
269
270
268
269
271270
272271
273
274
272
273
275274
276275
277
278
276
277
279278
280279
281
282
280
281
283282
284283
285284
286285
287
288
286
287
289288
290289
291290
292291
293
294
292
293
295294
296295
297296
......
302301
303302
304303
305
304
# / with volume name.
if [ "$3" == "/" ]
then
dest_vol="/Volumes/"$( ls -1F /Volumes | sed -n 's:@$::p' )
dest_vol="/Volumes/"$( ls -1F /Volumes | sed -n 's:@$::p' )
else
dest_vol="$3"
fi
fi
# Find script location so to find the Install Log script.
MYLOCATION="${PWD}/${BASH_ARGV[0]}"
"$scriptDir"InstallLog.sh "${dest_vol}" "Added module: $FILE"
done
fi
# ---------------------------------------------
# Add any installed themes to the Install Log
# ---------------------------------------------
mkdir "$chamTemp"/Extra
fi
tempOCBP="$chamTemp"/Extra/org.chameleon.Boot.plist
# Create template for org.chameleon.Boot.plist"
tempOCBP="$chamTemp"/Extra/org.chameleon.Boot.plist
# Create template for org.chameleon.Boot.plist"
tempOCBP="$chamTemp"/Extra/org.chameleon.Boot.plist
cp "$4"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist "$tempOCBP"
# Read list of all boot options the user added.
arrayCount=0
kernelFlagCount=0
if [ ${options[arrayCount]:0:2} = "KF" ];then
# plistbuddy only add's if the key doesn't already exist.
# So let's store any kernelflags and add them all at the
# same time once when we reach the end of the options list.
# same time once when we reach the end of the options list.
kernelflag[kernelFlagCount]="${options[arrayCount]##*flag=}"
"$scriptDir"InstallLog.sh "${dest_vol}" "Added kernel flag: ${kernelflag[kernelFlagCount]}"
(( kernelFlagCount++ ))
(( kernelFlagCount++ ))
else
keyRead="${options[$arrayCount]%=*}"
value="${options[$arrayCount]#*=}"
if [ "${keyToUse}" != "DONT" ] && [ "${value}" != "ADD" ]; then
sudo /usr/libexec/plistbuddy -c "Add :${keyToUse} string ${value}" "$tempOCBP"
returnValue=$?
if [ ${returnValue} -ne 1 ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Added boot option: ${keyRead}=${value}"
else
"$scriptDir"InstallLog.sh "${dest_vol}" "Can't add ${keyRead}=${value} as an option already exists for: ${keyRead}"
fi
if [ ${returnValue} -ne 1 ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Added boot option: ${keyRead}=${value}"
else
"$scriptDir"InstallLog.sh "${dest_vol}" "Can't add ${keyRead}=${value} as an option already exists for: ${keyRead}"
fi
fi
fi
fi
(( arrayCount++ ))
done < <(ls "${chamTemp}"/options )
# If exclusive options were used and the 'None' option was chosen,
# then a dummy file named DONT=ADD would be in /$chamTemp/Extra/options.
# If that was the only option then the above code would have made a
# temporary Extra folder with a default org.chameleon.Boot.plist
# In this case we don't need it and should discard it otherwise the folder
# will be copied to the users / directory when it's not wanted.
if [ ${arrayCount} == 1 ] && [ "${keyToUse}" == "DONT" ] && [ "${value}" == "ADD" ]; then
if [ -e "${chamTemp}"/Extra ] && [ ! -e "${chamTemp}"/Extra/Themes ] && [ ! -e "${chamTemp}"/Extra/Modules ]; then
rm -r -f "$chamTemp"/Extra
fi
fi
# If exclusive options were used and the 'None' option was chosen,
# then a dummy file named DONT=ADD would be in /$chamTemp/Extra/options.
# If that was the only option then the above code would have made a
# temporary Extra folder with a default org.chameleon.Boot.plist
# In this case we don't need it and should discard it otherwise the folder
# will be copied to the users / directory when it's not wanted.
if [ ${arrayCount} == 1 ] && [ "${keyToUse}" == "DONT" ] && [ "${value}" == "ADD" ]; then
if [ -e "${chamTemp}"/Extra ] && [ ! -e "${chamTemp}"/Extra/Themes ] && [ ! -e "${chamTemp}"/Extra/Modules ]; then
rm -r -f "$chamTemp"/Extra
fi
fi
if [ $kernelFlagCount -gt 0 ]; then
# Add any kernel flags together in to one string.
for (( i=0 ; i < $kernelFlagCount ; i++ ))
do
do
kernelFlagString="${kernelFlagString} ${kernelflag[i]}"
done
# We add the final string in the next section.
fi
fi
fi
# ---------------------------------------------
# Merge /Extra folders?
# ---------------------------------------------
# Does the user want to upgrade an existing /Extra folder?
# If so, then merge their existing one in to the temp one
if [ -e "$chamTemp/install_type_upgrade" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "User selected to do an upgrade install."
# first move the new org.chameleon.Boot.plist out of tmp
# Extra folder so we can merge that separately.
mv "$tempOCBP" "$chamTemp/holding.plist"
# Check for an existing /Extra folder
# and merge existing /Extra with temp one.
if [ -e "$dest_vol"/.ChameleonEFI ]; then
if [ -e "/Volumes/EFI/Extra" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Merging existing /Volumes/EFI/Extra folder."
ditto --noextattr --noqtn /Volumes/EFI/Extra "$chamTemp"/Extra
fi
else
if [ -e "$dest_vol/Extra" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Merging existing ${dest_vol}/Extra folder."
ditto --noextattr --noqtn "${dest_vol}"/Extra "$chamTemp"/Extra
fi
fi
# Check existing plist name for old naming convention
# and change to new convention.
if [ -e "$chamTemp"/Extra/com.apple.Boot.plist ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Renaming existing com.apple.Boot.plist to org.chameleon.Boot.plist."
mv "$chamTemp"/Extra/com.apple.Boot.plist "$tempOCBP"
fi
# Before merging org.chameleon.Boot.plist, copy any
# existing kernel flags, then delete the entry.
currentFlags=$( sudo /usr/libexec/plistbuddy -c "Print :Kernel\ Flags" "$tempOCBP" )
sudo /usr/libexec/plistbuddy -c "Delete :Kernel\ Flags" "$tempOCBP"
# Merge new org.chameleon.Boot.plist (holding.plist)
# with their currently existing one.
"$scriptDir"InstallLog.sh "${dest_vol}" "Merging new options into org.chameleon.Boot.plist.
# If so, then merge their existing one in to the temp one
if [ -e "$chamTemp/install_type_upgrade" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "User selected to do an upgrade install."
# first move the new org.chameleon.Boot.plist out of tmp
# Extra folder so we can merge that separately.
mv "$tempOCBP" "$chamTemp/holding.plist"
# Check for an existing /Extra folder
# and merge existing /Extra with temp one.
if [ -e "$dest_vol"/.ChameleonEFI ]; then
if [ -e "/Volumes/EFI/Extra" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Merging existing /Volumes/EFI/Extra folder."
ditto --noextattr --noqtn /Volumes/EFI/Extra "$chamTemp"/Extra
fi
else
if [ -e "$dest_vol/Extra" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Merging existing ${dest_vol}/Extra folder."
ditto --noextattr --noqtn "${dest_vol}"/Extra "$chamTemp"/Extra
fi
fi
# Check existing plist name for old naming convention
# and change to new convention.
if [ -e "$chamTemp"/Extra/com.apple.Boot.plist ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Renaming existing com.apple.Boot.plist to org.chameleon.Boot.plist."
mv "$chamTemp"/Extra/com.apple.Boot.plist "$tempOCBP"
fi
# Before merging org.chameleon.Boot.plist, copy any
# existing kernel flags, then delete the entry.
currentFlags=$( sudo /usr/libexec/plistbuddy -c "Print :Kernel\ Flags" "$tempOCBP" )
sudo /usr/libexec/plistbuddy -c "Delete :Kernel\ Flags" "$tempOCBP"
# Merge new org.chameleon.Boot.plist (holding.plist)
# with their currently existing one.
"$scriptDir"InstallLog.sh "${dest_vol}" "Merging new options into org.chameleon.Boot.plist.
NOTE: Please check the new merged org.chameleon.Boot.plist as
NOTE: any existing keys will NOT have been updated.
NOTE: For example: If you already had Wait=No as a boot option
NOTE: and chose Wait=Yes from the list, this will NOT be changed."
sudo /usr/libexec/plistbuddy -c "Merge $chamTemp/holding.plist" "$tempOCBP"
# Combine new kernel flags with old ones.
kernelFlagString="${kernelFlagString} $currentFlags"
# Write complete kernel flag entry back.
sudo /usr/libexec/plistbuddy -c "Add :Kernel\ Flags string $kernelFlagString" "$tempOCBP"
if [ ${returnValue}=1 ]; then # key already exists.
sudo /usr/libexec/plistbuddy -c "Delete :Kernel\ Flags" "$tempOCBP"
sudo /usr/libexec/plistbuddy -c "Add :Kernel\ Flags string $kernelFlagString" "$tempOCBP"
fi
elif [ -e "$chamTemp/install_type_new" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "User selected to make a new install."
# Add kernel flags (if any)
if [ $kernelFlagCount -gt 0 ]; then
sudo /usr/libexec/plistbuddy -c "Add :Kernel\ Flags string $kernelFlagString" "$tempOCBP"
if [ ${returnValue}=1 ]; then # key already exists.
sudo /usr/libexec/plistbuddy -c "Delete :Kernel\ Flags" "$tempOCBP"
sudo /usr/libexec/plistbuddy -c "Add :Kernel\ Flags string $kernelFlagString" "$tempOCBP"
fi
fi
fi
sudo /usr/libexec/plistbuddy -c "Merge $chamTemp/holding.plist" "$tempOCBP"
if [[ -n "$currentFlags" ]];then
# Combine new kernel flags with old ones.
kernelFlagString="${kernelFlagString} $currentFlags"
fi
elif [ -e "$chamTemp/install_type_new" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "User selected to make a new install."
fi
# Write kernel flags option
kernelFlagString=$(echo ${kernelFlagString}) # Remove leading and trailing spaces
if [[ -n "$kernelFlagString" ]];then
sudo /usr/libexec/plistbuddy -c "Add :Kernel\ Flags string $kernelFlagString" "$tempOCBP"
returnValue=$?
if [ ${returnValue} -ne 0 ]; then # key already exists.
sudo /usr/libexec/plistbuddy -c "Delete :Kernel\ Flags" "$tempOCBP"
sudo /usr/libexec/plistbuddy -c "Add :Kernel\ Flags string $kernelFlagString" "$tempOCBP"
fi
fi
# ---------------------------------------------
# Copy temp Extra folder to target destination
# ---------------------------------------------
else
if [ ! -f "$dest_vol"/.ChameleonEFI ]; then
if [ -e "$dest_vol"/Extra ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "No elements selected for adding to an Extra folder,
"$scriptDir"InstallLog.sh "${dest_vol}" "No elements selected for adding to an Extra folder,
so leaving existing $dest_vol/Extra folder untouched."
fi
else
fi
fi
fi
# Unmount ALL mounted volumes named EFI
"$scriptDir"UnMountEFIvolumes.sh "${dest_vol}" "${scriptDir}"
# Unmount ALL mounted volumes named EFI
"$scriptDir"UnMountEFIvolumes.sh "${dest_vol}" "${scriptDir}"
else
cleanUp="${cleanUp},0"
rm "$dest_vol"/.ChameleonExists
# remove any temporary boot sector files if they exist
if [ -d /tmp/newbs ]; then
cleanUp="${cleanUp},1a"
rm /tmp/newbs
cleanUp="${cleanUp},1a"
rm /tmp/newbs
fi
if [ -d /tmp/origbs ]; then
cleanUp="${cleanUp},1b"
rm /tmp/origbs
cleanUp="${cleanUp},1b"
rm /tmp/origbs
fi
if [ -d /tmp/newBootSector ]; then
cleanUp="${cleanUp},1c"
rm /tmp/newbs
cleanUp="${cleanUp},1c"
rm /tmp/newbs
fi
if [ -d /tmp/originalBootSector ]; then
cleanUp="${cleanUp},1d"
rm /tmp/origbs
cleanUp="${cleanUp},1d"
rm /tmp/origbs
fi
# delete the temporary Chameleon folder
if [ -e "$chamTemp" ]; then
cleanUp="${cleanUp},2"
rm -rf "$chamTemp"
cleanUp="${cleanUp},2"
rm -rf "$chamTemp"
fi
# Remove /.ChameleonEFI file
if [ -f "$dest_vol"/.ChameleonEFI ]; then
cleanUp="${cleanUp},3"
rm "$dest_vol"/.ChameleonEFI
cleanUp="${cleanUp},3"
rm "$dest_vol"/.ChameleonEFI
fi
"$scriptDir"InstallLog.sh "${dest_vol}" "Cleanup: ${cleanUp}"
echo "END - Post Post-Install Script"
echo "*********************************"
echo "-----------------------------------------------"
echo ""
echo ""

Archive Download the corresponding diff file

Revision: 1740