Chameleon

Chameleon Commit Details

Date:2011-12-25 08:43:17 (8 years 11 months ago)
Author:blackosx
Commit:1750
Parents: 1749
Message:Revise postinstall script to only backup /Extra folder if necessary, and provide better feedback in the Install Log. Clean up and remove some obselete commands.
Changes:
M/branches/blackosx/package/Scripts/Main/postinstall

File differences

branches/blackosx/package/Scripts/Main/postinstall
3737
3838
3939
40
41
42
43
40
41
42
43
44
45
46
4447
45
46
47
48
49
50
51
52
53
48
49
5450
55
56
57
58
59
60
61
62
51
52
53
6354
6455
65
66
67
68
69
70
71
56
7257
73
74
58
59
60
7561
76
77
78
79
62
63
64
65
66
67
8068
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
11690
11791
118
119
120
121
122
123
124
125
126
127
128
129
130
13192
93
94
13295
133
134
135
136
137
138
139
140
96
97
98
99
100
101
102
141103
104
142105
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
143132
144133
145134
146135
147
136
148137
149138
150139
......
180169
181170
182171
183
172
173
184174
185175
186176
187
177
178
188179
189180
190181
......
210201
211202
212203
213
214
204
215205
216206
217207
218208
219
220
221
209
210
222211
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
212
213
214
215
240216
217
218
219
241220
242
243
244
221
222
223
224
225
226
227
228
229
230
231
232
233
245234
246
247
248
249
235
236
237
238
250239
251
252240
253241
254
255
256
257
258
259
260242
261243
262244
263245
264246
265247
248
249
250
266251
267252
268253
# set temporary directory
chamTemp="$dest_vol/usr/local/chamTemp"
# Check for stopped installation due to Chameleon
# already existing on the same disk.
# TO DO - This check can be removed as it's no longer used!!
if [ ! -f "$dest_vol"/.ChameleonExists ]; then
# ---------------------------------------------
# Build org.chameleon.Boot.plist
# ---------------------------------------------
# All options selected are now dummy files with
# the filename of the option and value residing
# in /usr/local/chamTemp/options/
# for example. Boot Banner=Yes
# ---------------------------------------------
# Add any installed modules to the Install Log
# ---------------------------------------------
if [ -e "${chamTemp}"/Extra/modules ]; then
ls "${chamTemp}"/Extra/modules | while read FILE
do
"$scriptDir"InstallLog.sh "${dest_vol}" "Added module: $FILE"
done
fi
# Are there any options to build?
if [ "$(ls -A ${chamTemp}/options )" ]; then
# ---------------------------------------------
# Add any installed themes to the Install Log
# ---------------------------------------------
if [ -e "${chamTemp}"/Extra/Themes ]; then
ls "${chamTemp}"/Extra/Themes | while read FILE
do
"$scriptDir"InstallLog.sh "${dest_vol}" "Added Theme: $FILE"
done
# Check for temporary directory/Extra folder.
if [ ! -d "$chamTemp"/Extra ]; then
mkdir "$chamTemp"/Extra
fi
# ---------------------------------------------
# Build org.chameleon.Boot.plist
# ---------------------------------------------
# All options selected are now dummy files with
# the filename of the option and value residing
# in /usr/local/chamTemp/options/
# for example. Boot Banner=Yes
tempOCBP="$chamTemp"/Extra/org.chameleon.Boot.plist
# Are there any options to build?
if [ "$(ls -A ${chamTemp}/options )" ]; then
# Create template for org.chameleon.Boot.plist"
tempOCBP="$chamTemp"/Extra/org.chameleon.Boot.plist
cp "$4"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist "$tempOCBP"
# Check for temporary directory/Extra folder.
if [ ! -d "$chamTemp"/Extra ]; then
mkdir "$chamTemp"/Extra
fi
# Read list of all boot options the user added.
arrayCount=0
kernelFlagCount=0
while read FILE
do
options[arrayCount]="${FILE##*/}"
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
while read FILE
do
options[arrayCount]="${FILE##*/}"
# Check keyRead for 'KF' at beginning to
# indicate that should be a kernel flag
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.
kernelflag[kernelFlagCount]="${options[arrayCount]##*flag=}"
"$scriptDir"InstallLog.sh "${dest_vol}" "Added kernel flag: ${kernelflag[kernelFlagCount]}"
(( kernelFlagCount++ ))
else
keyRead="${options[$arrayCount]%=*}"
value="${options[$arrayCount]#*=}"
# escape any spaces
keyToUse=$( echo $keyRead | sed 's/ /\\ /g' )
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
# Check keyRead for 'KF' at beginning to
# indicate that should be a kernel flag
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.
kernelflag[kernelFlagCount]="${options[arrayCount]##*flag=}"
"$scriptDir"InstallLog.sh "${dest_vol}" "Added kernel flag: ${kernelflag[kernelFlagCount]}"
(( kernelFlagCount++ ))
else
keyRead="${options[$arrayCount]%=*}"
value="${options[$arrayCount]#*=}"
# escape any spaces
keyToUse=$( echo $keyRead | sed 's/ /\\ /g' )
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
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
(( arrayCount++ ))
done < <(ls "${chamTemp}"/options )
if [ $kernelFlagCount -gt 0 ]; then
# Add any kernel flags together in to one string.
for (( i=0 ; i < $kernelFlagCount ; i++ ))
do
kernelFlagString="${kernelFlagString} ${kernelflag[i]}"
done
# We add the final string in the next section.
fi
if [ $kernelFlagCount -gt 0 ]; then
# Add any kernel flags together in to one string.
for (( i=0 ; i < $kernelFlagCount ; i++ ))
do
kernelFlagString="${kernelFlagString} ${kernelflag[i]}"
done
# We add the final string in the next section.
fi
fi
# ---------------------------------------------
# Add any installed modules to the Install Log
# ---------------------------------------------
if [ -e "${chamTemp}"/Extra/modules ]; then
ls "${chamTemp}"/Extra/modules | while read FILE
do
"$scriptDir"InstallLog.sh "${dest_vol}" "Added module: $FILE"
if [ "$FILE" == "Keylayout.dylib" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Also adding required Keymaps."
fi
done
fi
# ---------------------------------------------
# Add any installed themes to the Install Log
# ---------------------------------------------
if [ -e "${chamTemp}"/Extra/Themes ]; then
ls "${chamTemp}"/Extra/Themes | while read FILE
do
"$scriptDir"InstallLog.sh "${dest_vol}" "Added Theme: $FILE"
done
fi
# Does a temporary /Extra folder exist?
if [ -d "$chamTemp"/Extra ]; then
# ---------------------------------------------
# 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 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."
# 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.
"$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."
NOTE: and chose Wait=Yes from the list, this will NOT be changed.
------"
sudo /usr/libexec/plistbuddy -c "Merge $chamTemp/holding.plist" "$tempOCBP"
if [[ -n "$currentFlags" ]];then
# ---------------------------------------------
# Copy temp Extra folder to target destination
# ---------------------------------------------
# If we've made a temporary Extra folder to use then
# check for an existing /Extra folder. If found, back it up
# Check for an existing /Extra folder. If found, back it up
# before copying the temporary Extra folder to destination.
# Extra folder now resides in /usr/local/chamTemp/
# Copy /usr/local/chamTemp/Extra to correct location.
if [ -d "$chamTemp"/Extra ]; then
if [ ! -f "$dest_vol"/.ChameleonEFI ]; then
# The Standard install option chosen
if [ ! -f "$dest_vol"/.ChameleonEFI ]; then
# The Standard install option chosen
# Does an /Extra folder already exist?
if [ -e "$dest_vol"/Extra ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Moving $dest_vol/Extra folder to $dest_vol/Extra-OLD-$( date "+%H-%M-%S" )"
mv "$dest_vol/Extra" "$dest_vol/Extra_OLD-"$( date "+%H-%M-%S" )
fi
"$scriptDir"InstallLog.sh "${dest_vol}" "Writing new Extra folder to: $dest_vol/"
echo "Copying $chamTemp/Extra TO $dest_vol"
cp -R "$chamTemp"/Extra "$dest_vol"
else
# The EFI system partition install option was chosen
# Does a /Volumes/Extra folder already exist?
if [ -e "/Volumes/EFI/Extra" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Moving /Volumes/EFI/Extra folder to /Volumes/EFI/Extra-OLD-$( date "+%H-%M-%S" )"
mv "/Volumes/EFI/Extra" "/Volumes/EFI/Extra_OLD-"$( date "+%H-%M-%S" )
fi
"$scriptDir"InstallLog.sh "${dest_vol}" "Writing new Extra folder to: /Volumes/EFI/"
cp -R "$chamTemp"/Extra "/Volumes/EFI"
# Does an /Extra folder already exist?
if [ -e "$dest_vol"/Extra ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Moving $dest_vol/Extra folder to $dest_vol/Extra-OLD-$( date "+%H-%M-%S" )"
mv "$dest_vol/Extra" "$dest_vol/Extra_OLD-"$( date "+%H-%M-%S" )
fi
"$scriptDir"InstallLog.sh "${dest_vol}" "Writing new Extra folder to: $dest_vol/"
echo "Copying $chamTemp/Extra TO $dest_vol"
cp -R "$chamTemp"/Extra "$dest_vol"
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,
# The EFI system partition install option was chosen
# Does a /Volumes/Extra folder already exist?
if [ -e "/Volumes/EFI/Extra" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "Moving /Volumes/EFI/Extra folder to /Volumes/EFI/Extra-OLD-$( date "+%H-%M-%S" )"
mv "/Volumes/EFI/Extra" "/Volumes/EFI/Extra_OLD-"$( date "+%H-%M-%S" )
fi
"$scriptDir"InstallLog.sh "${dest_vol}" "Writing new Extra folder to: /Volumes/EFI/"
cp -R "$chamTemp"/Extra "/Volumes/EFI"
fi
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,
so leaving existing $dest_vol/Extra folder untouched."
fi
else
if [ -e "/Volumes/EFI/Extra" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "No elements selected for adding to an Extra folder,
fi
else
if [ -e "/Volumes/EFI/Extra" ]; then
"$scriptDir"InstallLog.sh "${dest_vol}" "No elements selected for adding to an Extra folder,
so leaving existing /Volumes/EFI/Extra folder untouched."
fi
fi
fi
# Unmount ALL mounted volumes named EFI
"$scriptDir"UnMountEFIvolumes.sh "${dest_vol}" "${scriptDir}"
else
cleanUp="${cleanUp},0"
rm "$dest_vol"/.ChameleonExists
fi
# ---------------------------------------------
# Cleanup
# ---------------------------------------------
# Unmount ALL mounted volumes named EFI
"$scriptDir"UnMountEFIvolumes.sh "${dest_vol}" "${scriptDir}"
# remove any temporary boot sector files if they exist
if [ -d /tmp/newbs ]; then
cleanUp="${cleanUp},1a"

Archive Download the corresponding diff file

Revision: 1750