Chameleon

Chameleon Commit Details

Date:2015-01-29 23:41:03 (3 years 9 months ago)
Author:ErmaC
Commit:2567
Parents: 2566
Message:Update Chameleon pkg Installer (Allow install on ESP). (Credits to Micky1979)
Changes:
D/branches/ErmaC/Enoch/package/Scripts/Sub/UnMountEFIvolumes.sh
D/branches/ErmaC/Enoch/package/Scripts/Sub/WriteChameleonStage0.sh
D/branches/ErmaC/Enoch/package/Scripts.templates/Pre/clean_bootplist.pl
D/branches/ErmaC/Enoch/package/Scripts/Sub/WriteChameleonStage2.sh
D/branches/ErmaC/Enoch/package/Scripts/Sub/CheckDiskMicrocode.sh
D/branches/ErmaC/Enoch/package/Scripts/Sub/CheckWindowsDiskSignature.sh
D/branches/ErmaC/Enoch/package/Scripts/Sub/patch
D/branches/ErmaC/Enoch/package/Scripts.templates/InstallerLog
D/branches/ErmaC/Enoch/package/Scripts/Sub/CheckPartitionScheme.sh
D/branches/ErmaC/Enoch/package/Scripts/Sub/CheckGRUBLinuxLoader.sh
D/branches/ErmaC/Enoch/package/Resources/distribution/background.tiff
D/branches/ErmaC/Enoch/package/Scripts/Sub/CheckFatType.sh
D/branches/ErmaC/Enoch/package/Scripts/Sub/MountESP.sh
D/branches/ErmaC/Enoch/package/Scripts/Sub/WriteChameleonStage1.sh
D/branches/ErmaC/Enoch/package/Scripts/Sub/CheckProceed.sh
D/branches/ErmaC/Enoch/package/Scripts/Sub/SetActivePartition.sh
D/branches/ErmaC/Enoch/package/Scripts/Sub/CheckPreviousChameleon.sh
A/branches/ErmaC/Enoch/package/Scripts/Main/BootNO
A/branches/ErmaC/Enoch/package/Scripts.templates/CleanOptions/clean_bootplist.pl
A/branches/ErmaC/Enoch/package/Scripts/Main/BootYES
A/branches/ErmaC/Enoch/package/Scripts.templates/CleanOptions
M/branches/ErmaC/Enoch/package/Scripts/Main/Standardpostinstall
M/branches/ErmaC/Enoch/package/Scripts.templates/InstallModule/postinstall
M/branches/ErmaC/Enoch/package/Changes.txt
M/branches/ErmaC/Enoch/package/Scripts.templates/Pre/preinstall
M/branches/ErmaC/Enoch/package/Scripts/Main/ESPpostinstall
M/branches/ErmaC/Enoch/package/buildpkg.sh
M/branches/ErmaC/Enoch/package/slimpkg.sh
M/branches/ErmaC/Enoch/package/Distribution
M/branches/ErmaC/Enoch/package/Scripts.templates/AddOption/postinstall
M/branches/ErmaC/Enoch/package/Scripts.templates/Post/postinstall
M/branches/ErmaC/Enoch/package/Scripts.templates/InstallTheme/postinstall

File differences

