Chameleon

Chameleon Commit Details

Date:2012-01-27 08:17:16 (2 years 10 months ago)
Author:blackosx
Commit:1811
Parents: 1810
Message:Testing with various package installer changes to improve the feedback in the install log.
Changes:
D/branches/blackosx/package/Scripts/Sub/UnMountEFIvolumes.sh
A/branches/blackosx/package/Scripts.templates/UnMount/UnMountEFIvolumes.sh
A/branches/blackosx/package/Scripts.templates/UnMount
M/branches/blackosx/package/buildpkg.sh
M/branches/blackosx/package/Scripts.templates/Post/postinstall
M/branches/blackosx/package/Scripts.templates/Pre/clean_bootplist.pl
M/branches/blackosx/package/Scripts.templates/Pre/preinstall
M/branches/blackosx/package/Scripts/Main/Standardpostinstall

File differences

branches/blackosx/package/Scripts.templates/Post/postinstall
1111
1212
1313
14
14
1515
1616
1717
......
3131
3232
3333
34
35
34
35
3636
3737
3838
......
5454
5555
5656
57
57
exit 1
fi
# If target volume root of current system then replace
# If target volume is root of current system then replace
# / with volume name.
if [ "$3" == "/" ]; then
dest_vol="/Volumes/"$( ls -1F /Volumes | sed -n 's:@$::p' )
# Write some information to the Install Log
echo "======================================================"
echo "Running Post postinstall script"
echo "Target volume = ${dest_vol}"
echo "//Post"
echo "Updating permissions."
# ---------------------------------------------
# Update Rights
rm -f "${dest_vol}/.ChameleonEFI"
echo "======================================================"
echo "Post postinstall script complete"
echo "//Complete"
branches/blackosx/package/Scripts.templates/UnMount/UnMountEFIvolumes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# loop through and un-mount ALL mounted 'EFI' system partitions - Thanks kizwan
# Receives targetVolumeChosenByUser: To write install log to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 2 ]; then
targetVolumeChosenByUser="$1"
scriptDir="$2"
# echo "DEBUG: passed argument for targetVolumeChosenByUser = $targetVolumeChosenByUser"
# echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed" >&2
exit 9
fi
logName="@LOG_FILENAME@"
logFile="${targetVolumeChosenByUser}/$logName"
exec >>"${logFile}" 2>&1
echo "Check for and unmount all volumes named EFI..."
# Count of 5 exists incase for some reason /Volumes/EFI fails
# to be unmounted in which case the loop would run forever.
attempts=1
while [ "$( df | grep EFI )" ] && [ $attempts -lt 5 ]; do
#"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Volume named 'EFI' is mounted..."
#"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Unmounting $( df | grep EFI | awk '{print $1}' )"
echo "Volume named 'EFI' is mounted."
echo "Unmounting $( df | grep EFI | awk '{print $1}' )"
umount -f $( df | grep EFI | awk '{print $1}' )
(( attempts++ ))
done
if [ $attempts = 5 ]; then
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Failed to unmount 'EFI' System Partition."
exit 1
fi
exit 0
branches/blackosx/package/Scripts.templates/Pre/clean_bootplist.pl
55
66
77
8
89
910
1011
......
1213
1314
1415
16
1517
1618
1719
......
2224
2325
2426
25
2627
2728
2829
29
3030
3131
3232
33
33
3434
3535
3636
......
4040
4141
4242
43
44
43
44
45
46
47
48
49
4550
4651
4752
......
5055
5156
5257
58
5359
5460
5561
......
6773
6874
6975
76
7077
7178
7279
......
7784
7885
7986
80
87
88
8189
82
90
8391
8492
8593
......
92100
93101
94102
103
95104
our $target_volume;
our $boot_plist_filepath;
our $logfile;
our $yaml_file="@YAML_FILE@";
print stderr "A target volume is needed\n";
} else {
$target_volume=$ARGV[0];
$logfile=$ARGV[1];
}
$boot_plist_filepath = "${target_volume}/Extra/org.chameleon.Boot.plist";
sub _do_cmd {
my ($cmd, $key, $value) = @_;
my $out;
$key =~ s/([\s])/\\$1/g; # Escape characters in key
$value =~ s/([\s"])/\\$1/g; # Escape characters in value (space & ")
my $plistbuddy_command="$cmd :$key $value";
open ( OUTPUT, "-|", '/usr/libexec/plistbuddy', "-c", "$plistbuddy_command", "$boot_plist_filepath" );
my $exit_code = $?;
chomp($out = <OUTPUT>);
close OUTPUT;
close OUTPUT;
return $out;
}
}
sub delete_boot_plist_option {
my ($option) = @_;
return _do_cmd( "Delete", "$option");
my ($option) = @_;
my $current_value = get_boot_plist_option "$option";
if ( $current_value ne "") {
print LOG "$option\n";
return _do_cmd( "Delete", "$option");
}
return "";
}
sub delete_boot_plist_text_option {
if ( $current_value ne "") {
foreach my $recognized_value (@{$values}) {
if ($recognized_value eq $current_value) {
print LOG "$option $current_value\n";
return _do_cmd( "Delete", "$option");
}
}
$count{$value} = 1;
}
foreach my $value (split(/\s+/,$current_value)) {
print LOG "$option $value\n";
if ( not exists $count{$value} ) {
push @new_list, $value;
}
}
sub main() {
# Remove all options that installer can managed
# Remove all options that installer can manage
open (LOG,">>$logfile");
my ($yaml_file) = @_;
my $hash_ref = LoadFile($yaml_file) or die "Can't open yaml file\n";
my $hash_ref = LoadFile($yaml_file) or die "Can't open yaml file\n";
foreach my $option ( keys %{$hash_ref} ) {
my $type = $hash_ref->{$option}->{type};
if ( $type =~ /^bool$/i ) {
$hash_ref->{$option}->{values} );
}
}
close(LOG);
}
branches/blackosx/package/Scripts.templates/Pre/preinstall
11
22
3
4
5
6
7
8
93
104
115
......
4135
4236
4337
44
38
4539
4640
4741
4842
49
50
51
43
5244
5345
5446
......
5749
5850
5951
60
52
6153
62
54
55
6356
6457
65
58
59
60
6661
6762
6863
......
7267
7368
7469
75
7670
77
7871
7972
8073
......
8477
8578
8679
87
80
81
82
83
84
85
86
87
88
89
90
91
8892
89
90
91
93
94
95
96
97
9298
93
94
95
96
97
98
9999
#!/bin/bash
echo "==============================================="
echo "Pre-Install Script"
echo "*********************************"
echo "-----------------------------------------------"
echo ""
# Creates text file named '@LOG_FILENAME@'
# at the root of the target volume. This is to give the user
# a record of the installation process and also to show why
backupRootDir="${targetVolume}/Chameleon.Backups"
backupDir="${backupRootDir}/"$( date -j "+%F-%Hh%M" )
# Create the backup dirextory
# Create the backup directory
mkdir -p "$backupDir"
[[ -f "$logFile" ]] && mv "$logFile" "${backupDir}/${logName}" # Backup old log file
# Setup Chameleon Log file
# by writing header and diskutil list
# Setup Chameleon Log file by writing header and diskutil list
echo "Chameleon installer log - $( date )
Installer version: %CHAMELEONVERSION% %CHAMELEONREVISION%
======================================================" >"${logFile}"
echo "======================================================" >>"${logFile}"
# ---------------------------------------------
# Backing up Chameleon files
# Backup Chameleon files
# ---------------------------------------------
echo "Backing up Chameleon files" >>"${logFile}"
echo "//Preinstall
Search for and back up any existing Chameleon files..." >>"${logFile}"
# Backup stage2
if [[ -f "${targetVolume}/boot" ]];then
echo "Backing up stage2 file ${targetVolume}/boot to ${backupDir}/boot" >>"${logFile}"
bootVersion=$( strings "${targetVolume}/boot" | sed -nE 's!^Darwin/x86 boot.+(Chameleon.+)!\1!p' ) # zhell's command.
echo "Found stage2 'boot' file for $bootVersion on ${targetVolume}." >>"${logFile}"
echo "Backing up ${targetVolume}/boot to ${backupDir}/boot." >>"${logFile}"
cp -p "${targetVolume}/boot" "${backupDir}/boot"
fi
# Backup /Extra directory
fi
chflags -R nohidden "$backupDir" # Remove the invisible flag of files in the backups
find "${backupRootDir}" -type d -depth -empty -exec rmdir {} \; # Remove empty directories
echo "======================================================" >>"${logFile}"
# Check existing plist name for old naming convention and change to new convention.
fi
# ---------------------------------------------
# Clearing options that Chameleon can managed
# The installer now enables options found in an
# existing org.chameleon.Boot.plist. The user can
# then de-select these pre-selected options from
# the installer if desired.
#
# To deal with this, we clear all options that this
# installer can manage, then later on, re-add the
# options the user leaves checked.
#
# Other possible options that this installer can't
# manage are left in the org.chameleon.Boot.plist,
# for example: Rename Partition, SystemId.
# ---------------------------------------------
echo "Clearing options..." >>"${logFile}"
"${PWD}/clean_bootplist.pl" "${targetVolume}" 2>&1 | grep -v 'Does Not Exist' >>"${logFile}"
echo "======================================================" >>"${logFile}"
if [[ -f "${targetVolume}/Extra/org.chameleon.Boot.plist" ]]; then
echo "Clearing de-selectable options from existing org.chameleon.Boot.plist..." >>"${logFile}"
"${PWD}/clean_bootplist.pl" "${targetVolume}" "${logFile}" 2>&1 | grep -v 'Does Not Exist' >>"${logFile}"
echo "======================================================" >>"${logFile}"
fi
echo "==============================================="
echo "END - Pre-Install Script"
echo "*********************************"
echo "-----------------------------------------------"
echo ""
exit 0
branches/blackosx/package/Scripts/Main/Standardpostinstall
7979
8080
8181
82
82
8383
8484
8585
......
192192
193193
194194
195
195196
196
197
198197
199198
200199
# Write some information to the Install Log
"$scriptDir"InstallLog.sh "${targetVolume}" "Running Standard postinstall script"
"$scriptDir"InstallLog.sh "${targetVolume}" "//Standard"
"$scriptDir"InstallLog.sh "${targetVolume}" "Target volume = ${targetVolume} on ${targetDevice}"
# Double check we can see the selected partition and it's of the right type.
fi
fi
"$scriptDir"InstallLog.sh "${targetVolume}" "//End Standard"
"$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak"
"$scriptDir"InstallLog.sh "${targetVolume}" "Standard script complete"
"$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak"
echo "==============================================="
echo "END - Standard Post-Install Script"
branches/blackosx/package/Scripts/Sub/UnMountEFIvolumes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
echo "==============================================="
echo "Unmount all volumes named EFI"
# loop through and un-mount ALL mounted 'EFI' system partitions - Thanks kizwan
# Receives targetVolumeChosenByUser: To write install log to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 2 ]; then
targetVolumeChosenByUser="$1"
scriptDir="$2"
# echo "DEBUG: passed argument for targetVolumeChosenByUser = $targetVolumeChosenByUser"
# echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed" >&2
exit 9
fi
# Count of 5 exists incase for some reason /Volumes/EFI fails
# be unmounted in which case the loop would run forever.
attempts=1
while [ "$( df | grep EFI )" ] && [ $attempts -lt 5 ]; do
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Volume named 'EFI' is mounted..."
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Unmounting $( df | grep EFI | awk '{print $1}' )"
umount -f $( df | grep EFI | awk '{print $1}' )
(( attempts++ ))
done
if [ $attempts = 5 ]; then
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Failed to unmount 'EFI' System Partition."
exit 1
fi
exit 0
branches/blackosx/package/buildpkg.sh
3232
3333
3434
35
3635
3736
3837
......
4443
4544
4645
47
4846
4947
5048
......
5856
5957
6058
61
6259
6360
6461
......
9895
9996
10097
101
10298
10399
104100
......
107103
108104
109105
110
106
111107
112108
113109
......
172168
173169
174170
175
171
176172
177173
178174
......
239235
240236
241237
242
238
243239
244240
245241
......
313309
314310
315311
316
312
317313
318314
319315
......
442438
443439
444440
445
441
446442
447443
448444
......
477473
478474
479475
476
480477
481478
482479
......
652649
653650
654651
655
652
656653
657654
658655
......
807804
808805
809806
810
811
807
808
812809
813810
814811
......
852849
853850
854851
855
852
856853
857854
858855
......
865862
866863
867864
868
865
869866
870867
871868
......
873870
874871
875872
876
873
877874
878875
879876
......
881878
882879
883880
884
881
885882
886883
887884
......
955952
956953
957954
958
955
959956
960957
961958
......
965962
966963
967964
968
965
969966
970967
971968
......
990987
991988
992989
990
993991
992
993
994994
995995
996996
997997
998998
999
999
10001000
10011001
10021002
10031003
10041004
1005
1005
10061006
10071007
10081008
......
10211021
10221022
10231023
1024
1025
1026
1027
1028
1029
1024
1025
1026
1027
1028
1029
10301030
10311031
10321032
source "${SRCROOT}/auto.conf"
# ====== COLORS ======
declare -r COL_BLACK="\x1b[30;01m"
declare -r COL_RED="\x1b[31;01m"
declare -r COL_GREEN="\x1b[32;01m"
declare -r COL_RESET="\x1b[39;49;00m"
# ====== REVISION/VERSION ======
declare -r CHAMELEON_VERSION=$( cat version )
# stage
declare -r CHAMELEON_TIMESTAMP=$( date -j -f "%Y-%m-%d %H:%M:%S" "${CHAMELEON_BUILDDATE}" "+%s" )
# ====== CREDITS ======
declare -r CHAMELEON_DEVELOP=$(awk "NR==6{print;exit}" ${PKGROOT}/../CREDITS)
declare -r CHAMELEON_CREDITS=$(awk "NR==10{print;exit}" ${PKGROOT}/../CREDITS)
declare -r CHAMELEON_PKGDEV=$(awk "NR==14{print;exit}" ${PKGROOT}/../CREDITS)
declare -r modules_packages_identity="${chameleon_package_identity}.modules"
# ====== FUNCTIONS ======
trim () {
local result="${1#"${1%%[![:space:]]*}"}" # remove leading whitespace characters
echo "${result%"${result##*[![:space:]]}"}" # remove trailing whitespace characters
function makeSubstitutions () {
# Substition is like: Key=Value
#
# Optionnal arguments:
# Optional arguments:
# --subst=<substition> : add a new substitution
#
# Last argument(s) is/are file(s) where substitutions must be made
# Arguments:
# --pkg-rootdir=<pkg_rootdir> : path of the pkg root dir
#
# Optionnal arguments:
# Optional arguments:
# --subst=<substition> : add a new substitution
#
# Substition is like: Key=Value
# Add a new choice
addChoice () {
# Optionnal arguments:
# Optional arguments:
# --group=<group> : Group Choice Id
# --start-selected=<javascript code> : Specifies whether this choice is initially selected or unselected
# --start-enabled=<javascript code> : Specifies the initial enabled state of this choice
# Add a group choice
addGroupChoices() {
# Optionnal arguments:
# Optional arguments:
# --parent=<parent> : parent group choice id
# --exclusive_zero_or_one_choice : only zero or one choice can be selected in the group
# --exclusive_one_choice : only one choice can be selected in the group
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
# Package will be build at the end
# Package will be built at the end
# End pre install choice
# build core package
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources
addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" InstallerLog
addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" UnMount
cp -f ${PKGROOT}/Scripts/Main/${choiceId}postinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
cp -f ${PKGROOT}/Scripts/Sub/* ${PKG_BUILD_DIR}/${choiceId}/Scripts
ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile
while IFS= read -r -d '' OptionsFile; do
# Take filename and Strip .txt from end and path from front
# Take filename and strip .txt from end and path from front
builtOptionsList=${OptionsFile%.txt}
builtOptionsList=${builtOptionsList##*/}
packagesidentity="${chameleon_package_identity}.options.$builtOptionsList"
choiceId="Post"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" ${choiceId}
cp -f ${PKGROOT}/Scripts/Sub/UnMountEFIvolumes.sh ${PKG_BUILD_DIR}/${choiceId}/Scripts
addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" InstallerLog
addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" UnMount
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
header+="auth=\"root\">\n"
header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
rm -R -f "${packagePath}/Temp"
#rm -R -f "${packagePath}/Temp" //blackosx commented out for now
[ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"
[ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"
header+="\t</scripts>\n"
# Create the Script archive file (cpio format)
(cd "${packagePath}/Scripts" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \
grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
grep -E '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
fi
header+="</pkg-info>"
# Create the Payload file (cpio format)
(cd "${packagePath}/Root" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \
grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
grep -E '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
# Create the package
(cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)
# Add the package to the list of build packages
pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${CHAMELEON_VERSION}.0.0.${CHAMELEON_TIMESTAMP}'>#${packageName}.pkg</pkg-ref>"
rm -rf "${packagePath}"
#rm -rf "${packagePath}" //blackosx commented out for now
fi
}
declare -r distributionFilename="${packagename// /}-${CHAMELEON_VERSION}-r${CHAMELEON_REVISION}.pkg"
declare -r distributionFilePath="${distributionDestDir}/${distributionFilename}"
rm -f "${distributionDestDir}/${packagename// /}"*.pkg
#rm -f "${distributionDestDir}/${packagename// /}"*.pkg //blackosx commented out for now
mkdir -p "${PKG_BUILD_DIR}/${packagename}"
pkgdir="${PKG_BUILD_DIR}/${packagename}/${pkg}"
# expand individual packages
pkgutil --expand "${PKG_BUILD_DIR}/${pkg}" "$pkgdir"
rm -f "${PKG_BUILD_DIR}/${pkg}"
#rm -f "${PKG_BUILD_DIR}/${pkg}" //blackosx commented out for now
done
# Create the Distribution file
ditto --noextattr --noqtn "${PKGROOT}/Resources" "${PKG_BUILD_DIR}/${packagename}/Resources"
# CleanUp the directory
# this next line should work but it doesn't - not sure why.
#find "${PKG_BUILD_DIR}/${packagename}" \( -type d -name '.svn' \) -o -name '.DS_Store' -exec rm -rf {} \;
# instead, doing it this way works.
find "${PKG_BUILD_DIR}/${packagename}/Resources" -name ".svn" -type d -o -name ".DS_Store" -type f | while read component
do
rm -rf "${component}"
done
# Make substitutions like version, revision, stage, developers, credits, etc..
# Make substitutions for version, revision, stage, developers, credits, etc..
makeSubstitutions $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )
# Create the final package
pkgutil --flatten "${PKG_BUILD_DIR}/${packagename}" "${distributionFilePath}"
# Here is the place for assign a Icon to the pkg
# Here is the place to assign an icon to the pkg
ditto -xk "${PKGROOT}/Icons/pkg.zip" "${PKG_BUILD_DIR}/Icons/"
DeRez -only icns "${PKG_BUILD_DIR}/Icons/Icons/pkg.icns" > "${PKG_BUILD_DIR}/Icons/tempicns.rsrc"
Rez -append "${PKG_BUILD_DIR}/Icons/tempicns.rsrc" -o "${distributionFilePath}"
echo ""
echo -e $COL_GREEN" Build info."
echo -e $COL_GREEN" ==========="
echo -e $COL_BLUE" Package name: "$COL_RESET"${distributionFilename}"
echo -e $COL_BLUE" MD5: "$COL_RESET"$md5"
echo -e $COL_BLUE" Version: "$COL_RESET"$CHAMELEON_VERSION"
echo -e $COL_BLUE" Stage: "$COL_RESET"$CHAMELEON_STAGE"
echo -e $COL_BLUE" Date/Time: "$COL_RESET"$CHAMELEON_BUILDDATE"
echo -e $COL_BLUE" Builded by: "$COL_RESET"$CHAMELEON_WHOBUILD"
echo -e $COL_CYAN" Package name: "$COL_RESET"${distributionFilename}"
echo -e $COL_CYAN" MD5: "$COL_RESET"$md5"
echo -e $COL_CYAN" Version: "$COL_RESET"$CHAMELEON_VERSION"
echo -e $COL_CYAN" Stage: "$COL_RESET"$CHAMELEON_STAGE"
echo -e $COL_CYAN" Date/Time: "$COL_RESET"$CHAMELEON_BUILDDATE"
echo -e $COL_CYAN" Built by: "$COL_RESET"$CHAMELEON_WHOBUILD"
echo ""
}

Archive Download the corresponding diff file

Revision: 1811