branches/ErmaC/Enoch/package/Distribution
1717
1818
1919
20
20
2121
2222
2323
var bootPlist = null;
if (my.target) {
var boot_plist_filenames = new Array( 'org.chameleon.Boot.plist', 'com.apple.Boot.plist' );
var boot_plist_filenames = new Array( 'org.chameleon.Boot.plist', 'com.apple.Boot.plist', 'com.apple.boot.plist');
for ( var i = 0; i < boot_plist_filenames.length; i++ ) {
bootPlist = system.files.plistAtPath( my.target.mountpoint + '/Extra/' + boot_plist_filenames[i] );
if (bootPlist)
branches/ErmaC/Enoch/package/slimpkg.sh
6262
6363
6464
65
6665
6766
6867
......
123122
124123
125124
126
127125
128126
129127
......
135133
136134
137135
138
139136
140137
141138
......
223220
224221
225222
226
227
228223
229224
230225
ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/Pre/Scripts/Resources/revision
ditto --noextattr --noqtn ${1%/*/*}/version ${1}/Pre/Scripts/Resources/version
cp -f ${pkgroot}/Scripts/Main/preinstall ${1}/Pre/Scripts
cp -f ${pkgroot}/Scripts/Sub/InstallLog.sh ${1}/Pre/Scripts
echo "[BUILD] Pre "
buildpackage "${1}/Pre" "/" "" "start_visible=\"false\" start_selected=\"true\"" >/dev/null 2>&1
# End build pre install package
mkdir -p ${1}/Standard/Root
mkdir -p ${1}/Standard/Scripts/Resources
cp -f ${pkgroot}/Scripts/Main/Standardpostinstall ${1}/Standard/Scripts/postinstall
cp -f ${pkgroot}/Scripts/Sub/* ${1}/Standard/Scripts
ditto --arch i386 `which SetFile` ${1}/Standard/Scripts/Resources/SetFile
ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/Standard/Scripts/Resources/revision
ditto --noextattr --noqtn ${1%/*/*}/version ${1}/Standard/Scripts/Resources/version
mkdir -p ${1}/EFI/Root
mkdir -p ${1}/EFI/Scripts/Resources
cp -f ${pkgroot}/Scripts/Main/ESPpostinstall ${1}/EFI/Scripts/postinstall
cp -f ${pkgroot}/Scripts/Sub/* ${1}/EFI/Scripts
ditto --arch i386 `which SetFile` ${1}/EFI/Scripts/Resources/SetFile
ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/EFI/Scripts/Resources/revision
ditto --noextattr --noqtn ${1%/*/*}/version ${1}/EFI/Scripts/Resources/version
mkdir -p ${1}/Post/Root
mkdir -p ${1}/Post/Scripts
cp -f ${pkgroot}/Scripts/Main/postinstall ${1}/Post/Scripts
cp -f ${pkgroot}/Scripts/Sub/InstallLog.sh ${1}/Post/Scripts
cp -f ${pkgroot}/Scripts/Sub/UnMountEFIvolumes.sh ${1}/Post/Scripts
ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/Post/Scripts/Resources/revision
ditto --noextattr --noqtn ${1%/*/*}/version ${1}/Post/Scripts/Resources/version
echo "[BUILD] Post "
branches/ErmaC/Enoch/package/Scripts.templates/AddOption/postinstall
22
33
44
5
5
6
7
8
69
710
811
912
1013
11
1214
1315
14
15
16
17
1618
1719
1820
19
21
22
2023
21
24
2225
26
27
28
2329
2430
2531
26
32
2733
2834
2935
......
5460
5561
5662
63
5764
set -u
targetVolume="$3"
configFile='/private/tmp/InstallConfig.plist'
v_mntptDev=$( /usr/libexec/plistbuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
key="@optionKey@"
value="@optionValue@"
type="@optionType@"
logName="@LOG_FILENAME@"
logFile="${targetVolume}/$logName"
# Check if target volume exists
if [[ ! -d "$targetVolume" ]]; then
echo "$targetVolume volume does not exist!" >&2
if [[ ! -d "$v_mntpt" ]]; then
echo "$v_mntpt volume does not exist!" >&2
exit 1
fi
exec >>"${logFile}" 2>&1
mainLine="=============================================================================="
subLine="------------------------------------------------------------------------------"
echo "Added boot option: ${key}=${value}"
exec > >(tee -a "${v_mntpt}/${logName}") 2>&1
echo "$mainLine"
echo "Writing boot option: ${key}=${value}"
key="${key// /\\ }" # Escape spaces
value="${value// /\\ }" # Escape spaces
bootPListFile="${targetVolume}/Extra/org.chameleon.Boot.plist"
bootPListFile="${v_mntpt}/Extra/org.chameleon.Boot.plist"
case "$type" in
bool|text)
;;
esac
echo "$subLine"
exit 0
branches/ErmaC/Enoch/package/Scripts.templates/Post/postinstall
55
66
77
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
831
9
10
32
33
1134
1235
13
14
15
16
17
18
19
36
37
38
2039
40
41
42
43
2144
2245
23
2446
25
47
2648
27
28
29
30
31
32
33
49
3450
35
51
52
3653
37
54
55
56
57
58
59
60
61
62
63
64
65
3866
39
40
41
67
68
69
70
4271
43
44
45
72
4673
47
48
74
75
76
77
4978
50
51
79
80
81
82
83
84
85
86
5287
53
54
5588
56
57
89
90
91
92
93
94
95
96
97
# $3 = Installation volume (mountpoint) to receive the payload
# $4 = Root directory for the system
mainLine="=============================================================================="
subLine="------------------------------------------------------------------------------"
if [ "$3" == "/" ]
then
targetVolume="/Volumes/"$( ls -1F /Volumes | sed -n 's:@$::p' )
# really need to do that?? Unix "component" path assume are between "/"
# ie current volume can be also /// or ///Volumes///MyVolume w/o problem!
else
targetVolume="$3"
fi
configFile='/private/tmp/InstallConfig.plist'
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
targetDevice=$( /usr/libexec/PlistBuddy -c "Print :targetdev" ${configFile} )
choicedVolume=$( LC_ALL=C diskutil info ${targetDevice} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
backupRootDir="${targetVolume}/Chameleon.Backups"
backupDir=$( /usr/libexec/PlistBuddy -c "Print :backupDir" ${configFile} )
# Check target exists
if [ ! -d "$3" ]; then
echo "$3 volume does not exist !" >&2
if [ ! -d "${targetVolume}" ]; then
echo "Target volume does not exist !" >&2
exit 1
fi
# 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' )
else
dest_vol="$3"
if [ ! -d "${v_mntpt}" ]; then
echo "Ram disk volume does not exist !" >&2
exit 1
fi
if [ ! -d "${choicedVolume}" ]; then
echo "${choicedVolume} volume does not exist !" >&2
exit 1
fi
logName="@LOG_FILENAME@"
logFile="${dest_vol}/$logName"
exec >>"${logFile}" 2>&1
exec > >(tee -a "${v_mntpt}/${logName}") 2>&1
# Find script location so to find the Install Log script.
MYLOCATION="${PWD}/${BASH_ARGV[0]}"
export MYLOCATION="${MYLOCATION%/*}"
scriptDir=$MYLOCATION
# Write some information to the Install Log
echo "======================================================"
echo "$mainLine"
echo "Running Post postinstall script"
echo "Target volume = ${dest_vol}"
echo "Target volume = ${choicedVolume}"
echo "$subLine"
# ---------------------------------------------
# Replace/Copying the Extra folder
echo "Moving Extra folder to ${choicedVolume}"
cp -R "${v_mntpt}/Extra" "${choicedVolume}"/
echo "NOTE: any Themes or modules you have must be there since this now is the boot partition,"
echo " ACPI tables, SMBios.plist and the org.chameleon.Boot.plist (with custom settings"
echo " for the target OSX must be in each partition that contanin it.)"
echo "$subLine"
echo "Post postinstall script complete"
echo "$mainLine"
# Update Rights
# ---------------------------------------------
chmod 777 ${dest_vol}/Extra 2>/dev/null
chmod 666 ${dest_vol}/Extra/*.plist 2>/dev/null
chmod 777 "${choicedVolume}"/Extra 2>/dev/null
chmod 666 "${choicedVolume}"/Extra/*.plist 2>/dev/null
chmod 666 "${choicedVolume}/Extra/${logName}" 2>/dev/null
# if an Extra/Extensions exist... we can repair the permission???
# ---------------------------------------------
# Cleanup
# ---------------------------------------------
# Check Backup folder (is always on the target Volume)
# Unmount ALL mounted volumes named EFI
"$scriptDir"UnMountEFIvolumes.sh "${dest_vol}" "${scriptDir}"
if [ -d "${backupRootDir}/${backupDir}" ]; then
# Remove empty directories
find "${backupRootDir}" -type d -depth -empty -exec rmdir {} \;
fi
# remove any temporary boot sector files if they exist
rm -f /tmp/newbs /tmp/origbs /tmp/originalBootSector /tmp/newBootSector
# copying the installer log inside the Extra folder
if [[ $( /usr/libexec/PlistBuddy -c "Print bootloader" ${configFile} ) == "true" ]];then
# if we have installed the bootloader, this is a new log
cat "${v_mntpt}/${logName}" > "${choicedVolume}/Extra/${logName}"
else
# ..otherwise adding the new log to the existing one (if exist)
cat "${v_mntpt}/${logName}" >> "${choicedVolume}/Extra/${logName}"
fi
# Remove /.ChameleonEFI file
rm -f "${dest_vol}/.ChameleonEFI"
echo "======================================================"
echo "Post postinstall script complete"
# Umount the Ram Disk & cleaning
rm -f /private/tmp/InstallConfig.plist
rm -f "${targetVolume}/EXTRAROOTDIR"
exec 1<&- # Restore stdout and close file descriptor #1 before umount the Ram Disk
umount -f $v_mntptDev > /dev/null
hdiutil detach $v_mntptDev
branches/ErmaC/Enoch/package/Scripts.templates/Pre/clean_bootplist.pl
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/perl
use strict;
use YAML::Syck;
our $target_volume;
our $boot_plist_filepath;
our $yaml_file="@YAML_FILE@";
if ($#ARGV < 0) {
print stderr "A target volume is needed\n";
} else {
$target_volume=$ARGV[0];
}
$boot_plist_filepath = "${target_volume}/Extra/org.chameleon.Boot.plist";
if ( -f "$boot_plist_filepath" ) {
main("$yaml_file");
}
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;
return $out;
}
sub get_boot_plist_option {
my ($option) = @_;
return _do_cmd( "Print", "$option");
}
sub delete_boot_plist_option {
my ($option) = @_;
return _do_cmd( "Delete", "$option");
}
sub delete_boot_plist_text_option {
my ($option, $values) = @_;
my $current_value = get_boot_plist_option "$option";
if ( $current_value ne "") {
foreach my $recognized_value (@{$values}) {
if ($recognized_value eq $current_value) {
return _do_cmd( "Delete", "$option");
}
}
}
return "";
}
sub delete_boot_plist_list_option {
my ($option, $values) = @_;
my $current_value = get_boot_plist_option "$option";
if ( $current_value ne "") {
my %count;
my @new_list;
foreach my $value (@{$values}) {
$count{$value} = 1;
}
foreach my $value (split(/\s+/,$current_value)) {
if ( not exists $count{$value} ) {
push @new_list, $value;
}
}
return _do_cmd( "Set", $option, join(' ',@new_list) );
}
return "";
}
sub main() {
# Remove all options that installer can managed
my ($yaml_file) = @_;
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 ) {
delete_boot_plist_option($option);
} elsif ( $type =~ /^text$/i ) {
delete_boot_plist_text_option( $option,
$hash_ref->{$option}->{values} );
} elsif ( $type =~ /^list$/i ) {
delete_boot_plist_list_option( $option,
$hash_ref->{$option}->{values} );
}
}
}
branches/ErmaC/Enoch/package/Scripts.templates/Pre/preinstall
11
22
3
4
5
6
7
8
93
104
115
126
137
148
15
16
9
10
11
1712
18
19
20
21
22
23
24
25
26
27
2813
2914
3015
......
3217
3318
3419
20
21
3522
36
23
3724
38
39
40
41
42
25
26
27
28
29
4330
44
45
31
32
33
34
35
36
37
38
4639
47
40
41
42
43
44
45
46
4847
49
50
48
49
50
51
5152
52
53
54
53
5554
56
57
58
59
60
61
62
63
64
65
66
55
56
57
58
59
60
6761
68
69
70
71
72
7362
74
63
64
7565
76
66
67
68
7769
78
70
71
72
7973
80
81
82
83
84
74
75
76
8577
86
87
88
89
90
91
78
79
9280
93
81
82
83
84
85
86
87
88
9489
95
96
97
9890
9991
#!/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
# possibly the installation process failed (even though the
# package installer ends reading 'Installation Successful').
# This script also prepares, then backs up any previous
# stage2 boot file, /Extra folder and install log if they exist.
# This script also prepares the Ram Disk and the InstallConfig.plist
mainLine="=============================================================================="
subLine="------------------------------------------------------------------------------"
# Find location of this script in the package installer
# so we know where all the other scripts are located.
MYLOCATION="${PWD}/${BASH_ARGV[0]}"
export MYLOCATION="${MYLOCATION%/*}"
scriptDir=$MYLOCATION
# If target volume root of current system then replace
# / with volume name.
if [ "$3" == "/" ]
then
targetVolume="/Volumes/"$( ls -1F /Volumes | sed -n 's:@$::p' )
targetVolume="$3"
fi
v_mntpt="/Volumes/BOOTRAMDISK"
size='409600' # is the size of a standard EFI partition
logName="@LOG_FILENAME@"
logFile="${targetVolume}/$logName"
configFile="/private/tmp/InstallConfig.plist"
# ---------------------------------------------
# Preparing Backing up of Chameleon files
# ---------------------------------------------
backupRootDir="${targetVolume}/Chameleon.Backups"
backupDir="${backupRootDir}/"$( date -j "+%F-%Hh%M" )
# Functions to create/umount the RAM DISK
UMOUNT_VDISK() {
umount -f "${1}"
hdiutil detach "${1}"
}
# Create the backup directory
mkdir -p "$backupDir"
RAM_DISK() {
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \
grep -x "${v_mntpt}" ) ]; then
devToUmount=$( LC_ALL=C diskutil info "${v_mntpt}" | grep -i 'Device Node:' | awk '{print $3}' )
UMOUNT_VDISK $devToUmount
fi
echo "CREATING RAM DISK"
# mkdir -p $v_mntpt
[[ -f "$logFile" ]] && mv "$logFile" "${backupDir}/${logName}" # Backup old log file
dev=$(hdiutil attach -nomount ram://${size})
if [ $? -eq 0 ] ; then
diskutil erasevolume FAT32 "BOOTRAMDISK" ${dev}
else
echo "Failed to create the Ram Disk, installation aborted!"
exit 1
fi
# Setup Chameleon Log file
# by writing header and diskutil list
rm -f $configFile
# adding the Ram disk device to InstallConfig.plist to be shared with other packages
/usr/libexec/PlistBuddy -c "Add :ramdisk string ${dev}" $configFile
}
echo "Chameleon installer log - $( date )
Installer version: %CHAMELEONVERSION% %CHAMELEONREVISION%
======================================================" >"${logFile}"
RAM_DISK
diskutil list >>"${logFile}"
echo "======================================================" >>"${logFile}"
# ---------------------------------------------
# Backup Chameleon files
# ---------------------------------------------
echo "Backup Chameleon files" >>"${logFile}"
# Backup stage2
if [[ -f "${targetVolume}/boot" ]];then
echo "Backup stage2 file ${targetVolume}/boot to ${backupDir}/boot" >>"${logFile}"
cp -p "${targetVolume}/boot" "${backupDir}/boot"
# ensure that ram disk has "/Volumes/BOOTRAMDISK" mount point
v_mntpt=$( LC_ALL=C diskutil info ${dev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
if [ ! -d "${v_mntpt}" ]; then
echo "Ram Disk not found!"
exit
fi
# Backup /Extra directory
if [[ -d "${targetVolume}/Extra" ]];then
echo "Backing up ${targetVolume}/Extra folder to ${backupDir}/Extra" >>"${logFile}"
cp -pR "${targetVolume}/Extra" "${backupDir}/Extra"
fi
chflags -R nohidden "$backupDir" # Remove the invisible flag of files in the backups
touch "${v_mntpt}/${logName}"
exec > >(tee -a "${v_mntpt}/${logName}") 2>&1
find "${backupRootDir}" -type d -depth -empty -exec rmdir {} \; # Remove empty directories
echo "$mainLine"
echo "Pre-Install Script"
echo "$subLine"
echo "======================================================" >>"${logFile}"
# creating a symlink (from Clover)
echo "Creating ${targetVolume}/EXTRAROOTDIR symlink targeting ${v_mntpt}"
ln -sf "${v_mntpt}" "${targetVolume}/EXTRAROOTDIR"
# Check existing plist name for old naming convention and change to new convention.
if [[ -f "${targetVolume}/Extra/com.apple.Boot.plist" ]]; then
echo "Renaming existing com.apple.Boot.plist to org.chameleon.Boot.plist" >>"${logFile}"
mv "${targetVolume}/Extra/com.apple.Boot.plist" "${targetVolume}/Extra/org.chameleon.Boot.plist"
fi
# Preparing Backing up of Chameleon files
backupRootDir="${targetVolume}/Chameleon.Backups"
backupDir=$( date -j "+%F-%Hh%M" )
# ---------------------------------------------
# Clearing options that Chameleon can managed
# ---------------------------------------------
echo "Clearing options..." >>"${logFile}"
"${PWD}/clean_bootplist.pl" "${targetVolume}" 2>&1 | grep -v 'Does Not Exist' >>"${logFile}"
echo "======================================================" >>"${logFile}"
# Create the backup directory
mkdir -p "${backupRootDir}/${backupDir}"
echo "==============================================="
# Remove the invisible flag of files in the backups
chflags -R nohidden "${backupRootDir}"
# adding the backupdir name to InstallConfig.plist to be shared with other packages
/usr/libexec/PlistBuddy -c "Add :backupDir string ${backupDir}" $configFile >/dev/null
diskutil list >> "${v_mntpt}/${logName}"
echo "$subLine"
echo "END - Pre-Install Script"
echo "*********************************"
echo "-----------------------------------------------"
echo ""
exit 0
branches/ErmaC/Enoch/package/Scripts.templates/InstallTheme/postinstall
22
33
44
5
5
6
7
8
69
710
811
912
10
1113
1214
13
14
15
16
1517
1618
1719
18
20
21
1922
20
23
2124
25
26
27
28
29
30
31
32
33
34
35
2236
set -u
targetVolume="$3"
configFile='/private/tmp/InstallConfig.plist'
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
themeName="@themeName@"
themeDir="@themeDir@"
logName="@LOG_FILENAME@"
logFile="${targetVolume}/$logName"
# Check if target volume exists
if [[ ! -d "$targetVolume" ]]; then
echo "$targetVolume volume does not exist!" >&2
if [[ ! -d "${v_mntpt}" ]]; then
echo "$v_mntpt volume does not exist!" >&2
exit 1
fi
exec >>"${logFile}" 2>&1
mainLine="=============================================================================="
subLine="------------------------------------------------------------------------------"
[[ -d "${targetVolume}/Extra/Themes/$themeDir" ]] && echo "Theme $themeName installed"
exec > >(tee -a "${v_mntpt}/${logName}") 2>&1
echo "$mainLine"
echo "Installing Theme $themeName"
echo "$subLine"
if [[ -d "${v_mntpt}/Extra/Themes/$themeDir" ]]; then
echo "Theme $themeName installed"
else
echo "*** ERROR:$themeName not installed"
fi
echo "$subLine"
exit 0
branches/ErmaC/Enoch/package/Scripts.templates/InstallModule/postinstall
22
33
44
5
5
6
7
8
69
710
811
912
10
1113
1214
13
14
15
15
16
17
1618
1719
18
20
21
1922
20
23
2124
25
26
27
28
29
30
31
32
33
34
35
36
2237
set -u
targetVolume="$3"
configFile='/private/tmp/InstallConfig.plist'
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
moduleName="@moduleName@"
moduleFile="@moduleFile@"
logName="@LOG_FILENAME@"
logFile="${targetVolume}/$logName"
# Check if target volume exists
if [[ ! -d "$targetVolume" ]]; then
echo "$targetVolume volume does not exist!" >&2
exit 1
if [[ ! -d "${v_mntpt}" ]]; then
echo "Ram Disk not found volume does not exist!" >&2
# exit 1
fi
exec >>"${logFile}" 2>&1
mainLine="=============================================================================="
subLine="------------------------------------------------------------------------------"
[[ -f "${targetVolume}/Extra/modules/$moduleFile" ]] && echo "Module $moduleName installed"
exec > >(tee -a "${v_mntpt}/${logName}") 2>&1
echo "$mainLine"
echo "Installing $moduleFile"
echo "$subLine"
if [[ -f "${v_mntpt}/Extra/modules/$moduleFile" ]]; then
echo "$moduleName installed to Ram disk"
else
echo "*** ERROR:$moduleName not installed"
fi
echo "$subLine"
exit 0
branches/ErmaC/Enoch/package/Scripts.templates/CleanOptions/clean_bootplist.pl
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/perl
use strict;
use YAML::Syck;
our $target_volume;
our $boot_plist_filepath;
our $yaml_file="@YAML_FILE@";
if ($#ARGV < 0) {
print stderr "A target volume is needed\n";
} else {
$target_volume=$ARGV[0];
}
$boot_plist_filepath = "${target_volume}/Extra/org.chameleon.Boot.plist";
if ( -f "$boot_plist_filepath" ) {
main("$yaml_file");
}
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;
return $out;
}
sub get_boot_plist_option {
my ($option) = @_;
return _do_cmd( "Print", "$option");
}
sub delete_boot_plist_option {
my ($option) = @_;
return _do_cmd( "Delete", "$option");
}
sub delete_boot_plist_text_option {
my ($option, $values) = @_;
my $current_value = get_boot_plist_option "$option";
if ( $current_value ne "") {
foreach my $recognized_value (@{$values}) {
if ($recognized_value eq $current_value) {
return _do_cmd( "Delete", "$option");
}
}
}
return "";
}
sub delete_boot_plist_list_option {
my ($option, $values) = @_;
my $current_value = get_boot_plist_option "$option";
if ( $current_value ne "") {
my %count;
my @new_list;
foreach my $value (@{$values}) {
$count{$value} = 1;
}
foreach my $value (split(/\s+/,$current_value)) {
if ( not exists $count{$value} ) {
push @new_list, $value;
}
}
return _do_cmd( "Set", $option, join(' ',@new_list) );
}
return "";
}
sub main() {
# Remove all options that installer can managed
my ($yaml_file) = @_;
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 ) {
delete_boot_plist_option($option);
} elsif ( $type =~ /^text$/i ) {
delete_boot_plist_text_option( $option,
$hash_ref->{$option}->{values} );
} elsif ( $type =~ /^list$/i ) {
delete_boot_plist_list_option( $option,
$hash_ref->{$option}->{values} );
}
}
}
branches/ErmaC/Enoch/package/Changes.txt
1
2
13
24
35
- Micky1979 - Update Chameleon pkg Installer (Allow install on ESP).
- Micky1979 - Add sectorsize is a tiny command line made to detect the Physical and logical sector size of your hard disk.
- JrCs - boot1-install can show ntfs volume.
branches/ErmaC/Enoch/package/Scripts/Main/BootNO
1
2
3
4
5
6
7
8
#!/bin/bash
configFile="/private/tmp/InstallConfig.plist"
# adding option to declare that we are NOT installing the binary of the bootloader
# to the InstallConfig.plist
/usr/libexec/PlistBuddy -c "Add :bootloader bool false" ${configFile}
branches/ErmaC/Enoch/package/Scripts/Main/BootYES
1
2
3
4
5
6
7
8
#!/bin/bash
configFile="/private/tmp/InstallConfig.plist"
# adding option to declare that we are NOT installing the binary of the bootloader
# to the InstallConfig.plist
/usr/libexec/PlistBuddy -c "Add :bootloader bool true" ${configFile}
branches/ErmaC/Enoch/package/Scripts/Main/ESPpostinstall
11
22
3
4
5
6
7
3
4
5
6
7
8
9
10
811
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
3334
3435
3536
3637
38
3739
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
3858
39
40
41
42
43
44
45
46
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
4798
48
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
49115
50
51
52
53
54
55
116
117
118
119
120
121
122
123
124
56125
57
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
58145
59
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
60161
61
62
63
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
64186
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
81213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
82229
83
84
85
86
230
231
232
233
87234
88
235
236
237
238
239
240
241
242
243
89244
90
91
245
246
247
248
249
250
251
252
253
92254
93
94
255
256
257
258
259
260
261
95262
96
97
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
98317
318
319
320
321
322
323
324
325
326
327
328
329
330
99331
100
101
102
103
332
104333
105
106
107
108
334
335
336
337
338
109339
110
111
340
112341
113
114
115
116
342
343
344
345
346
347
348
117349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
118374
119
120
121375
122
123
376
377
378
124379
380
381
125382
126
127
128
129
383
384
130385
131
132
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
133410
411
412
134413
135
136
137
414
415
416
138417
139
140
141
142
143
144
145
146
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203418
#!/bin/bash
echo "==============================================="
echo "Main EFI System Partition Post-Install Script"
echo "*********************************************"
echo "-----------------------------------------------"
echo ""
# --------------------------------------------------------------------------------------------------------
# Install.sh v1.3, script to install Chameleon
# Created by Miky1979 on December 8th, 2014
# --------------------------------------------------------------------------------------------------------
targetVolume="${3}"
InstallToESP="1"
InstallBootloader="0"
configFile="/private/tmp/InstallConfig.plist"
# Find location of this script in the package installer
# so we know where all the other scripts are located.
MYLOCATION="${PWD}/${BASH_ARGV[0]}"
export MYLOCATION="${MYLOCATION%/*}"
scriptDir=$MYLOCATION
#echo "==============================================="
#echo "Apple Installer Package Variables"
#echo "*********************************"
#echo "DEBUG: $ 1 = Full path to the installation package the installer app is processing: " $1
#echo "DEBUG: $ 2 = Full path to the installation destination: " $2
#echo "DEBUG: $ 3 = Installation volume (mountpoint) to receive the payload: " $3
#echo "DEBUG: $ 4 = Root directory for the system: " $4
#echo "DEBUG: Script Name: " $SCRIPT_NAME
#echo "DEBUG: Package Path: " $PACKAGE_PATH
#echo "DEBUG: Installer Temp: " $INSTALLER_TEMP
#echo "DEBUG: Full path to the temp directory containing the operation executable: " $RECEIPT_PATH
#echo "-----------------------------------------------"
#echo ""
# Initialise Script Globals
if [[ $( /usr/libexec/PlistBuddy -c "Print bootloader" ${configFile} ) == "true" ]];then
# installing stage 0, 1 and 2 only if user want this:
# ie only if have no selected noboot choice
InstallBootloader="1"
fi
# --------------------------------------------------------------------------------------------------------
if [ ! -d "${targetVolume}" ]; then echo "target Volume not found, aborting!"; exit 1; fi
# --------------------------------------------------------------------------------------------------------
i386Dir="${targetVolume}/usr/standalone/i386"
usrLocalBin="${targetVolume}/usr/local/bin"
# --------------------------------------------------------------------------------------------------------
choicedVolume="${targetVolume}"
ESP_MOUNTED="0"
# --------------------------------------------------------------------------------------------------------
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//')
backupRootDir="${targetVolume}/Chameleon.Backups"
backupDir=$( /usr/libexec/PlistBuddy -c "Print :backupDir" ${configFile} )
logName="Chameleon_Installer_Log.txt"
logFile="${v_mntpt}/${logName}"
# --------------------------------------------------------------------------------------------------------
stage0Loader="boot0"
stage0LoaderDualBoot="boot0md"
stage1LoaderHFS="boot1h"
stage1LoaderFAT="boot1f32"
stage1LoaderExFAT="boot1x"
stage2Loader="boot"
versionToInstall=$(cat "${i386Dir}/Boot" | grep -a 'Darwin/x86 boot v' )
# --------------------------------------------------------------------------------------------------------
localdd="/bin/dd"
SS="${usrLocalBin}/sectorsize"
# --------------------------------------------------------------------------------------------------------
# Scanning all Variables. We are switching to the target Volume or its ESP.
# This function is usefull to rescan the new target "at need"
SCAN() {
targetDevice=$( LC_ALL=C diskutil info "${choicedVolume}" | grep -i 'Device Node:' | awk '{print $NF}' )
targetDeviceRaw=${targetDevice/disk/rdisk}
targetDisk=${targetDevice%s*}
targetDiskRaw=${targetDisk/disk/rdisk}
targetSlice=${targetDevice#*disk*s}
IOContent=$( LC_ALL=C diskutil info "${targetDisk}" | grep -i 'Content (IOContent)' | awk '{print $NF}' )
FS=$( LC_ALL=C diskutil info ${targetDevice} | grep -i 'Type (Bundle)' | \
awk '{print $NF}' | awk '{print tolower($0)}' )
disksignature=$( dd 2>/dev/null if="${targetDisk}" count=1 | dd 2>/dev/null count=4 bs=1 skip=440 | \
perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
# If target volume root of current system then replace
# / with volume name.
if [ "$3" == "/" ]
then
targetVolumeChosenByUser="/Volumes/"$( ls -1F /Volumes | sed -n 's:@$::p' )
else
targetVolumeChosenByUser="$3"
fi
if [ $InstallBootloader = "1" ];then
blocksize=$( "${SS}" "${targetDeviceRaw}" | awk '{ print $2 }' )
fi
}
# --------------------------------------------------------------------------------------------------------
# lines
mainLine="=============================================================================="
subLine="------------------------------------------------------------------------------"
# --------------------------------------------------------------------------------------------------------
# Debug for Chameleon.
# Create a folder inside the Desktop called "DebugChameleon", and the log will be full
DEBUG() {
echo "$mainLine"
echo "DEBUG: display script variables (ESPpostinstall)"
echo "$mainLine"
echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader} (or boot0hfs)"
echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot} (or boot0hfs)"
echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
echo "DEBUG: stage1LoaderExFAT: Partition loader is ${stage1LoaderExFAT}"
echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"
echo "DEBUG: targetVolume: Volume is ${targetVolume}"
echo "DEBUG: targetDevice: Volume device is ${targetDevice}"
echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"
echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
echo "DEBUG: versionToInstall: version to install is ${versionToInstall}"
echo "DEBUG: IOContent: partition scheme is ${IOContent}"
echo "DEBUG: FS: file System is ${FS}"
if [ $InstallBootloader = "1" ];then
echo "DEBUG: blocksize: block size detected = ${blocksize}-bytes"
fi
}
# --------------------------------------------------------------------------------------------------------
# Checking for unsupported FAT16 filesystem
CHECK_FAT16() {
pers=$( LC_ALL=C diskutil info "${targetDeviceRaw}" | grep -i 'File System Personality' \
| awk '{print $NF}' | awk '{print tolower($0)}' )
targetDeviceChosenByUser=$( df "${targetVolumeChosenByUser}" | sed -n '2p' | awk '{print $1}' )
case $pers in
fat16)
echo "** ERROR: Can't Install to a device using FAT16!"
exit 1
;;
*)
echo "First Check Passed!"
;;
esac
}
# --------------------------------------------------------------------------------------------------------
# Mount or umount the ESP..or leave as is if already mounted..
UMOUNT_ESP_DISK() {
# umount the ESP by its dev
umount -f $espDisk
}
targetVolume="/Volumes/EFI"
targetDevice=${targetDeviceChosenByUser%s*}s1
targetDeviceRaw=${targetDevice/disk/rdisk}
targetDisk=${targetDevice%s*}
targetDiskRaw=${targetDisk/disk/rdisk}
targetSlice=${targetDevice#*disk*s}
CHECK_ESP_MOUNTPOINT() {
# umount the ESP by its Mount Point
# and checking it if is busy by another ESP
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \
grep -x '/Volumes/ESP' ) ]; then
umount -f /Volumes/ESP
ESP_MOUNTED="0"
fi
}
targetResources="${targetVolumeChosenByUser}/usr/local/bin/"
MOUNT_ESP() {
ESP_MOUNTED="1" # ..assuming that the ESP can be already mounted..
if [ $( df | grep "${espDisk}" | awk '{print $1}' | grep -x "${espDisk}" ) ];then
# ESP is already mounted, so now we aquire the Mount Point
espmtp=$( LC_ALL=C diskutil info ${espDisk} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^[ \t]*//' )
if [ -d "${espmtp}" ];then
echo "ESP Mount Point is:${espmtp}, using that as target Volume!"
choicedVolume="${espmtp}"
SCAN
else
echo "The mount point was not found, try to umount it to get the standard one.."
UMOUNT_ESP_DISK
CHECK_ESP_MOUNTPOINT
fi
else
# ESP is not mounted..
ESP_MOUNTED="0"
fi
efiPartitionExist=0 # target volume does not have EFI system partition.
if [ $ESP_MOUNTED = "0" ];then
mkdir -p /Volumes/ESP
case $( fstyp $espDisk ) in
hfs)
mount -t hfs $espDisk /Volumes/ESP
;;
msdos)
mount -t msdos $espDisk /Volumes/ESP
;;
*)
echo "ESP fileSystem unsupported, Installing to ${targetVolume}!"
choicedVolume="${targetVolume}"
;;
esac
sleep 0.3
echo "==============================================="
echo "DEBUG: display script variables"
echo "***************************"
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \
grep -x '/Volumes/ESP' ) ]; then
ESP_MOUNTED="1"
choicedVolume="/Volumes/ESP"
SCAN
else
echo "ESP can't be mounted, Installing to ${targetVolume}!"
choicedVolume="${targetVolume}"
fi
fi
}
# --------------------------------------------------------------------------------------------------------
PARTITION_ACTIVE_IF() {
echo -e "${mainLine}\nSET PARTITION ACTIVE:"
# if Windows was detected, don't activate the partition..
# if the stage 0 loader is boo0hfs, don't activate the partition
if [ WINDOWS_EXIST = "0" ] || [ "${stage0Loader}" != "boot0hfs" ];then
partitionactive=$( fdisk -d ${targetDiskRaw} | grep -n "*" | awk -F: '{print $1}')
if [ "${partitionactive}" ] && [ "${partitionactive}" = "${targetSlice}" ]; then
echo "${targetDiskRaw#/dev/r}, slice "${targetSlice}" is already set active. No need to change it."
else
echo "Setting ${choicedVolume} partition active."
# BadAxe requires EFI partition to be flagged active.
# but it doesn't' hurt to do it for any non-windows partition.
echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"
echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot}"
echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"
echo "DEBUG: targetVolumeChosenByUser: Volume is ${targetVolumeChosenByUser}"
echo "DEBUG: targetDeviceChosenByUser: Volume device is ${targetDeviceChosenByUser}"
echo "DEBUG: targetVolume: Volume is ${targetVolume}"
echo "DEBUG: targetDevice: Volume device is ${targetDevice}"
echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"
echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
echo "DEBUG: targetResources: Boot Resources is ${targetResources}"
echo "-----------------------------------------------"
echo ""
# leave left aligned the follow code:
fdisk -e ${targetDiskRaw} <<-MAKEACTIVE
print
flag ${targetSlice}
write
y
quit
MAKEACTIVE
fi
else
echo "Partition will not activate when Windows is detected or stage 0 is boot0hfs"
fi
echo ""
echo "$mainLine"
}
# --------------------------------------------------------------------------------------------------------
# Writing stage 0
CHECK_WINDOWS() {
WINDOWS_EXIST="0"
if [ "${disksignature}" = "00000000" ]; then
echo "Windows installation not found on ${targetDisk}."
else
echo "Windows installation found on ${targetDisk}."
WINDOWS_EXIST="1"
fi
}
WRITE_STAGE0() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 0:"
CHECK_WINDOWS
case "$1" in
hfs)
if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0hfs"; else stage0Loader="boot0"; fi
;;
msdos)
if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0md"; else stage0Loader="boot0";fi
;;
exfat)
stage0Loader="boot0"
;;
esac
# Write some information to the Install Log
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Running EFI postinstall script"
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Target selected by user = ${targetVolumeChosenByUser} on ${targetDeviceChosenByUser}"
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Target volume = ${targetVolume} on ${targetDevice}"
"${usrLocalBin}/fdisk440" -u -f "${i386Dir}/${stage0Loader}" -y ${targetDisk}
echo "${stage0Loader} writed to ${targetDisk}"
fi
}
# Check to see if the selected disk uses a GPT
# --------------------------------------------------------------------------------------------------------
# Writing stage 1 on different filesystems
WRITE_STAGE1_HFS() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 HFS:"
$localdd if="${i386Dir}/${stage1LoaderHFS}" of=${targetDeviceRaw}
echo "${stage1LoaderHFS} (hfs) writed to ${targetDeviceRaw}."
fi
}
bootuuid=$( diskutil info "$targetDeviceChosenByUser" | grep Volume\ UUID | awk {'print $3'} )
partitiontable=$( diskutil list ${targetDeviceChosenByUser%s*} | sed -n '3p' | awk '{print $2}' )
WRITE_STAGE1_EXFAT() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 ExFAT:"
cp -R "${usrLocalBin}/boot1-install" "${v_mntpt}"/
cp -R "${i386Dir}/${stage1LoaderExFAT}" "${v_mntpt}"/
"${v_mntpt}/boot1-install" -y -u -f "${v_mntpt}/${stage1LoaderExFAT}" ${targetDeviceRaw}
echo "${stage1LoaderExFAT} (ExFAT) writed to ${targetDeviceRaw}."
fi
}
if [ ${partitiontable} = "GUID_partition_scheme" ]; then
echo "Confirm this is a GPT partitioned disk."
WRITE_STAGE1_FAT32() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 FAT32:"
$localdd if=${targetDeviceRaw} count=1 bs=512 of="${v_mntpt}/origbs"
cp "${i386Dir}/${stage1LoaderFAT}" "${v_mntpt}/newbs"
$localdd if="${v_mntpt}/origbs" of="${v_mntpt}/newbs" skip=3 seek=3 bs=1 count=87 conv=notrunc
$localdd if="${v_mntpt}/newbs" of="${targetDeviceRaw}" count=1 bs=512
# Double check we can see the selected partition and it's of the right type.
# The following script returns either 0 or 1 to proceed, or 2 to indicate failure.
echo "${stage1LoaderFAT} (Fat32) writed to ${targetDeviceRaw}."
fi
}
# --------------------------------------------------------------------------------------------------------
# Writing stage 2
WRITE_STAGE2() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 2:"
cp -R "${i386Dir}/${stage2Loader}" "${choicedVolume}/"
chflags hidden "${choicedVolume}/${stage2Loader}"
echo "Stage 2 (boot) writed to ${choicedVolume}."
fi
}
# --------------------------------------------------------------------------------------------------------
# Waiting for targhet Volume was re-mounted before proceeding..
# Note: the target Volume is umonted by boot1-install that also take the step to remount it (only waiting..)
WAIT_REMOUNT() {
if [ $InstallBootloader = "1" ];then
if [ ! -d "${choicedVolume}" ]; then
echo -e "${mainLine}\nWAITING TO RE-MOUNT ${choicedVolume}:"
until [ -d "${choicedVolume}" ]; do
sleep 0.3
done
echo "${choicedVolume} is mounted!"
fi
fi
}
# --------------------------------------------------------------------------------------------------------
# Extra folder...
EXTRA() {
echo -e "${mainLine}\nEXTRA FOLDER:"
if [ ! -d "${choicedVolume}/Extra" ]; then
echo "Extra not found on ${choicedVolume}, creating.."
mkdir -p "${v_mntpt}/Extra"
/usr/libexec/PlistBuddy -c "Add :'Kernel Flags' string -v" "${v_mntpt}/Extra/org.chameleon.Boot.plist"
else
echo "Extra folder already exist on ${choicedVolume}, copying to the Ram Disk.."
cp -R "${choicedVolume}/Extra" "${v_mntpt}"/
./clean_bootplist.pl "${v_mntpt}" >/dev/null
fi
}
# --------------------------------------------------------------------------------------------------------
# Preparing Backing up of Chameleon files
BACKUP() {
echo -e "${mainLine}\nBACKUP CHAMELEON FILES:"
# Backup Stage 2
if [ $InstallBootloader = "1" ];then
if [ -f "${choicedVolume}/boot" ]; then
echo "Backup stage2 file ${choicedVolume}/boot to ${backupRootDir}/${backupDir}/boot"
cp "${choicedVolume}/boot" "${backupRootDir}/${backupDir}/boot"
else
echo "No stage 2 (boot) was found, nothing to be saved."
fi
fi
# Backup /Extra directory
if [[ -d "${choicedVolume}/Extra" ]];then
echo "Backing up ${choicedVolume}/Extra folder to ${backupRootDir}/${backupDir}/Extra"
cp -pR "${choicedVolume}/Extra" "${backupRootDir}/${backupDir}"/
else
echo "No Extra folder was found, nothing to be saved."
fi
}
# --------------------------------------------------------------------------------------------------------
if [ ! -d "${v_mntpt}" ]; then
echo "Ram Disk not found!"
exit
fi
"$scriptDir"CheckProceed.sh "${targetVolume}" "${targetDeviceChosenByUser}" "${targetVolumeChosenByUser}" "${scriptDir}"
returnValue=$?
if [ ${returnValue} -ne 2 ]; then
# OK to proceed
exec > >(tee -a "${logFile}") 2>&1
# Remember if the target volume has an EFI system partition.
if [ ${returnValue} -ne 1 ]; then
efiPartitionExist=1
fi
echo "$mainLine"
echo "Main ESP Post-Install Script"
echo "Chameleon installer log - $( date )"
if [ $InstallBootloader = "1" ];then echo "$versionToInstall"; else echo "no boot session"; fi
echo ""
# Does a GRUB or Linux loader already exist in the disk's MBR?
# The script returns 1 if yes, 0 if no.
SCAN
"$scriptDir"CheckGRUBLinuxLoader.sh "${targetDisk}" "${targetVolumeChosenByUser}" "${scriptDir}"
returnValue=$?
if [ ${returnValue} = 0 ]; then
# OK to proceed
# (adjusted from Clover)
if [ ! "${targetDevice#*disk*s}" ]; then
echo
echo "*** ERROR: Volume does not use slices!"
echo
exit 1
fi
if [ "${InstallToESP}" == "1" ]; then
echo "$mainLine"
echo "SEARCHING ESP PARTITION:"
case "$IOContent" in
GUID_partition_scheme)
echo "GPT partition Scheme detected.."
espDisk="${targetDisk}s1"
if [ $( LC_ALL=C diskutil info ${espDisk} | grep -i 'Partition Type:' | \
awk '{print $NF}' ) = "EFI" ]; then
echo "EFI partition found is ${espDisk}, try to mount it.."
MOUNT_ESP
else
echo "EFI was not fount, continue installing to ${targetVolume}"
choicedVolume="${targetVolume}"
fi
;;
*)
echo "Can't install on the ESP, because does not exist.."
echo "..continue installing to ${targetVolume}"
;;
esac
else
SCAN
fi
# check for a 4-byte Windows disk signature in the disk's MBR.
# the following script returns 1 if a Windows disk signature exists, and 0 if not.
"$scriptDir"CheckWindowsDiskSignature.sh "${targetDisk}" "${targetVolumeChosenByUser}" "${scriptDir}"
diskSigCheck=$?
if [ -d "${HOME}/Desktop/DebugChameleon" ]; then
DEBUG
fi
# adding the chosen Volume dev id to the InstallConfig.plist
/usr/libexec/PlistBuddy -c "Add :targetdev string ${targetDevice}" $configFile
# check for existing bootloaders in the disk's MBR
# and find out if we can write the Chameleon boot files.
# the following script returns 0 if we can proceed
# with writing the boot files, and 1 for not.
BACKUP
EXTRA
"$scriptDir"CheckDiskMicrocode.sh "${targetDisk}" "${diskSigCheck}" "${targetVolumeChosenByUser}" "${scriptDir}"
diskupdate=$?
echo "${mainLine}"
CHECK_FAT16
case "$FS" in
hfs)
echo "${targetDevice} is HFS formatted"
WRITE_STAGE0 hfs
WRITE_STAGE1_HFS
;;
msdos)
echo "${targetDevice} is FAT32 formatted"
WRITE_STAGE0 msdos
WRITE_STAGE1_FAT32
;;
exfat)
echo "${targetDevice} is ExFAT formatted"
WRITE_STAGE0 exfat
WRITE_STAGE1_EXFAT
WAIT_REMOUNT
;;
*)
echo "FileSystem unsupported, aborting!"
exit 0
;;
esac
WRITE_STAGE2
PARTITION_ACTIVE_IF
# check the format of the selected partition.
# result should be either hfs or msdos
# Should really check to make sure!
echo "$mainLine"
echo "END - ESP Post-Install Script"
# --------------------------------------------------------------------------------------------------------
targetFormat=$( fstyp "$targetDevice" )
# Append a LineBreak to the installer log
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "LineBreak"
if [ ${diskupdate} = "0" ]; then
# Write the stage 0 loader to the MBR
"$scriptDir"WriteChameleonStage0.sh "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetResources}" "${targetVolumeChosenByUser}" "${scriptDir}"
else
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Stage 0 loader not written to ${targetDisk}."
fi
# Write the stage 1 loader to the partition boot sector
"$scriptDir"WriteChameleonStage1.sh "${targetFormat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${targetVolumeChosenByUser}" "${targetDeviceRaw}" "${targetVolumeChosenByUser}" "${scriptDir}"
# Unmount ALL mounted volumes named EFI.
# Returns 0=success, 1=fail
"$scriptDir"UnMountEFIvolumes.sh "${targetVolumeChosenByUser}" "${scriptDir}"
returnValue=$?
if [ ${returnValue} = 0 ]; then
# OK to proceed
# Mount the EFI system partition
"$scriptDir"MountESP.sh "${targetDisk}" "${targetVolumeChosenByUser}" "${efiPartitionExist}" "${scriptDir}"
# Write the stage 2 loader to the root of the selected partition
"$scriptDir"WriteChameleonStage2.sh "${stage2Loader}" "${targetVolume}" "${targetDevice}" "${targetVolumeChosenByUser}" "${scriptDir}"
# Check for another existing Chameleon installation on the same disk
"$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak"
"$scriptDir"InstallLog.sh "${targetVolume}" "Preparing to check target disk for previous installations."
"$scriptDir"CheckPreviousChameleon.sh "${targetDisk}" "${targetDeviceRaw}" "${targetDevice}" "${targetVolumeChosenByUser}" "${scriptDir}"
fi
# Append a LineBreak to the installer log
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "LineBreak"
# Set the active partition ONLY if Windows is not installed
"$scriptDir"SetActivePartition.sh "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolumeChosenByUser}" "${scriptDir}"
fi
fi
else
#echo "ERROR Volume is not on a GPT partitioned disc."
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "ERROR Volume is not on a GPT partitioned disc."
fi
# Create temporary file on target volume to notify Postinstall
# script, boot option code, that EFI (ESP) option was chosen
echo "EFI" >"${targetVolumeChosenByUser}"/.ChameleonEFI
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "LineBreak"
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "EFI script complete"
echo "==============================================="
echo "END - Main EFI System Partition Post-Install Script"
echo "*********************************************"
echo "-----------------------------------------------"
echo ""
exit 0
branches/ErmaC/Enoch/package/Scripts/Main/Standardpostinstall
11
22
3
4
5
6
7
3
4
5
6
7
8
9
10
811
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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
3434
3535
3636
3737
38
3839
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
3958
40
41
42
43
44
45
46
47
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
4898
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
49115
50
51
52
53
54
116
117
118
119
120
121
122
123
124
55125
56
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
57145
58
59
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
60161
61
62
63
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
64186
65
66
67
68
69
70
71
72
73
74
75
76
77
78
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
79213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
80229
81
82
83
230
231
232
233
234
235
236
237
238
239
240
241
242
84243
85
86
244
245
246
247
248
249
250
251
252
87253
88
89
90
91
92
93
94
95
96
254
255
256
257
258
259
260
97261
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
114316
317
318
319
320
321
322
323
324
325
326
327
328
329
115330
116
117
118
119
331
120332
333
334
335
336
337
121338
122
123
124
125
339
126340
341
342
343
344
345
346
347
127348
128
129
130
131
132
133
134
135
136
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
137373
138
139
140
141
142
143
144374
145
146
147
148
149
375
376
377
150378
151
152
379
380
153381
154
155
156
157
158
159
382
383
160384
161
162
163
164
165
166
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
167409
168
169
410
411
170412
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
413
200414
201
202
203
415
204416
205417
#!/bin/bash
echo "==============================================="
echo "Main Standard Post-Install Script"
echo "*********************************"
echo "-----------------------------------------------"
echo ""
# --------------------------------------------------------------------------------------------------------
# Install.sh v1.3, script to install Chameleon
# Created by Miky1979 on December 8th, 2014
# --------------------------------------------------------------------------------------------------------
targetVolume="${3}"
InstallToESP="0"
InstallBootloader="0"
configFile="/private/tmp/InstallConfig.plist"
# Find location of this script in the package installer
# so we know where all the other scripts are located.
MYLOCATION="${PWD}/${BASH_ARGV[0]}"
export MYLOCATION="${MYLOCATION%/*}"
scriptDir=$MYLOCATION
#echo "==============================================="
#echo "Apple Installer Package Variables"
#echo "*********************************"
#echo "DEBUG: $ 1 = Full path to the installation package the installer app is processing: " $1
#echo "DEBUG: $ 2 = Full path to the installation destination: " $2
#echo "DEBUG: $ 3 = Installation volume (mountpoint) to receive the payload: " $3
#echo "DEBUG: $ 4 = Root directory for the system: " $4
#echo "DEBUG: Script Name: " $SCRIPT_NAME
#echo "DEBUG: Package Path: " $PACKAGE_PATH
#echo "DEBUG: Installer Temp: " $INSTALLER_TEMP
#echo "DEBUG: Full path to the temp directory containing the operation executable: " $RECEIPT_PATH
#echo "-----------------------------------------------"
#echo ""
# Initialise Script Globals
if [[ $( /usr/libexec/PlistBuddy -c "Print bootloader" ${configFile} ) == "true" ]];then
# installing stage 0, 1 and 2 only if user want this:
# ie only if have no selected noboot choice
InstallBootloader="1"
fi
# --------------------------------------------------------------------------------------------------------
if [ ! -d "${targetVolume}" ]; then echo "target Volume not found, aborting!"; exit 1; fi
# --------------------------------------------------------------------------------------------------------
i386Dir="${targetVolume}/usr/standalone/i386"
usrLocalBin="${targetVolume}/usr/local/bin"
# --------------------------------------------------------------------------------------------------------
choicedVolume="${targetVolume}"
ESP_MOUNTED="0"
# --------------------------------------------------------------------------------------------------------
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//')
backupRootDir="${targetVolume}/Chameleon.Backups"
backupDir=$( /usr/libexec/PlistBuddy -c "Print :backupDir" ${configFile} )
logName="Chameleon_Installer_Log.txt"
logFile="${v_mntpt}/${logName}"
# --------------------------------------------------------------------------------------------------------
stage0Loader="boot0"
stage0LoaderDualBoot="boot0md"
stage1LoaderHFS="boot1h"
stage1LoaderFAT="boot1f32"
stage1LoaderExFAT="boot1x"
stage2Loader="boot"
versionToInstall=$(cat "${i386Dir}/Boot" | grep -a 'Darwin/x86 boot v' )
# --------------------------------------------------------------------------------------------------------
localdd="/bin/dd"
SS="${usrLocalBin}/sectorsize"
# --------------------------------------------------------------------------------------------------------
# Scanning all Variables. We are switching to the target Volume or its ESP.
# This function is usefull to rescan the new target "at need"
SCAN() {
targetDevice=$( LC_ALL=C diskutil info "${choicedVolume}" | grep -i 'Device Node:' | awk '{print $NF}' )
targetDeviceRaw=${targetDevice/disk/rdisk}
targetDisk=${targetDevice%s*}
targetDiskRaw=${targetDisk/disk/rdisk}
targetSlice=${targetDevice#*disk*s}
IOContent=$( LC_ALL=C diskutil info "${targetDisk}" | grep -i 'Content (IOContent)' | awk '{print $NF}' )
FS=$( LC_ALL=C diskutil info ${targetDevice} | grep -i 'Type (Bundle)' | \
awk '{print $NF}' | awk '{print tolower($0)}' )
disksignature=$( dd 2>/dev/null if="${targetDisk}" count=1 | dd 2>/dev/null count=4 bs=1 skip=440 | \
perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
# If target volume root of current system then replace
# / with volume name.
if [ "$3" == "/" ]
then
targetVolume="/Volumes/"$( ls -1F /Volumes | sed -n 's:@$::p' )
else
targetVolume="$3"
fi
if [ $InstallBootloader = "1" ];then
blocksize=$( "${SS}" "${targetDeviceRaw}" | awk '{ print $2 }' )
fi
}
# --------------------------------------------------------------------------------------------------------
# lines
mainLine="=============================================================================="
subLine="------------------------------------------------------------------------------"
# --------------------------------------------------------------------------------------------------------
# Debug for Chameleon.
# Create a folder inside the Desktop called "DebugChameleon", and the log will be full
DEBUG() {
echo "$mainLine"
echo "DEBUG: display script variables (Standardpostinstall)"
echo "$mainLine"
echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader} (or boot0hfs)"
echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot} (or boot0hfs)"
echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
echo "DEBUG: stage1LoaderExFAT: Partition loader is ${stage1LoaderExFAT}"
echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"
echo "DEBUG: targetVolume: Volume is ${targetVolume}"
echo "DEBUG: targetDevice: Volume device is ${targetDevice}"
echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"
echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
echo "DEBUG: versionToInstall: version to install is ${versionToInstall}"
echo "DEBUG: IOContent: partition scheme is ${IOContent}"
echo "DEBUG: FS: file System is ${FS}"
if [ $InstallBootloader = "1" ];then
echo "DEBUG: blocksize: block size detected = ${blocksize}-bytes"
fi
}
# --------------------------------------------------------------------------------------------------------
# Checking for unsupported FAT16 filesystem
CHECK_FAT16() {
pers=$( LC_ALL=C diskutil info "${targetDeviceRaw}" | grep -i 'File System Personality' \
| awk '{print $NF}' | awk '{print tolower($0)}' )
case $pers in
fat16)
echo "** ERROR: Can't Install to a device using FAT16!"
exit 1
;;
*)
echo "First Check Passed!"
;;
esac
}
# --------------------------------------------------------------------------------------------------------
# Mount or umount the ESP..or leave as is if already mounted..
UMOUNT_ESP_DISK() {
# umount the ESP by its dev
umount -f $espDisk
}
targetDevice=$( df "${targetVolume}" | sed -n '2p' | awk '{print $1}' )
targetDeviceRaw=${targetDevice/disk/rdisk}
targetDisk=${targetDevice%s*}
targetDiskRaw=${targetDisk/disk/rdisk}
targetSlice=${targetDevice#*disk*s}
CHECK_ESP_MOUNTPOINT() {
# umount the ESP by its Mount Point
# and checking it if is busy by another ESP
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \
grep -x '/Volumes/ESP' ) ]; then
umount -f /Volumes/ESP
ESP_MOUNTED="0"
fi
}
targetResources="${targetVolume}/usr/local/bin/"
MOUNT_ESP() {
ESP_MOUNTED="1" # ..assuming that the ESP can be already mounted..
if [ $( df | grep "${espDisk}" | awk '{print $1}' | grep -x "${espDisk}" ) ];then
# ESP is already mounted, so now we aquire the Mount Point
espmtp=$( LC_ALL=C diskutil info ${espDisk} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^[ \t]*//' )
if [ -d "${espmtp}" ];then
echo "ESP Mount Point is:${espmtp}, using that as target Volume!"
choicedVolume="${espmtp}"
SCAN
else
echo "The mount point was not found, try to umount it to get the standard one.."
UMOUNT_ESP_DISK
CHECK_ESP_MOUNTPOINT
fi
else
# ESP is not mounted..
ESP_MOUNTED="0"
fi
updateStage1=1 # by default update partition boot sector
efiPartitionExist=0 # target volume does not have EFI system partition.
if [ $ESP_MOUNTED = "0" ];then
mkdir -p /Volumes/ESP
case $( fstyp $espDisk ) in
hfs)
mount -t hfs $espDisk /Volumes/ESP
;;
msdos)
mount -t msdos $espDisk /Volumes/ESP
;;
*)
echo "ESP fileSystem unsupported, Installing to ${targetVolume}!"
choicedVolume="${targetVolume}"
;;
esac
sleep 0.3
echo "==============================================="
echo "DEBUG: display script variables"
echo "*******************************"
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \
grep -x '/Volumes/ESP' ) ]; then
ESP_MOUNTED="1"
choicedVolume="/Volumes/ESP"
SCAN
else
echo "ESP can't be mounted, Installing to ${targetVolume}!"
choicedVolume="${targetVolume}"
fi
fi
}
# --------------------------------------------------------------------------------------------------------
PARTITION_ACTIVE_IF() {
echo -e "${mainLine}\nSET PARTITION ACTIVE:"
# if Windows was detected, don't activate the partition..
# if the stage 0 loader is boo0hfs, don't activate the partition
if [ WINDOWS_EXIST = "0" ] || [ "${stage0Loader}" != "boot0hfs" ];then
partitionactive=$( fdisk -d ${targetDiskRaw} | grep -n "*" | awk -F: '{print $1}')
if [ "${partitionactive}" ] && [ "${partitionactive}" = "${targetSlice}" ]; then
echo "${targetDiskRaw#/dev/r}, slice "${targetSlice}" is already set active. No need to change it."
else
echo "Setting ${choicedVolume} partition active."
# BadAxe requires EFI partition to be flagged active.
# but it doesn't' hurt to do it for any non-windows partition.
echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"
echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot}"
echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"
echo "DEBUG: targetVolume: Volume is ${targetVolume}"
echo "DEBUG: targetDevice: Volume device is ${targetDevice}"
echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"
echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
echo "DEBUG: targetResources: Boot Resources is ${targetResources}"
echo "-----------------------------------------------"
echo ""
# leave left aligned the follow code:
fdisk -e ${targetDiskRaw} <<-MAKEACTIVE
print
flag ${targetSlice}
write
y
quit
MAKEACTIVE
fi
else
echo "Partition will not activate when Windows is detected or stage 0 is boot0hfs"
fi
echo ""
echo "$mainLine"
}
# --------------------------------------------------------------------------------------------------------
# Writing stage 0
CHECK_WINDOWS() {
WINDOWS_EXIST="0"
if [ "${disksignature}" = "00000000" ]; then
echo "Windows installation not found on ${targetDisk}."
else
echo "Windows installation found on ${targetDisk}."
WINDOWS_EXIST="1"
fi
}
WRITE_STAGE0() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 0:"
CHECK_WINDOWS
case "$1" in
hfs)
if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0hfs"; else stage0Loader="boot0"; fi
;;
msdos)
if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0md"; else stage0Loader="boot0";fi
;;
exfat)
stage0Loader="boot0"
;;
esac
# Write some information to the Install Log
"$scriptDir"InstallLog.sh "${targetVolume}" "Running Standard postinstall script"
"$scriptDir"InstallLog.sh "${targetVolume}" "Target volume = ${targetVolume} on ${targetDevice}"
"${usrLocalBin}/fdisk440" -u -f "${i386Dir}/${stage0Loader}" -y ${targetDisk}
echo "${stage0Loader} writed to ${targetDisk}"
fi
}
# --------------------------------------------------------------------------------------------------------
# Writing stage 1 on different filesystems
WRITE_STAGE1_HFS() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 HFS:"
$localdd if="${i386Dir}/${stage1LoaderHFS}" of=${targetDeviceRaw}
echo "${stage1LoaderHFS} (hfs) writed to ${targetDeviceRaw}."
fi
}
# Double check we can see the selected partition and it's of the right type.
# The following script returns either 0 or 1 to proceed, or 2 to indicate failure.
WRITE_STAGE1_EXFAT() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 ExFAT:"
cp -R "${usrLocalBin}/boot1-install" "${v_mntpt}"/
cp -R "${i386Dir}/${stage1LoaderExFAT}" "${v_mntpt}"/
"${v_mntpt}/boot1-install" -y -u -f "${v_mntpt}/${stage1LoaderExFAT}" ${targetDeviceRaw}
echo "${stage1LoaderExFAT} (ExFAT) writed to ${targetDeviceRaw}."
fi
}
"$scriptDir"CheckProceed.sh "${targetVolume}" "${targetDevice}" "${targetVolume}" "${scriptDir}"
returnValue=$?
if [ ${returnValue} -ne 2 ]; then
# OK to proceed
# Remember if the target volume has an EFI system partition.
if [ ${returnValue} -ne 1 ]; then
efiPartitionExist=1
fi
WRITE_STAGE1_FAT32() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 FAT32:"
$localdd if=${targetDeviceRaw} count=1 bs=512 of="${v_mntpt}/origbs"
cp "${i386Dir}/${stage1LoaderFAT}" "${v_mntpt}/newbs"
$localdd if="${v_mntpt}/origbs" of="${v_mntpt}/newbs" skip=3 seek=3 bs=1 count=87 conv=notrunc
$localdd if="${v_mntpt}/newbs" of="${targetDeviceRaw}" count=1 bs=512
# Does a GRUB or Linux loader already exist in the disk's MBR?
# The script returns 1 if yes, 0 if no.
"$scriptDir"CheckGRUBLinuxLoader.sh "${targetDisk}" "${targetVolume}" "${scriptDir}"
diskupdate=$?
if [ ${diskupdate} -ne 0 ]; then
"$scriptDir"InstallLog.sh "${targetVolume}" "Found an existing GRUB/LILO bootloader in the MBR."
"$scriptDir"InstallLog.sh "${targetVolume}" "MBR and partition boot sector will not be modified."
updateStage1=0
else
# check for existing bootloaders in the disk's MBR
# and find out if we can write the Chameleon boot files.
# the following script returns 0 if we can proceed
# with writing the boot files, and 1 for not.
"$scriptDir"CheckDiskMicrocode.sh "${targetDisk}" "${diskSigCheck}" "${targetVolume}" "${scriptDir}"
diskupdate=$?
fi
echo "${stage1LoaderFAT} (Fat32) writed to ${targetDeviceRaw}."
fi
}
# --------------------------------------------------------------------------------------------------------
# Writing stage 2
WRITE_STAGE2() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 2:"
cp -R "${i386Dir}/${stage2Loader}" "${choicedVolume}/"
chflags hidden "${choicedVolume}/${stage2Loader}"
echo "Stage 2 (boot) writed to ${choicedVolume}."
fi
}
# --------------------------------------------------------------------------------------------------------
# Waiting for targhet Volume was re-mounted before proceeding..
# Note: the target Volume is umonted by boot1-install that also take the step to remount it (only waiting..)
WAIT_REMOUNT() {
if [ $InstallBootloader = "1" ];then
if [ ! -d "${choicedVolume}" ]; then
echo -e "${mainLine}\nWAITING TO RE-MOUNT ${choicedVolume}:"
until [ -d "${choicedVolume}" ]; do
sleep 0.3
done
echo "${choicedVolume} is mounted!"
fi
fi
}
# --------------------------------------------------------------------------------------------------------
# Extra folder...
EXTRA() {
echo -e "${mainLine}\nEXTRA FOLDER:"
if [ ! -d "${choicedVolume}/Extra" ]; then
echo "Extra not found on ${choicedVolume}, creating.."
mkdir -p "${v_mntpt}/Extra"
/usr/libexec/PlistBuddy -c "Add :'Kernel Flags' string -v" "${v_mntpt}/Extra/org.chameleon.Boot.plist"
else
echo "Extra folder already exist on ${choicedVolume}, copying to the Ram Disk.."
cp -R "${choicedVolume}/Extra" "${v_mntpt}"/
./clean_bootplist.pl "${v_mntpt}" >/dev/null
fi
}
# --------------------------------------------------------------------------------------------------------
# Preparing Backing up of Chameleon files
BACKUP() {
echo -e "${mainLine}\nBACKUP CHAMELEON FILES:"
# Backup Stage 2
if [ $InstallBootloader = "1" ];then
if [ -f "${choicedVolume}/boot" ]; then
echo "Backup stage2 file ${choicedVolume}/boot to ${backupRootDir}/${backupDir}/boot"
cp "${choicedVolume}/boot" "${backupRootDir}/${backupDir}/boot"
else
echo "No stage 2 (boot) was found, nothing to be saved."
fi
fi
# Backup /Extra directory
if [[ -d "${choicedVolume}/Extra" ]];then
echo "Backing up ${choicedVolume}/Extra folder to ${backupRootDir}/${backupDir}/Extra"
cp -pR "${choicedVolume}/Extra" "${backupRootDir}/${backupDir}"/
else
echo "No Extra folder was found, nothing to be saved."
fi
}
# --------------------------------------------------------------------------------------------------------
if [ ! -d "${v_mntpt}" ]; then
echo "Ram Disk not found!"
exit
fi
# check for a 4-byte Windows disk signature in the disk's MBR.
# the following script returns 1 if a Windows disk signature exists, and 0 if not.
"$scriptDir"CheckWindowsDiskSignature.sh "${targetDisk}" "${targetVolume}" "${scriptDir}"
diskSigCheck=$?
exec > >(tee -a "${logFile}") 2>&1
echo "$mainLine"
echo "Main Standard Post-Install Script"
echo "Chameleon installer log - $( date )"
if [ $InstallBootloader = "1" ];then echo "$versionToInstall"; else echo "no boot session"; fi
echo ""
# check the format of the selected partition.
# result should be either hfs or msdos
# Should really check to make sure!
targetFormat=$( fstyp "$targetDevice" )
SCAN
# (adjusted from Clover)
if [ ! "${targetDevice#*disk*s}" ]; then
echo
echo "*** ERROR: Volume does not use slices!"
echo
exit 1
fi
# check the partition scheme used for the selected disk.
# the following script returns 1 if GPT
# the following script returns 2 if GPT/MBR
# the following script returns 3 if MBR
# the following script returns 0 if nothing
"$scriptDir"CheckPartitionScheme.sh "${targetDisk}" "${targetVolume}" "${scriptDir}"
partitionScheme=$?
if [ ${partitionScheme} = 3 ]; then
# If MBR partition scheme then check for FAT16 or FAT32
if [ "${InstallToESP}" == "1" ]; then
echo "$mainLine"
echo "SEARCHING ESP PARTITION:"
case "$IOContent" in
GUID_partition_scheme)
echo "GPT partition Scheme detected.."
espDisk="${targetDisk}s1"
if [ $( LC_ALL=C diskutil info ${espDisk} | grep -i 'Partition Type:' | \
awk '{print $NF}' ) = "EFI" ]; then
echo "EFI partition found is ${espDisk}, try to mount it.."
MOUNT_ESP
else
echo "EFI was not fount, continue installing to ${targetVolume}"
choicedVolume="${targetVolume}"
fi
;;
*)
echo "Can't install on the ESP, because does not exist.."
echo "..continue installing to ${targetVolume}"
;;
esac
else
SCAN
fi
# the following script returns 1 if FAT16
# the following script returns 2 if FAT32
# the following script returns 0 if nothing
"$scriptDir"CheckFatType.sh "${targetDeviceRaw}" "${targetVolume}" "${scriptDir}"
fatType=$?
fi
if [ "${fatType}" = 1 ] && [ "${partitionScheme}" = 3 ]; then
# Write error to Chameleon_Error_Log file
"$scriptDir"InstallLog.sh "${targetVolume}" "FAIL: Cannot install to a device using FAT16"
else
# Continue if the selected device is not a FAT16 format device
if [ -d "${HOME}/Desktop/DebugChameleon" ]; then
DEBUG
fi
# Append a line break to the installer log
"$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak"
# adding the chosen Volume dev id to the InstallConfig.plist
/usr/libexec/PlistBuddy -c "Add :targetdev string ${targetDevice}" $configFile
if [ ${diskupdate} -eq 0 ]; then
# Write the stage 0 loader to the MBR
"$scriptDir"WriteChameleonStage0.sh "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetResources}" "${targetVolume}" "${scriptDir}"
else
"$scriptDir"InstallLog.sh "${targetVolume}" "Stage 0 loader not written to ${targetDisk}."
fi
BACKUP
EXTRA
if [ ${updateStage1} -eq 1 ]; then
# Write the stage 1 loader to the partition boot sector
"$scriptDir"WriteChameleonStage1.sh "${targetFormat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${3}" "${targetDeviceRaw}" "${targetVolume}" "${scriptDir}"
else
"$scriptDir"InstallLog.sh "${targetVolume}" "Partition boot sector not written to ${targetDevice}."
fi
echo "${mainLine}"
CHECK_FAT16
case "$FS" in
hfs)
echo "${targetDevice} is HFS formatted"
WRITE_STAGE0 hfs
WRITE_STAGE1_HFS
;;
msdos)
echo "${targetDevice} is FAT32 formatted"
WRITE_STAGE0 msdos
WRITE_STAGE1_FAT32
;;
exfat)
echo "${targetDevice} is ExFAT formatted"
WRITE_STAGE0 exfat
WRITE_STAGE1_EXFAT
WAIT_REMOUNT
;;
*)
echo "FileSystem unsupported, aborting!"
exit 0
;;
esac
# Write the stage 2 loader to the root of the selected partition
"$scriptDir"WriteChameleonStage2.sh "${stage2Loader}" "${3}" "${targetDevice}" "${targetVolume}" "${scriptDir}"
WRITE_STAGE2
PARTITION_ACTIVE_IF
# Next we look to check for existing Chameleon installations.
"$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak"
"$scriptDir"InstallLog.sh "${targetVolume}" "Preparing to check target disk for previous installations."
if [ ${efiPartitionExist} -ne 0 ]; then # volume has an EFI system partition
"$scriptDir"InstallLog.sh "${targetVolume}" "Going to check the EFI system partition also."
# Unmount ALL mounted volumes named EFI. Returns 0=success, 1=fail
"$scriptDir"UnMountEFIvolumes.sh "${targetVolume}" "${scriptDir}"
returnValue=$?
if [ ${returnValue} = 0 ]; then
# Mount the EFI system partition
"$scriptDir"MountESP.sh "${targetDisk}" "${targetVolume}" "${efiPartitionExist}" "${scriptDir}"
fi
fi
# Check for another existing Chameleon installation on the same disk
"$scriptDir"CheckPreviousChameleon.sh "${targetDisk}" "${targetDeviceRaw}" "${targetDevice}" "${targetVolume}" "${scriptDir}"
# Append a line break to the installer log
"$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak"
# Set the active partition ONLY if Windows is not installed
"$scriptDir"SetActivePartition.sh "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolume}" "${scriptDir}"
fi
fi
"$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak"
"$scriptDir"InstallLog.sh "${targetVolume}" "Standard script complete"
"$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak"
echo "==============================================="
echo "$mainLine"
echo "END - Standard Post-Install Script"
echo "*********************************"
echo "-----------------------------------------------"
echo ""
# --------------------------------------------------------------------------------------------------------
exit 0
branches/ErmaC/Enoch/package/Scripts/Sub/CheckPreviousChameleon.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
184
185
186
187
#!/bin/bash
echo "==============================================="
echo "Check Previous Chameleon: Will there be problems?"
echo "***********************************************"
# Checks for another existing Chameleon installation on the same disk
# and tries to make sure the user doesn't end up with an un-bootable
# system due to having installed Chameleon previously elsewhere.
# Called from the Standard/postinstall and EFI/postinstall scripts
# /Volumes/EFI should already be mounted before this is called.
# Receives targetDisk: for example, /dev/disk3.
# Receives targetDeviceRaw: for example, /dev/rdisk3s1.
# Receives targetDevice: Stores device number, for example /dev/disk2s1.
# Receives installerVolume: Volume to write the installer log to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 5 ]; then
targetDisk="$1"
targetDeviceRaw="$2"
targetDevice="$3"
installerVolume="$4"
scriptDir="$5"
echo "DEBUG: passed argument for targetDisk = $targetDisk"
echo "DEBUG: passed argument for targetDeviceRaw = $targetDeviceRaw"
echo "DEBUG: passed argument for targetDevice = $targetDevice"
echo "DEBUG: passed argument for installerVolume = $installerVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
# ===============================================
# Prepare some vars
# ===============================================
sliceNumber=$( echo ${targetDeviceRaw#*disk*s} )
# strip slice from end
targetDiskRawNoSlice=$( echo ${targetDeviceRaw%$sliceNumber} )
# Are there any other partitions on the disk?
# How many actual partitions are there?
numSlices=$(( $( diskutil list | grep $( echo ${targetDisk#/dev/} ) | sed -n '$=' ) -2 ))
# ===============================================
# Checking the disk for existing Chameleon installations
# if there is more than one partition on the disk.
# ===============================================
if [ $numSlices -gt 1 ]; then
"$scriptDir"InstallLog.sh "${installerVolume}" "Checking ${targetDisk#/dev/}."
# Check the disk's MBR for existing stage 0 boot code (code from CheckDiskMicrocode.sh script)
stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )
if [ "${stage0type}" == "0a803c" ] || [ "${stage0type}" == "ee7505" ] || [ "${stage0type}" == "742b80" ]; then
stage0type=2
elif [ "${stage0type}" == "0b807c" ]; then
stage0type=1
fi
#Scan all partitions for Chameleon code
cleanRun=1
for (( i=1; i <= $numSlices; i++ ));
do
if [ $stage0type == 1 ] || [ $stage0type == 2 ]; then
stagesFound=1
else
stagesFound=0
fi
stage1Existence="NONE"
stage2Existence=0
targetDiskRaw=$targetDiskRawNoSlice$i
# Check for existence of a bootable partition boot sector containing either boot1h or boot1f32
boot1Search=$( dd 2>/dev/null if="$targetDiskRaw" count=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
if [ "${boot1Search:0:16}" == "fa31c08ed0bcf0ff" ] && [ "${boot1Search:1020:2}" == "55" ]; then
(( stagesFound++ ))
stage1Existence="boot1h"
elif [ "${boot1Search:0:4}" == "e962" ] && [ "${boot1Search:180:12}" == "424f4f542020" ] && [ "${boot1Search:1020:2}" == "55" ]; then
(( stagesFound++ ))
stage1Existence="boot1f32"
fi
# Check for existing stage 2 boot file.
# Include checking the EFI system partition if it exists and is mounted.
if [ -e "$( df | grep ${targetDisk}s${i} | awk '{ print $6 }' )"/boot ]; then
(( stagesFound++ ))
stage2Existence=1
fi
if [ $stagesFound -ge 2 ] && [ "$stage1Existence" != "NONE" ] && [ $i -ne $sliceNumber ]; then
# There is previous Chameleon stage 1 code on a partition boot sector,
# and either a complete or incomplete installation (ie. boot0 or boot are missing).
if [ $stagesFound == 3 ] && [ $i -lt $sliceNumber ]; then
# Exisitng installation found which will still be default.
message="************************** TAKE NOTE *****************************
**** There is an existing Chameleon installation on $targetDiskRaw
**** and that installation will still be the default loader as it's
**** on an earlier partition. If you want this new installation on
**** $installerVolume to be default then you will need to remove the
**** boot file from $targetDiskRaw and re-run this installer.
**************************************************************"
"$scriptDir"InstallLog.sh "${installerVolume}" "${message}"
fi
if [ $stagesFound == 3 ] && [ $i -gt $sliceNumber ]; then
# Existing installation found which will no longer be default.
message="NOTE: There is an existing Chameleon installation on $targetDiskRaw
NOTE: but this installation on $targetDevice will be the default loader
NOTE: because you're installing to an earlier partition on the disk."
"$scriptDir"InstallLog.sh "${installerVolume}" "${message}"
fi
# User could see a b1f:error or boot0:error if the following conditions are true:
# A) Boot0hfs, Boot0md or Boot0md (dmazar's Boot0workV2) is being used.
# B) The previous stage 1 code is on a lower partiton than the one being installed to now.
# C) boot is missing from that partition.
if [ $stagesFound == 2 ] && [ $stage2Existence == 0 ]; then
# Exisitng boot0 and boot1 only found - missing boot
"$scriptDir"InstallLog.sh "${installerVolume}" "INFO: Found $stage1Existence installed to ${targetDisk}s${i}"
# stage0type=2 is used to know if 'A' is true.
if [ $stage0type == 2 ]; then
# i = current slice we're checking, slicenumber = slice trying to install to.
if [ $i -lt $sliceNumber ]; then
"$scriptDir"InstallLog.sh "${installerVolume}" "WARN: Conditions point to the possibility of a boot failure"
# Fix by making previous parition bootsector un-bootable
message="---
FIX: Make ${targetDisk}s${i} boot sector un-bootable by changing byte 1FEh to 00.
NOTE: Any Extra folder you had there will still be there. If you want to use
NOTE: ${targetDisk}s${i} again as your boot partition then re-run this installer
NOTE: selecting it as the target, ONLY choosing the 'Chameleon Bootloader' option
NOTE: and NONE of the other options.
---"
"$scriptDir"InstallLog.sh "${installerVolume}" "${message}"
# /Volumes/EFI needs unmounting before changing partition boot sector
if [ $i == 1 ]; then
umount /Volumes/EFI
else
diskutil unmount "${targetDisk}"s${i}
fi
# Change Byte 01FExh to 00 (510 decimal)
# Same code can be used for HFS or FAT32
dd if=${targetDisk}s${i} count=1 bs=512 of=/tmp/originalBootSector
cp /tmp/originalBootSector /tmp/newBootSector
dd if="$scriptDir/patch" of=/tmp/newBootSector bs=1 count=1 seek=510 conv=notrunc
dd if=/tmp/newBootSector of=${targetDisk}s${i} count=1 bs=512
# /Volumes/EFI needs re-mounting so EFI/postinstall script can use it.
# Don't check for a GPT as wouldn't have got here if it wasn't
if [ $i == 1 ]; then
"$scriptDir"MountESP.sh "${targetDisk}" "${installerVolume}" "${scriptDir}"
else
diskutil mount "${targetDisk}"s${i}
fi
else
"$scriptDir"InstallLog.sh "${installerVolume}" "INFO: but won't interfere as you're installing to an earlier partition."
fi
elif [ $stage0type == 1 ]; then
# boot0 was found which looks for boot1 on the first active partition.
"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: so select to boot that partition (if used) with active flag."
#else
#echo "DEBUG: Boot0 not found"
fi
fi
else
(( cleanRun++ ))
fi
done
if [[ $cleanRun == $i ]]; then
"$scriptDir"InstallLog.sh "${installerVolume}" "Nothing found that could cause any problems."
fi
else
"$scriptDir"InstallLog.sh "${installerVolume}" "Nothing to check as there's only one partition."
fi
exit 0
branches/ErmaC/Enoch/package/Scripts/Sub/CheckFatType.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
echo "==============================================="
echo "CheckFatType: Do we have FAT16 or FAT32?"
echo "****************************************"
# Looks for the following in the partition boot sector
# Byte number 19 to see if it's either 00 or 02
# Byte number 22 to see if it's either F8 or F0
# Byte number 25 to see if it's either 3F or 20
#
# Exit with value 1 for FAT16, 2 for FAT32
# Exit with value 0 if nothing is found - this shouldn't happen.?
# Receives targetDeviceRaw: for example, /dev/rdisk0s2.
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 3 ]; then
targetDeviceRaw="$1"
targetVolume="$2"
scriptDir="$3"
echo "DEBUG: passed argument = $targetDeviceRaw"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
partitionBootSector=$( dd 2>/dev/null if="$targetDeviceRaw" count=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
if [ "${partitionBootSector:36:2}" == "00" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "3f" ]; then
#echo "DEBUG: Found a FAT32 device formatted by Windows Explorer"
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT32 volume formatted by Windows Explorer"
exit 2
fi
if [ "${partitionBootSector:36:2}" == "02" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "3f" ]; then
#echo "DEBUG: Found a FAT16 device formatted by Windows Explorer"
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT16 volume formatted by Windows Explorer"
exit 1
fi
if [ "${partitionBootSector:36:2}" == "00" ] && [ "${partitionBootSector:42:2}" == "f0" ] && [ "${partitionBootSector:48:2}" == "20" ]; then
#echo "DEBUG: Found a FAT32 device formatted by OS X Snow Leopard Disk Utility"
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT32 volume formatted by OS X Snow Leopard Disk Utility"
exit 2
fi
if [ "${partitionBootSector:36:2}" == "02" ] && [ "${partitionBootSector:42:2}" == "f0" ] && [ "${partitionBootSector:48:2}" == "20" ]; then
#echo "DEBUG: Found a FAT16 device formatted by OS X Snow Leopard Disk Utility"
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT16 volume formatted by OS X Snow Leopard Disk Utility"
exit 1
fi
if [ "${partitionBootSector:36:2}" == "00" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "20" ]; then
#echo "DEBUG: Found a FAT32 device formatted by OS X Lion Disk Utility"
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT32 volume formatted by OS X Lion Disk Utility"
exit 2
fi
if [ "${partitionBootSector:36:2}" == "02" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "20" ]; then
#echo "DEBUG: Found a FAT16 device formatted by OS X Lion Disk Utility"
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT16 volume formatted by OS X Lion Disk Utility"
exit 1
fi
exit 0
branches/ErmaC/Enoch/package/Scripts/Sub/MountESP.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
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
echo "==============================================="
echo "MountESP: Mount the EFI system partition"
echo "***********************************************"
# Creates a mountpoint and mounts /Volumes/EFI of the
# supplied disk which would have been pre-checked as using a GPT
# Receives targetDisk: for example /dev/disk2.
# Receives installerVolume: Volume to write the installer log to.
# Receives efiPartitionExist: either 0 or 1
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 4 ]; then
targetDisk="$1"
installerVolume="$2"
efiPartitionExist="$3"
scriptDir="$4"
echo "DEBUG: passed argument for targetDisk = $targetDisk"
echo "DEBUG: passed argument for installerVolume = $installerVolume"
echo "DEBUG: passed argument for efiPartitionExist = $efiPartitionExist"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
# Check the first partition is actually type 'EFI'
# as we could be checking a USB flash drive <4GB
if [ ${efiPartitionExist} = 1 ]; then
# Does the mountpoint exist?
if [ ! -e "/Volumes/EFI" ]; then
mkdir -p "/Volumes/EFI"
fi
# Mount '/Volumes/EFI' using the correct format type
if [ "$( fstyp "${targetDisk}"s1 | grep hfs )" ]; then
"$scriptDir"InstallLog.sh "${installerVolume}" "Mounting ${targetDisk}s1 as /Volumes/EFI."
mount_hfs "${targetDisk}"s1 "/Volumes/EFI"
fi
if [ "$( fstyp "${targetDisk}"s1 | grep msdos )" ]; then
"$scriptDir"InstallLog.sh "${installerVolume}" "Mounting ${targetDisk}s1 as /Volumes/EFI."
mount_msdos -u 0 -g 0 "${targetDisk}"s1 "/Volumes/EFI"
fi
else
"$scriptDir"InstallLog.sh "${installerVolume}" "Target volume doesn't have an EFI system partition."
fi
exit 0
branches/ErmaC/Enoch/package/Scripts/Sub/WriteChameleonStage0.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
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
echo "==============================================="
echo "Write Chameleon Stage 0 Loader:"
echo "*******************************"
# Writes Chameleon stage 0 loader.
# Receives disksignature: 0 = Windows not found, 1 = Windows Found
# Receives stage0Loader: for example, boot0
# Receives stage0Loaderdualboot: for example, boot0md
# Receives targetDisk: for example, /dev/disk3
# Receives targetResources: location of fdisk440
# Receives targetVolume: for example, /Volumes/USB
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 7 ]; then
disksignature="$1"
stage0Loader="$2"
stage0Loaderdualboot="$3"
targetDisk="$4"
targetResources="$5"
targetVolume="$6"
scriptDir="$7"
echo "DEBUG: passed argument for disksignature = $disksignature"
echo "DEBUG: passed argument for stage0Loader = $stage0Loader"
echo "DEBUG: passed argument for stage0Loaderdualboot = $stage0Loaderdualboot"
echo "DEBUG: passed argument for targetDisk = $targetDisk"
echo "DEBUG: passed argument for targetResources = $targetResources"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
if [ ${disksignature} = "0" ]; then
#echo "DEBUG: Executing command: ${targetResources}fdisk440 -u -f /usr/standalone/i386/${stage0Loader} -y ${targetDisk}"
"${targetResources}"fdisk440 -u -f "${targetVolume}"/usr/standalone/i386/${stage0Loader} -y ${targetDisk}
"$scriptDir"InstallLog.sh "${targetVolume}" "Written ${stage0Loader} to ${targetDisk}."
else
# Windows is also installed on the HDD so we need to write boot0md
#echo "DEBUG: Executing command: ${targetResources}fdisk440 -u -f /usr/standalone/i386/${stage0Loaderdualboot} -y ${targetDisk}"
"${targetResources}"fdisk440 -u -f "${targetVolume}"/usr/standalone/i386/${stage0Loaderdualboot} -y ${targetDisk}
"$scriptDir"InstallLog.sh "${targetVolume}" "Written ${stage0Loaderdualboot} to ${targetDisk}."
fi
exit 0
branches/ErmaC/Enoch/package/Scripts/Sub/WriteChameleonStage1.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
echo "==============================================="
echo "Write Chameleon Stage 1 Loader:"
echo "*******************************"
# Writes Chameleon stage 1 loader.
# Receives targetFormat: either hfs or msdos
# Receives stage1LoaderHFS: Name of file - boot1h
# Receives stage1LoaderFAT: Name of file - boot1f32
# Receives selectedDestination: for example, /Volumes/USB
# Receives targetDeviceRaw: for example, /dev/disk3s1
# Receives targetVolume: for example, /Volumes/USB
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 7 ]; then
targetFormat="$1"
stage1LoaderHFS="$2"
stage1LoaderFAT="$3"
selectedDestination="$4"
targetDeviceRaw="$5"
targetVolume="$6"
scriptDir="$7"
echo "DEBUG: passed argument for targetFormat = $targetFormat"
echo "DEBUG: passed argument for stage1LoaderHFS = $stage1LoaderHFS"
echo "DEBUG: passed argument for stage1LoaderFAT = $stage1LoaderFAT"
echo "DEBUG: passed argument for selectedDestination = $selectedDestination"
echo "DEBUG: passed argument for targetDeviceRaw = $targetDeviceRaw"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
if [ ${targetFormat} = "hfs" ]; then
#echo "DEBUG: Executing command: dd if=${selectedDestination}/usr/standalone/i386/${stage1LoaderHFS} of=${targetDeviceRaw}"
dd if="${selectedDestination}"/usr/standalone/i386/${stage1LoaderHFS} of=${targetDeviceRaw}
"$scriptDir"InstallLog.sh "${targetVolume}" "Written ${stage1LoaderHFS} to ${targetDeviceRaw}."
fi
if [ ${targetFormat} = "msdos" ]; then
#echo "DEBUG: Executing command: dd if=${targetDeviceRaw} count=1 bs=512 of=/tmp/origbs"
dd if=${targetDeviceRaw} count=1 bs=512 of=/tmp/origbs
#echo "DEBUG: Executing command: cp "${selectedDestination}"/usr/standalone/i386/${stage1LoaderFAT} /tmp/newbs"
cp "${selectedDestination}"/usr/standalone/i386/${stage1LoaderFAT} /tmp/newbs
#echo "DEBUG: Executing command: dd if=/tmp/origbs of=/tmp/newbs skip=3 seek=3 bs=1 count=87 conv=notrunc"
dd if=/tmp/origbs of=/tmp/newbs skip=3 seek=3 bs=1 count=87 conv=notrunc
#echo "DEBUG: Executing command: dd of=${targetDeviceRaw} count=1 bs=512 if=/tmp/newbs"
dd if=/tmp/newbs of="${targetDeviceRaw}" count=1 bs=512
"$scriptDir"InstallLog.sh "${targetVolume}" "Written ${stage1LoaderFAT} to ${targetDeviceRaw}."
fi
exit 0
branches/ErmaC/Enoch/package/Scripts/Sub/CheckPartitionScheme.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
echo "==============================================="
echo "Check the Partition Scheme: GPT, GPT/MBR or MBR?"
echo "************************************************"
# Looks for the first 8 bytes of the GPTdiskGPTHeader to identify a GUID partition table.
# Byte number 450 of the GPTdiskProtectiveMBR to identify ID of 'EE' to identify a GPT partition.
# Byte numbers 466, 482 & 498 of the GPTdiskProtectiveMBR to identify further partitions.
#
# Exit with value 1 for GPT, 2 for GPT/MBR and 3 for MBR.
# Exit with value 0 if nothing is found - this shouldn't happen.?
# Receives targetDisk: for example, /dev/disk0s2
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 3 ]; then
targetDisk="$1"
targetVolume="$2"
scriptDir="$3"
echo "DEBUG: passed argument = $targetDisk"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
partitiontable=$( dd 2>/dev/null if="$targetDisk" count=1 skip=1 | dd 2>/dev/null count=8 bs=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
if [ "${partitiontable:0:16}" == "4546492050415254" ]; then
partitiontable=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=64 bs=1 skip=446 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
if [ "${partitiontable:8:2}" == "ee" ]; then
#echo "DEBUG: Found System ID 'EE' to identify GPT Partition"
if [ "${partitiontable:40:2}" == "00" ] && [ "${partitiontable:72:2}" == "00" ] && [ "${partitiontable:104:2}" == "00" ]; then
#echo "DEBUG: Found System ID '00' for each remaining possible partition"
partitiontable="GPT"
#echo "DEBUG: ${partitiontable} found."
#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using a GPT."
exit 1
else
partitiontable="GPT/MBR"
#echo "DEBUG: ${partitiontable} found."
#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using a GPT/MBR."
exit 2
fi
fi
else
partitiontable="MBR"
#echo "DEBUG: ${partitiontable} found."
#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using MBR."
exit 3
fi
#echo "DEBUG: No partition table found."
"$scriptDir"InstallLog.sh "${targetVolume}" "NOTE: No partition table found."
exit 0
branches/ErmaC/Enoch/package/Scripts/Sub/WriteChameleonStage2.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
42
43
44
45
46
47
#!/bin/bash
echo "==============================================="
echo "Write Chameleon Stage 2 Loader:"
echo "*******************************"
# Receives stage2Loader: Name of file - boot
# Receives selectedDestination: for example, /Volumes/ChameleonBootUSB (or /Volumes/EFI if ESP install).
# Receives targetDevice: for example, /dev/disk3s1
# Receives targetVolume: for example, /Volumes/ChameleonBootUSB
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 5 ]; then
stage2Loader="$1"
selectedDestination="$2"
targetDevice="$3"
targetVolume="$4"
scriptDir="$5"
echo "DEBUG: passed argument for stage2Loader = $stage2Loader"
echo "DEBUG: passed argument for selectedDestination = $selectedDestination"
echo "DEBUG: passed argument for targetDevice = $targetDevice"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
# check to see if install to EFI system partition was selected
if [ "${selectedDestination}" = "/Volumes/EFI" ]; then
#echo "DEBUG: Executing command: cp "${targetVolume}"/usr/standalone/i386/${stage2Loader} ${selectedDestination}"
cp "${targetVolume}"/usr/standalone/i386/"${stage2Loader}" "${selectedDestination}"
"$scriptDir"InstallLog.sh "${targetVolume}" "Written boot to ${selectedDestination}."
else
#echo "DEBUG: Executing command: cp "${targetVolume}"/usr/standalone/i386/${stage2Loader} ${targetVolume}"
cp "${targetVolume}"/usr/standalone/i386/"${stage2Loader}" "${targetVolume}"
"$scriptDir"InstallLog.sh "${targetVolume}" "Written boot to ${targetVolume} on ${targetDevice}."
fi
#if [ -f "${selectedDestination}"/.Chameleon/nullhideboot ]; then
#echo "Executing command: SetFile -a V ${targetVolume}/${stage2Loader}"
#"${selectedDestination}"/.Chameleon/Resources/SetFile -a V "${targetVolume}"/"${stage2Loader}"
#fi
exit 0
branches/ErmaC/Enoch/package/Scripts/Sub/CheckDiskMicrocode.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
116
#!/bin/bash
echo "==============================================="
echo "CheckDiskMicrocode: Any existing bootloaders?"
echo "*********************************************"
# Reads the GPTdiskProtectiveMBR and searches for an existing
# Windows bootloader and also for an existing Chameleon stage 0 loader
# which might be better changed depending on whether or not a Windows
# signature is found or not.
# The script then exits with the value 0 to indicate that Chameleon stage0
# loader can be written, or 1 to indicate not to write the stage0 loader.
# Receives targetDisk: for example, /dev/disk2.
# Receives diskSigCheck: 0 = Windows not installed / 1 = Windows installed.
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 4 ]; then
targetDisk="$1"
diskSigCheck="$2"
targetVolume="$3"
scriptDir="$4"
echo "DEBUG: passed argument for targetDisk = $targetDisk"
echo "DEBUG: passed argument for diskSigCheck = $diskSigCheck"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed - Exiting"
exit 9
fi
# read the first 437 bytes of the MBR
mbr437=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=1 bs=437 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
#mbr437md5=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=1 bs=437 | md5 )
if [ $( echo "${mbr437}" | awk -F0 '{print NF-1}' ) != 874 ]; then
# There is already something on the MBR
# See if a Windows bootloader already exists
# Check bytes 440-443 of the GPTdiskProtectiveMBR for a Windows Disk Signature
windowsloader=$( dd 2>/dev/null if="$targetDisk" count=4 bs=1 | xxd | awk '{print $2$3}' )
if [ "${windowsloader}" == "33c08ed0" ] ; then
#echo "DEBUG: Found existing Windows Boot Loader so will replace with Chameleon boot0md"
"$scriptDir"InstallLog.sh "${targetVolume}" "Target disk has existing Windows boot loader - Will replace with boot0md (boot0workV2)."
fi
# See if a Chameleon stage0 boot file already exists
# Note: The checks for Boot0, Boot0hfs, Boot0md and Boot0md (dmazar's Boot0workV2) assume the code stays the same.
# if the code changes then the hex values 0b807c, 0a803c, ee7505 and 742b80 used for matching
# need to be checked to see if they are the same or not.
stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )
if [ "${stage0type}" == "0b807c" ]; then
#echo "DEBUG: Target has existing Chameleon stage 0 loader - Boot0hfs"
"$scriptDir"InstallLog.sh "${targetVolume}" "Target disk already has existing Chameleon stage 0 loader - boot0hfs"
# Script CheckDiskSignature.sh returned 0 if a Windows installation was NOT found
if [ "$diskSigCheck" == "0" ]; then
#echo "DEBUG: Found no existing Windows installation so will replace stage 0 loader with Boot0"
"$scriptDir"InstallLog.sh "${targetVolume}" "Will replace boot0hfs with boot0 as Windows is not on target disk."
exit 0
fi
exit 1
fi
if [ "${stage0type}" == "0a803c" ]; then
#echo "DEBUG: Found existing Chameleon stage 0 loader - Boot0"
"$scriptDir"InstallLog.sh "${targetVolume}" "Target disk already has existing Chameleon stage 0 loader - boot0"
# Script CheckDiskSignature.sh returned 1 if a Windows installation was found
if [ "$diskSigCheck" = "1" ]; then
#echo "DEBUG: Found existing Windows installation so will replace stage 0 loader with boot0md"
"$scriptDir"InstallLog.sh "${targetVolume}" "Will replace boot0 with boot0md (boot0workV2) as Windows is on target disk."
exit 0
fi
exit 1
fi
if [ "${stage0type}" == "ee7505" ]; then
#echo "DEBUG: Found existing Chameleon stage 0 loader - Boot0md"
#echo "DEBUG: And will leave boot0md installed."
"$scriptDir"InstallLog.sh "${targetVolume}" "Target disk already has existing Chameleon stage 0 loader - boot0md (v1)."
exit 1
fi
if [ "${stage0type}" == "742b80" ]; then
#echo "DEBUG: Found existing Chameleon stage 0 loader - Boot0workV2"
#echo "DEBUG: And will leave Boot0workV2 installed."
"$scriptDir"InstallLog.sh "${targetVolume}" "Target disk already has existing Chameleon stage 0 loader - boot0md (boot0workV2)."
exit 1
fi
if [ "${stage0type}" != "0b807c" ] && [ "${stage0type}" != "0a803c" ] && [ "${stage0type}" != "ee7505" ] && [ "${stage0type}" != "742b80" ] && [ "${windowsloader}" != "33c08ed0" ] ; then
#echo "DEBUG: Something other than Chameleon or a Windows bootloader was found"
test=$(echo "${mbr437}" | awk -F0 '{print NF-1}' )
#echo "DEBUG: Disk microcode found: ${test} - Preserving."
#echo "DEBUG: diskupdate is set to false"
#echo "DEBUG: -----------------------------------------------"
"$scriptDir"InstallLog.sh "${targetVolume}" "NOTE: Target has existing unrecognised bootcode in the MBR. Leaving as is."
exit 1
fi
#else
#echo "DEBUG: The first 437 bytes of the MBR Disk Sector is blank - Updating"
#"$scriptDir"InstallLog.sh "${targetVolume}" "Target has no bootcode in the MBR disk sector."
fi
echo "diskupdate is now set to true."
echo "-----------------------------------------------"
echo ""
exit 0
branches/ErmaC/Enoch/package/Scripts/Sub/CheckProceed.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
echo "==============================================="
echo "Check Proceed: Can the installation continue?"
echo "***********************************************"
# Checks the selected volume is present and the disk is partitioned
# Now also check for another existing Chameleon installation on the same disk.
# Exit with 0 to indicate okay to proceed, no problems.
# Exit with 1 to indicate okay to proceed, but target disk doesn't have EFI system partition.
# Exit with 2 to indicate not to proceed.
# Receives targetVolume: Volume to install to (will be '/Volumes/EFI' if EFI install)
# Receives targetDevice: Stores device number, for example /dev/disk2s1.
# Receives installerVolume: Volume to write the installer log to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 4 ]; then
targetVolume="$1"
targetDevice="$2"
installerVolume="$3"
scriptDir="$4"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for targetDevice = $targetDevice"
echo "DEBUG: passed argument for installerVolume = $installerVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
# Does target volume exist?
if [ -z "$targetVolume" ]; then
echo "*** Cannot find the volume. Exiting."
"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: Cannot file the volume: $targetVolume."
exit 2
fi
# Does target volume use slices?
if [ "$targetDevice" = "$targetDevice#*disk*s" ]; then
echo "*** ERROR Volume does not use slices. Exiting."
"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: $targetVolume doesn't use slices."
exit 2
fi
# Check to find if an EFI system partition exists on the disk.
# This is used in two cases:
# A) When checking for existing Chameleon installations.
# B) When the user chooses the EFI system partition install option,
# and installing to a 'small' HFS device like a 1GB USB flash
# drive which won't have an EFI System Partition.
# Take target device and check if slice 1 is not named "EFI"
stripped=$( echo ${targetDevice#/dev/} )
if [ ! $(echo ${stripped#*disk*s}) = 1 ]; then
stripped=$( echo ${stripped%s*})"s1"
fi
if [ ! $( diskutil list | grep ${stripped} | awk {'print $2'} ) = "EFI" ]; then
if [ "$targetVolume" = "/Volumes/EFI" ]; then
"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: Selected disk does not have an EFI System Partition."
fi
exit 1
fi
exit 0
branches/ErmaC/Enoch/package/Scripts/Sub/SetActivePartition.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
echo "==============================================="
echo "Set Active Partition ONLY if Windows is not installed"
echo "*****************************************************"
# Sets partition active if Windows is not installed.
# Receives diskSigCheck: code is 1 for a Windows install, 0 for no Windows install
# Receives targetDiskRaw: for example, /dev/rdisk1
# Receives targetSlice: for example, 1
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 5 ]; then
diskSigCheck="$1"
targetDiskRaw="$2"
targetSlice="$3"
targetVolume="$4"
scriptDir="$5"
echo "DEBUG: passed argument for diskSigCheck = $diskSigCheck"
echo "DEBUG: passed argument for targetDiskRaw = $targetDiskRaw"
echo "DEBUG: passed argument for targetSlice = $targetSlice"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
# Append fdisk output to the installer log
"$scriptDir"InstallLog.sh "${targetVolume}" "fdisk ${targetDiskRaw}"
if [ ${diskSigCheck} == "0" ]; then
#Windows is not installed so let's change the active partition"
partitionactive=$( fdisk -d ${targetDiskRaw} | grep -n "*" | awk -F: '{print $1}')
if [ "${partitionactive}" ] && [ "${partitionactive}" = "${targetSlice}" ]; then
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDiskRaw#/dev/r}, slice "${targetSlice}" is already set active. No need to change it."
else
"$scriptDir"InstallLog.sh "${targetVolume}" "Setting ${targetVolume} partition active."
# BadAxe requires EFI partition to be flagged active.
# but it doesn't' hurt to do it for any non-windows partition.
fdisk -e ${targetDiskRaw} <<-MAKEACTIVE
print
flag ${targetSlice}
write
y
quit
MAKEACTIVE
fi
else
# TO DO
# Add check to make sure that the active partition is actually the Windows partition
# before printing next statement.
#echo "DEBUG: Windows is installed so we let that remain the active partition"
"$scriptDir"InstallLog.sh "${targetVolume}" "Windows is installed so that can remain the active partition"
fi
exit 0
branches/ErmaC/Enoch/package/Scripts/Sub/CheckGRUBLinuxLoader.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
42
43
44
45
#!/bin/bash
echo "==============================================="
echo "CheckGRUBLinuxLoader: Does GRUB or LILO exist?"
echo "**********************************************"
# This reads the MBR of the disk in the attempt to find the
# signature for either the GRUB or Linux bootloaders.
# The script returns 1 if either is found, or 0 if none found.
# Receives targetdisk: for example, /dev/disk2.
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 3 ]; then
targetDisk="$1"
targetVolume="$2"
scriptDir="$3"
echo "DEBUG: passed argument for targetDisk = $targetDisk"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
diskmicrocodetype[1]="GRUB,47525542"
diskmicrocodetype[2]="LILO,4c494c4f"
diskmicrocode=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=1 bs=437 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
#echo "DEBUG: ${diskmicrocode}"
diskmicrocodetypecounter=0
while [ ${diskmicrocodetypecounter} -lt ${#diskmicrocodetype[@]} ]; do
diskmicrocodetypecounter=$(( ${diskmicrocodetypecounter} + 1 ))
diskmicrocodetypeid=${diskmicrocodetype[${diskmicrocodetypecounter}]#*,}
if [ ! "${diskmicrocode}" = "${diskmicrocode/${diskmicrocodetypeid}/}" ]; then
echo "${diskmicrocodetype[${diskmicrocodetypecounter}]%,*} found."
exit 1
#else
#echo "DEBUG: Didn't find a match for ${diskmicrocodetype[${diskmicrocodetypecounter}]%,*}"
fi
done
exit 0
branches/ErmaC/Enoch/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/ErmaC/Enoch/package/Scripts/Sub/CheckWindowsDiskSignature.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
#!/bin/bash
echo "==============================================="
echo "CheckWindowsDiskSignature: Is Windows installed?"
echo "************************************************"
# Checks the disk sector for a 4-byte Windows disk signature
# if one is found then it exits with 1, otherwise it exits with 0
# Receives targetdisk: for example, /dev/disk0
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 3 ]; then
targetDisk="$1"
targetVolume="$2"
scriptDir="$3"
echo "DEBUG: passed argument for targetDisk = $targetDisk"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed - Exiting"
exit 9
fi
disksignature=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=4 bs=1 skip=440 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
#echo "DEBUG: ${disksignature}"
if [ "${disksignature}" = "00000000" ]; then
#echo "DEBUG: No Windows installation detected."
exit 0
else
#echo "DEBUG: Detected an existing Windows installation"
"$scriptDir"InstallLog.sh "${targetVolume}" "Detected a Windows installation on this volume."
exit 1
fi
exit 0
branches/ErmaC/Enoch/package/buildpkg.sh
274274
275275
276276
277
278
279
280
277281
278282
279283
......
467471
468472
469473
470
471
472
473
474
475
476
477
478
479
480
474
475
476
477
478
479
480
481
482
483
484
485
481486
482487
483488
484489
485490
486
491
487492
488493
489
490
491
492
493
494
494
495
495496
496
497
498
499
500
497
498
501499
502500
503501
504
505
502
503
504
506505
507
508
509
510
511
512
513
514
515
516
517
518
506
507
508
519509
520
521
522
523
524
525
510
526511
527512
513
514
528515
529516
530517
531
532
518
519
520
533521
534522
535523
......
573561
574562
575563
576
564
577565
578566
579567
......
592580
593581
594582
595
583
596584
597585
598586
......
611599
612600
613601
614
602
615603
616604
617605
......
630618
631619
632620
633
621
634622
635623
636624
......
649637
650638
651639
652
640
653641
654642
655643
......
668656
669657
670658
671
659
672660
673661
674662
......
680668
681669
682670
683
671
684672
685673
686674
687675
688676
689
677
690678
691679
692
680
693681
694
682
695683
696684
697685
......
722710
723711
724712
725
713
726714
727715
728716
......
741729
742730
743731
744
732
745733
746734
747735
......
760748
761749
762750
763
751
764752
765753
766754
......
779767
780768
781769
782
770
783771
784772
785773
......
798786
799787
800788
801
789
802790
803791
804792
......
822810
823811
824812
825
813
826814
827815
828816
......
978966
979967
980968
981
969
982970
983971
984972
985973
986
987
974
975
988976
989
977
978
979
980
981
982
983
984
985
990986
991987
988
989
990
991
992
993
994
995
996
992997
993998
994999
9951000
996
1001
9971002
1003
1004
1005
1006
9981007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
9991022
10001023
10011024
......
10041027
10051028
10061029
1007
10081030
10091031
10101032
......
11071129
11081130
11091131
1132
11101133
11111134
11121135
......
11721195
11731196
11741197
1198
11751199
11761200
11771201
case "$option" in
--group=*)
shift; groupChoice=${option#*=} ;;
--selected=*)
shift; choiceOptions="$choiceOptions selected=\"${option#*=}\"" ;;
--enabled=*)
shift; choiceOptions="$choiceOptions enabled=\"${option#*=}\"" ;;
--start-selected=*)
shift; choiceOptions="$choiceOptions start_selected=\"${option#*=}\"" ;;
--start-enabled=*)
choiceId="Core"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot0md ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1f32 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1h ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1x ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1he ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1hp ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/cdboot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/chain0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/fdisk440 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
ditto --noextattr --noqtn ${SYMROOT}/i386/boot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot0md ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1f32 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1h ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1x ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1he ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1hp ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/cdboot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/chain0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/fdisk440 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
ditto --noextattr --noqtn ${SYMROOT}/i386/sectorsize ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1-install ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
ditto --noextattr --noqtn ${SYMROOT}/i386/bdmesg ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
addChoice --start-visible="false" --selected="choices['boot'].selected" --pkg-refs="$packageRefId" "${choiceId}"
# End build core package
# build Chameleon package
echo "================= Chameleon ================="
addGroupChoices --exclusive_one_choice "Chameleon"
# build standard package
choiceId="Standard"
# build boot choice package
choiceId="boot"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources
addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" InstallerLog
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
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts
cp -f ${PKGROOT}/Scripts/Main/BootYES ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
addChoice --group="Chameleon" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
# End build standard package
addChoice --start-visible="false" --selected="!choices['noboot'].selected" \
--pkg-refs="$packageRefId" "${choiceId}"
# End build boot choice package
# build efi package
if [[ 1 -eq 0 ]];then
# Only standard installation is currently supported
# We need to update the script to be able to install
# Chameleon on EFI partition
choiceId="EFI"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources
addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" InstallerLog
cp -f ${PKGROOT}/Scripts/Main/ESPpostinstall ${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
# build Chameleon package
echo "================= Chameleon ================="
addGroupChoices "Chameleon"
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
addChoice --group="Chameleon" --start-visible="systemHasGPT()" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build efi package
fi
# build no bootloader choice package
# build noboot choice package
choiceId="noboot"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts
cp -f ${PKGROOT}/Scripts/Main/BootNO ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
addChoice --group="Chameleon" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build no bootloader choice package
addChoice --group="Chameleon" --selected="!choices['boot'].selected" \
--pkg-refs="$packageRefId" "${choiceId}"
# End build noboot choice package
# End build Chameleon package
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build ACPICodec package module
}
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build NvidiaGraphicsEnabler package module
}
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build AMDGraphicsEnabler package module
}
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build IntelGraphicsEnabler package module
}
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build KernelPatcher package module
}
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build KextPatcher package module
}
# Start build Keylayout package module
choiceId="Keylayout"
moduleFile="${choiceId}.dylib"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/{modules,Keymaps}
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/EXTRAROOTDIR/Extra/{modules,Keymaps}
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
layout_src_dir="${SRCROOT}/i386/modules/Keylayout/layouts/layouts-src"
if [ -d "$layout_src_dir" ];then
# Create a tar.gz from layout sources
(cd "$layout_src_dir"; \
tar czf "${PKG_BUILD_DIR}/${choiceId}/Root/Extra/Keymaps/layouts-src.tar.gz" README *.slt)
tar czf "${PKG_BUILD_DIR}/${choiceId}/Root/EXTRAROOTDIR/Extra/Keymaps/layouts-src.tar.gz" README *.slt)
fi
# Adding module
ditto --noextattr --noqtn ${SYMROOT}/i386/modules/$moduleFile ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/modules
ditto --noextattr --noqtn ${SYMROOT}/i386/modules/$moduleFile ${PKG_BUILD_DIR}/${choiceId}/Root/EXTRAROOTDIR/Extra/modules
# Adding Keymaps
ditto --noextattr --noqtn ${SRCROOT}/Keymaps ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/Keymaps
ditto --noextattr --noqtn ${SRCROOT}/Keymaps ${PKG_BUILD_DIR}/${choiceId}/Root/EXTRAROOTDIR/Extra/Keymaps
# Adding tools
ditto --noextattr --noqtn ${SYMROOT}/i386/cham-mklayout ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
# Adding scripts
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build klibc package module
}
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build Resolution package module
}
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build HDAEnabler package module
}
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build FileNVRAM package module
}
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build Sata package module
}
InstallModule
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
# Add the klibc package because the uClibc module is dependent of klibc module
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId $klibcPackageRefId" "${choiceId}"
# End build uClibc package module
InstallTheme
packageRefId=$(getPackageRefId "${packagesidentity}" "${themeName}")
buildpackage "$packageRefId" "${themeName}" "${PKG_BUILD_DIR}/${themeName}" "/Extra/Themes"
buildpackage "$packageRefId" "${themeName}" "${PKG_BUILD_DIR}/${themeName}" "/EXTRAROOTDIR/Extra/Themes"
addChoice --group="Themes" --start-selected="false" --pkg-refs="$packageRefId" "${themeName}"
done
# End build theme packages# End build Extras package
# build pre install package
echo "================= Pre ================="
# build standard package
echo "================ standard ================"
packagesidentity="${chameleon_package_identity}"
choiceId="Pre"
choiceId="Standard"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources
local yamlFile="Resources/chameleon_options.yaml"
addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
--subst="YAML_FILE=${yamlFile}" CleanOptions
generate_options_yaml_file "${PKG_BUILD_DIR}/${choiceId}/Scripts/$yamlFile"
cp -f ${PKGROOT}/Scripts/Main/${choiceId}postinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
addChoice --group="Chameleon" --start-selected="true" --selected="!choices['EFI'].selected" \
--pkg-refs="$packageRefId" "${choiceId}"
# End build standard package
# build efi package
echo "================== EFI =================="
packagesidentity="${chameleon_package_identity}"
choiceId="EFI"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources
local yamlFile="Resources/chameleon_options.yaml"
addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
--subst="YAML_FILE=${yamlFile}" ${choiceId}
--subst="YAML_FILE=${yamlFile}" CleanOptions
generate_options_yaml_file "${PKG_BUILD_DIR}/${choiceId}/Scripts/$yamlFile"
cp -f ${PKGROOT}/Scripts/Main/ESPpostinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
addChoice --group="Chameleon" --enabled="systemHasGPT()" --start-selected="false" \
--selected="!choices['Standard'].selected" \
--pkg-refs="$packageRefId" "${choiceId}"
# End build efi package
# build pre install package
echo "================= Pre ================="
packagesidentity="${chameleon_package_identity}"
choiceId="Pre"
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" ${choiceId}
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
# End build pre install package
# build post install package
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
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
}
generateChoices() {
for (( idx=1; idx < ${#choice_key[*]} ; idx++)); do
local choiceId=${choice_key[$idx]}
local choiceOptions=${choice_options[$idx]}
local start_indent_level=2
echo -e "\n\t<choices-outline>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
for main_choice in ${choice_group_items[0]};do
generateOutlineChoices $main_choice $start_indent_level >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
done

Archive Download the corresponding diff file

Revision: 2567