Clover.app v1.07 Beta

Fixed dump of nvram for Clover EFI. Fixed a bug installing boot sectors.
This commit is contained in:
vectorsigma72 2019-11-19 22:18:11 +01:00
parent 66f30d4dc0
commit 4e3dc60ab7
14 changed files with 185 additions and 251 deletions

View File

@ -855,7 +855,7 @@
CODE_SIGN_ENTITLEMENTS = Clover/Clover.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.05;
CURRENT_PROJECT_VERSION = 1.07;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Clover/Frameworks",
@ -869,7 +869,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Clover/Frameworks",
);
MARKETING_VERSION = 1.05;
MARKETING_VERSION = 1.07;
PRODUCT_BUNDLE_IDENTIFIER = org.slice.Clover;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
@ -884,7 +884,7 @@
CODE_SIGN_ENTITLEMENTS = Clover/Clover.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.05;
CURRENT_PROJECT_VERSION = 1.07;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Clover/Frameworks",
@ -898,7 +898,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Clover/Frameworks",
);
MARKETING_VERSION = 1.05;
MARKETING_VERSION = 1.07;
PRODUCT_BUNDLE_IDENTIFIER = org.slice.Clover;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;

View File

@ -124,7 +124,6 @@ func getVolumeUUID(from diskOrMtp: String) -> String? {
func getDiskUUID(from diskOrMtp: String) -> String? {
var uuid : String? = nil
if let dict : NSDictionary = getDAdiskDescription(from: getBSDParent(of: diskOrMtp)!) {
print(dict)
if (dict.object(forKey: kDADiskDescriptionMediaUUIDKey) != nil) {
let temp : AnyObject = dict.object(forKey: kDADiskDescriptionMediaUUIDKey) as AnyObject
if temp is NSUUID {

View File

@ -59,6 +59,4 @@ extension String {
return UnsafePointer<UInt8>(buffer)
}
}

View File

@ -45,11 +45,6 @@
<string>Copyright © 2019 CloverHackyColor. All rights reserved.</string>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>SMPrivilegedExecutables</key>
<dict>
<key>org.slice.CloverDaemonNew</key>
<string>identifier &quot;org.slice.CloverDaemonNew&quot;</string>
</dict>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSSupportsAutomaticTermination</key>

View File

@ -730,7 +730,7 @@ class InstallerViewController: NSViewController {
let name : String = getVolumeName(from: disk) ?? kNotAvailable.locale
let mp : String = getMountPoint(from: disk) ?? kNotAvailable.locale
let parentDiskName : String = getMediaName(from: getBSDParent(of: disk) ?? "") ?? kNotAvailable.locale
if fs == "msdos" || fs == "fat32" || fs == "exfat" || fs == "hfs" {
if fs == "fat32" || fs == "exfat" || fs == "hfs" {
self.targetPop.addItem(withTitle: "\(disk)\t\(name), \("mount point".locale): \(mp), \(fs.uppercased()), \(psm): (\(parentDiskName))")
self.targetPop.invalidateIntrinsicContentSize()
// get the image

View File

@ -368,10 +368,10 @@ class SettingsViewController: NSViewController, NSTextFieldDelegate, URLSessionD
deleteNVRAM(key: key)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) {
var value = ""
if let nvram = getNVRAM() {
let nvdata = nvram.object(forKey: "Clover.DisableSleepProxyClient") as? Data
let nvdata = nvram.object(forKey: key) as? Data
value = String(decoding: nvdata ?? Data(), as: UTF8.self)
}
self.disbaleSleepProxyButton.state = (value == "true") ? .on : .off
@ -386,10 +386,10 @@ class SettingsViewController: NSViewController, NSTextFieldDelegate, URLSessionD
deleteNVRAM(key: key)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) {
var value = ""
if let nvram = getNVRAM() {
let nvdata = nvram.object(forKey: "Clover.RootRW") as? Data
let nvdata = nvram.object(forKey: key) as? Data
value = String(decoding: nvdata ?? Data(), as: UTF8.self)
}
self.disbaleSleepProxyButton.state = (value == "true") ? .on : .off

View File

@ -12,7 +12,6 @@
953B8DF22370BF5B007E36E3 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 953B8DF12370BF5A007E36E3 /* Extensions.swift */; };
953D98872377094A003B369E /* Disks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 953D98862377094A003B369E /* Disks.swift */; };
953DBFDF236F037400B0C4FB /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 953DBFDE236F037400B0C4FB /* main.swift */; };
9546F0EB2376F94100A3D053 /* PowerObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 9546F0EA2376F94100A3D053 /* PowerObserver.m */; };
954FF20E2371B13C00C3D94C /* DiskArbitration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 954FF20D2371B13C00C3D94C /* DiskArbitration.framework */; };
954FF2102371B16300C3D94C /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 954FF20F2371B16300C3D94C /* IOKit.framework */; };
/* End PBXBuildFile section */
@ -24,9 +23,6 @@
953D98862377094A003B369E /* Disks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Disks.swift; path = ../../Clover/Disks.swift; sourceTree = "<group>"; };
953DBFDB236F037400B0C4FB /* CloverDaemonNew */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = CloverDaemonNew; sourceTree = BUILT_PRODUCTS_DIR; };
953DBFDE236F037400B0C4FB /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
9546F0E82376F94100A3D053 /* CloverDaemonNew-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CloverDaemonNew-Bridging-Header.h"; sourceTree = "<group>"; };
9546F0E92376F94100A3D053 /* PowerObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PowerObserver.h; sourceTree = "<group>"; };
9546F0EA2376F94100A3D053 /* PowerObserver.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PowerObserver.m; sourceTree = "<group>"; };
954FF20D2371B13C00C3D94C /* DiskArbitration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DiskArbitration.framework; path = System/Library/Frameworks/DiskArbitration.framework; sourceTree = SDKROOT; };
954FF20F2371B16300C3D94C /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
@ -69,9 +65,6 @@
953B8DEF2370BB5C007E36E3 /* NVRAM.swift */,
953B8DED2370BB1A007E36E3 /* bdmesg.swift */,
953B8DF12370BF5A007E36E3 /* Extensions.swift */,
9546F0E92376F94100A3D053 /* PowerObserver.h */,
9546F0EA2376F94100A3D053 /* PowerObserver.m */,
9546F0E82376F94100A3D053 /* CloverDaemonNew-Bridging-Header.h */,
);
path = CloverDaemonNew;
sourceTree = "<group>";
@ -144,7 +137,6 @@
buildActionMask = 2147483647;
files = (
953B8DF22370BF5B007E36E3 /* Extensions.swift in Sources */,
9546F0EB2376F94100A3D053 /* PowerObserver.m in Sources */,
953D98872377094A003B369E /* Disks.swift in Sources */,
953DBFDF236F037400B0C4FB /* main.swift in Sources */,
953B8DF02370BB5D007E36E3 /* NVRAM.swift in Sources */,
@ -281,7 +273,8 @@
MACOSX_DEPLOYMENT_TARGET = 10.9;
OTHER_LDFLAGS = "";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "CloverDaemonNew/CloverDaemonNew-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
@ -301,7 +294,8 @@
MACOSX_DEPLOYMENT_TARGET = 10.9;
OTHER_LDFLAGS = "";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "CloverDaemonNew/CloverDaemonNew-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
SWIFT_VERSION = 5.0;
};
name = Release;

View File

@ -1,5 +0,0 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "PowerObserver.h"

View File

@ -1,24 +0,0 @@
//
// PowerObserver.h
// CloverDaemonNew
//
// Created by vector sigma on 09/11/2019.
// Copyright © 2019 CloverHackyColor. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <IOKit/pwr_mgt/IOPMLib.h>
#import <IOKit/IOMessage.h>
NS_ASSUME_NONNULL_BEGIN
@interface PowerObserver : NSObject {
io_connect_t root_port;
io_object_t notifier;
}
- (void)registerPowerNotifications;
- (void)powerDidReceiveMessage:(natural_t)type argument:(void *)argument;
- (void)readAndCleanConflictingsKeys;
@end
NS_ASSUME_NONNULL_END

View File

@ -1,104 +0,0 @@
//
// PowerObserver.m
// CloverDaemonNew
//
// Created by vector sigma on 09/11/2019.
// Copyright © 2019 CloverHackyColor. All rights reserved.
//
#import "PowerObserver.h"
void powerCallback(void *refCon, io_service_t service, natural_t type, void *argument)
{
[(PowerObserver *)CFBridgingRelease(refCon)powerDidReceiveMessage: type argument: argument];
}
@implementation PowerObserver
- (id)init {
self = [super init];
if (self) {
[self registerPowerNotifications];
}
return self;
}
- (void)registerPowerNotifications {
printf("Registering for Power notifications..\n");
IONotificationPortRef notificationPort;
root_port = IORegisterForSystemPower((void *)CFBridgingRetain(self),
&notificationPort,
powerCallback,
&notifier);
if (root_port) {
CFRunLoopAddSource(CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(notificationPort),
kCFRunLoopDefaultMode);
} else {
printf("Can't register for Power notification.\n");
}
}
- (void)powerDidReceiveMessage:(natural_t)type argument:(void *)argument {
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MMM-dd HH:mm:ss"];
NSString *date = [formatter stringFromDate:[NSDate new]];
switch (type) {
case kIOMessageSystemWillSleep:{
printf("System Sleep called at %s\n", [date UTF8String]);
break;
}
case kIOMessageSystemHasPoweredOn:{
printf("System awaken at %s\n", [date UTF8String]);
[self performSelector:@selector(readAndCleanConflictingsKeys) withObject:nil afterDelay:3];
break;
}
}
}
- (void)readAndCleanConflictingsKeys {
if ([[NSFileManager defaultManager] fileExistsAtPath:@"/nvram.plist"]) {
printf("Found /nvram.plist after waking from sleep, checking fro Apple GUIDs..\n");
NSMutableDictionary *nvram = [NSMutableDictionary dictionaryWithContentsOfFile:@"/nvram.plist"];
if (nvram != nil) {
NSArray *keys = [nvram allKeys];
int removed = 0;
for (int i = 0; i < [keys count]; i++) {
NSString *key = [keys objectAtIndex:i];
if ([key hasPrefix:@"8BE4DF61-93CA-11D2-AA0D-00E098032B8C:"]) {
printf("/nvram.plist contains %s\n", [key UTF8String]);
}
if ([key isEqualToString: @"efi-backup-boot-device"]) {
printf("removing %s.\n", [key UTF8String]);
[nvram removeObjectForKey:@"efi-backup-boot-device"];
}
if ([key isEqualToString: @"efi-backup-boot-device-data"]) {
printf("removing %s.\n", [key UTF8String]);
[nvram removeObjectForKey:@"efi-backup-boot-device-data"];
}
if ([key isEqualToString: @"install-product-url"]) {
printf("removing %s.\n", [key UTF8String]);
[nvram removeObjectForKey:@"install-product-url"];
}
if ([key isEqualToString: @"previous-system-uuid"]) {
printf("removing %s.\n", [key UTF8String]);
[nvram removeObjectForKey:@"previous-system-uuid"];
}
}
if (removed > 0) {
if (![nvram writeToFile:@"/nvram.plist" atomically:YES]) {
printf("Error: cannot write back to /nvram.plist.\n");
} else {
system("/usr/bin/chflags hidden /nvram.plist");
}
}
}
}
}
@end

View File

@ -9,7 +9,7 @@
import Foundation
let fm = FileManager.default
let daemonVersion = "1.0.3"
let daemonVersion = "1.0.4"
let wrapperPath = "/Library/Application Support/Clover/CloverWrapper.sh"
let loginwindow = "/var/root/Library/Preferences/com.apple.loginwindow.plist"
@ -114,6 +114,7 @@ func getLogOutHook() -> String? {
func main() {
let df = DateFormatter()
df.locale = Locale(identifier: "en_US")
df.dateFormat = "yyyy-MM-dd hh:mm:ss"
var now = df.string(from: Date())
@ -123,7 +124,6 @@ func main() {
print("- System start at \(now)")
print("------")
run(cmd: "kextunload /System/Library/Extensions/msdosfs.kext 2>/dev/null")
let _ : PowerObserver? = PowerObserver()
if let volname = getMediaName(from: "/") {
print("root mount point is '/Volumes/\(volname)'")
}
@ -135,12 +135,39 @@ func main() {
}
// check if old daemon exist
let myDir = (CommandLine.arguments[0] as NSString).deletingLastPathComponent
if fm.fileExists(atPath: "\(myDir)/CloverDaemon") {
let oldLaunchDaemon = "/Library/LaunchDaemons/com.slice.CloverDaemonNew.plist"
if fm.fileExists(atPath: oldLaunchDaemon) {
print("unloading old CloverDaemon")
run(cmd: "launchctl unload /Library/LaunchDaemons/com.projectosx.clover.daemon.plist")
run(cmd: "launchctl unload \(oldLaunchDaemon)")
try? fm.removeItem(atPath: oldLaunchDaemon)
if fm.fileExists(atPath: "/Library/Application Support/Clover/CloverDaemon") {
try? fm.removeItem(atPath: "/Library/Application Support/Clover/CloverDaemon")
}
if fm.fileExists(atPath: "/Library/Application Support/Clover/CloverDaemon-stopservice") {
try? fm.removeItem(atPath: "/Library/Application Support/Clover/CloverDaemon-stopservice")
}
}
let oldRCScripts : [String] = ["/Library/Application Support/Clover/CloverDaemon-stopservice",
"/etc/rc.boot.d/10.save_and_rotate_boot_log.local",
"/etc/rc.boot.d/20.mount_ESP.local",
"/etc/rc.boot.d/70.disable_sleep_proxy_client.local.disabled",
"/etc/rc.boot.d/70.disable_sleep_proxy_client.local",
"/etc/rc.clover.lib",
"/etc/rc.shutdown.d/80.save_nvram_plist.local"];
if fm.fileExists(atPath: "/etc/rc.clover.lib") {
for rc in oldRCScripts {
print("Removing old rc scripts..")
run(cmd: "mount -uw /")
sleep(2)
if fm.fileExists(atPath: rc) {
try? fm.removeItem(atPath: rc)
}
}
}
/*
Clean some lines from clover.daemon.log.
This is not going to go into the System log and is not
@ -272,27 +299,33 @@ func main() {
sleep(2)
}
}
checkSleepProxyClient(nvram: nvram)
}
checkSleepProxyClient(nvram: nvram)
/*
Clean old nvram.plist user may have in all volumes
Note: never delete in / as this will be done at shut down/restart
if the nvram is correctly saved somewhere else (e.g. in the ESP)
*/
/*
for v in getVolumes() {
let nvramtPath = v.addPath("nvram.plist")
if fm.fileExists(atPath: nvramtPath) {
if fm.isDeletableFile(atPath: nvramtPath) {
do {
try fm.removeItem(atPath: nvramtPath)
print("old '\(nvramtPath)' removed.")
} catch {
print("Error: can't remove '\(nvramtPath)'.")
if v != "/" {
if fm.fileExists(atPath: nvramtPath) {
if fm.isDeletableFile(atPath: nvramtPath) {
do {
try fm.removeItem(atPath: nvramtPath)
print("old '\(nvramtPath)' removed.")
} catch {
print("Error: can't remove '\(nvramtPath)'.")
}
} else {
print("Error: '\(nvramtPath)' is not deletable.")
}
} else {
print("Error: '\(nvramtPath)' is not deletable.")
}
}
}
*/
} else {
print("Error: nvram not present in this System.")
}
@ -304,7 +337,6 @@ func main() {
now = df.string(from: Date())
print("")
print("SIGTERM received at \(now)")
//print("- CloverDaemonNew v\(daemonVersion)")
doJob()
}
sigtermSource.resume()

View File

@ -8,6 +8,9 @@
import Foundation
let cmdVersion = "1.0.2"
let savedNVRAMPath = "/tmp/NVRAM_saved"
func log(_ str: String) {
let logUrl = URL(fileURLWithPath: "/Library/Logs/CloverEFI/clover.daemon.log")
@ -41,6 +44,7 @@ func run(cmd: String) {
}
func saveNVRAM(nvram: NSMutableDictionary, volume: String) {
/*
if (nvram.object(forKey: "efi-backup-boot-device") != nil) {
nvram.removeObject(forKey: "efi-backup-boot-device")
}
@ -56,37 +60,64 @@ func saveNVRAM(nvram: NSMutableDictionary, volume: String) {
if (nvram.object(forKey: "previous-system-uuid") != nil) {
nvram.removeObject(forKey: "previous-system-uuid")
}
if fm.fileExists(atPath: "/nvram.plist") {
do {
try fm.removeItem(atPath: "/nvram.plist")
} catch {
log("\(error)")
}
}
*/
let bsdname = getBSDName(of: volume) ?? ""
let uuid = getVolumeUUID(from: bsdname) ?? kNotAvailable
if nvram.write(toFile: volume.addPath("nvram.plist"), atomically: false) {
if volume == "/" {
run(cmd: "chflags hidden /nvram.plist")
}
log("nvram correctly saved to \(volume) with UUID: \(uuid).")
nvram.write(toFile: savedNVRAMPath, atomically: false)
if volume != "/" {
if fm.fileExists(atPath: "/nvram.plist") {
do {
try fm.removeItem(atPath: "/nvram.plist")
} catch {
log("\(error)")
}
}
}
} else {
log("Error: nvram cannot be saved to \(volume) with UUID: \(uuid).")
}
}
func disableInsexing(for volume: String) {
if fm.fileExists(atPath: volume) {
var file = volume.addPath(".metadata_never_index")
if !fm.fileExists(atPath: file) {
try? "".write(toFile: file, atomically: false, encoding: .utf8)
}
file = volume.addPath(".Spotlight-V100")
if fm.fileExists(atPath: volume.addPath("")) {
try? fm.removeItem(atPath: file)
}
}
}
func main() {
let df = DateFormatter()
df.dateFormat = "yyyy-MM-dd hh:mm:ss"
df.locale = Locale(identifier: "en_US")
var now = df.string(from: Date())
log("- CloverLogOut: begin at \(now)")
log("- CloverLogOut v\(cmdVersion): logout begin at \(now)")
if let nvram = getNVRAM() {
// Check if we're running from CloverEFI
if (nvram.object(forKey: "EmuVariableUefiPresent") != nil ||
nvram.object(forKey: "TestEmuVariableUefiPresent") != nil) {
// we already saved once? Check if the nvram is changed
if fm.fileExists(atPath: savedNVRAMPath) {
if let old = NSDictionary(contentsOfFile: savedNVRAMPath) {
if nvram.isEqual(to: old) {
log("nvram not changed, nothing to do.")
log("- CloverLogOut: end at \(now)")
exit(EXIT_SUCCESS)
}
}
}
var disk : String? = nil
var espList = [String]()
@ -125,47 +156,50 @@ func main() {
// get the mount point or mount it
var mounted : Bool = false
if let mp = getMountPoint(from: disk!) {
mounted = true
log("\(disk!) was already mounted.")
saveNVRAM(nvram: nvram, volume: mp)
if espList.contains(disk!) {
disableInsexing(for: mp)
}
return
}
if !mounted {
log("mount begin for \(disk!)..")
var mountattempts : Int = 0
repeat {
mount(disk: disk!, at: nil) { (result) in
mountattempts+=1
log("mounting \(disk!)..")
mount(disk: disk!, at: nil) { (result) in
if result == true {
sleep(1)
if result == true {
var attempts = 0
repeat {
sleep(1)
attempts+=1
if let mp = getMountPoint(from: disk!) {
mounted = true
mountattempts = 5
saveNVRAM(nvram: nvram, volume: mp)
sleep(1)
umount(disk: disk!, force: true)
break
var attempts = 0
repeat {
attempts+=1
if let mp = getMountPoint(from: disk!) {
mounted = true
saveNVRAM(nvram: nvram, volume: mp)
if espList.contains(disk!) {
disableInsexing(for: mp)
}
} while (getMountPoint(from: disk!) == nil || attempts > 10)
}
sleep(1)
umount(disk: disk!, force: true)
break
}
} while (mounted || attempts == 5)
}
} while mountattempts < 5
if !mounted {
log("mount failed for \(disk!).")
saveNVRAM(nvram: nvram, volume: "/")
}
} else {
// CloverDaemonNew should have made the fs read-write for us.
}
if !mounted {
log("mount failed for \(disk!).")
saveNVRAM(nvram: nvram, volume: "/")
}
} else {
// CloverDaemonNew should have made the fs read-write for us.
saveNVRAM(nvram: nvram, volume: "/")
}
} else {
log("EmuVariableUefi is not present, nvram will not be saved.")
}
} else {
log("Error: non nvram to be saved.")
}
now = df.string(from: Date())

View File

@ -49,8 +49,8 @@ fi
if [ "${filesystem}" != fat32 ] && \
[ "${filesystem}" != hfs ] && \
[ "${filesystem}" != exfat ]; then
[ "${filesystem}" != exfat ] && \
[ "${filesystem}" != hfs ]; then
echo "Error: unsupported filesystem \"${filesystem}\""
exit 1
fi
@ -70,16 +70,16 @@ if [[ ! -f "${boot1install}" ]]; then
exit 1
fi
chmod +x "${boot1install}"
# chmod +x "${boot1install}"
rootdisk=$(LC_ALL=C diskutil info / | grep -i 'device identifier:' | awk '{print $NF}')
rootdisk=$(LC_ALL=C /usr/sbin/diskutil info / | grep -i 'device identifier:' | awk '{print $NF}')
if [[ "${rootdisk}" == "${disk}" ]]; then
keepmounted=1
fi
echo
LC_ALL=C diskutil list
LC_ALL=C /usr/sbin/diskutil list
echo
# hfs can cause a panic writing boot sectors if journaled
@ -89,58 +89,51 @@ echo
# panic("jnl: end_tr: !!!DANGER!!! bp %p flags (0x%x) not LOCKED & DELWRI\n", bp, buf_flags(bp));
# fix? disable the journal (will be reactivated later)
if [[ $(LC_ALL=C diskutil info "${disk}" | grep -i 'file system personality:') == *ournaled* ]]; then
diskutil disableJournal "${disk}"
if [[ $(LC_ALL=C /usr/sbin/diskutil info "${disk}" | grep -i 'file system personality:') == *ournaled* ]]; then
/usr/sbin/diskutil disableJournal "${disk}"
journaled=1
fi
# Try to unmount the partition first
mnt_pt=$(LC_ALL=C mount | egrep "^$bootdev on" | sed 's/^.* on *//;s/ ([^(]*//')
mnt_pt=$(LC_ALL=C /sbin/mount | egrep "^$bootdev on" | sed 's/^.* on *//;s/ ([^(]*//')
if [[ $keepmounted -eq 0 ]]; then
if [[ -n "$mnt_pt" ]]; then
# Try to umount the partition with umount
umount $bootdev 2>/dev/null
/sbin/umount $bootdev 2>/dev/null
if [[ $? -ne 0 ]]; then
# If it doesn't work try with diskutil
diskutil unmount $bootdev 2>/dev/null
/usr/sbin/diskutil unmount $bootdev 2>/dev/null
[[ $? -ne 0 ]] && mnt_pt=''
fi
fi
fi
### Stage 0 ###
echo
echo "Stage 0 - Writing ${boot0} to ${bootrdisk}"
echo "Executing: dd if=${bootrdisk} count=1 bs=512 of=/tmp/CloverOrigMBR"
dd if="${bootrdisk}" count=1 bs=512 of=/tmp/CloverOrigMBR
/bin/dd if="${bootrdisk}" count=1 bs=512 of=/tmp/CloverOrigMBR
echo "Executing: cp /tmp/CloverOrigMBR /tmp/CloverNewMBR"
cp /tmp/CloverOrigMBR /tmp/CloverNewMBR
/bin/cp -R /tmp/CloverOrigMBR /tmp/CloverNewMBR
echo "Executing: dd if=${boot0} of=/tmp/CloverNewMBR bs=440 count=1 conv=notrunc"
dd if="${boot0}" of=/tmp/CloverNewMBR bs=440 count=1 conv=notrunc
/bin/dd if="${boot0}" of=/tmp/CloverNewMBR bs=440 count=1 conv=notrunc
echo "Executing: fdisk -f /tmp/CloverNewMBR -u -y ${bootrdisk}"
fdisk -f /tmp/CloverNewMBR -u -y "${bootrdisk}"
/usr/sbin/fdisk -f /tmp/CloverNewMBR -u -y "${bootrdisk}"
### Stage 1 ###
echo
echo "Stage 1 - Writing ${boot1} to ${bootrdev}"
if [[ $keepmounted -eq 0 ]]; then
echo "Executing: boot1-install -y -f -M "${boot1}" "${bootrdev}"
if [[ $keepmounted -eq 1 ]]; then
echo "Executing: boot1-install -y -f -M ${boot1} ${bootrdev}"
"$boot1install" -y -f -M "${boot1}" "${bootrdev}"
else
echo "Executing: boot1-install -y -f "${boot1}" "${bootrdev}"
echo "Executing: boot1-install -y -f ${boot1} ${bootrdev}"
"$boot1install" -y -f "${boot1}" "${bootrdev}"
fi
# Now try to remount the partition
if [[ -n "$mnt_pt" ]]; then
[[ ! -d "$mnt_pt" ]] && mkdir -p "$mnt_pt"
# First try to mount with the mount command
mount -t "$filesystem" "$bootdev" "$mnt_pt"
# If failed try with diskutil
[[ $? -ne 0 ]] && diskutil mount -mountPoint "$mnt_pt" "$bootdev"
fi
if [[ "${partition_scheme}" == FDisk_partition_scheme && "$boot0" == "/tmp/boot0af" ]]; then
echo "Setup Active Partition to be: ${bootslice}"
fdisk -e "${bootrdisk}" <<-MAKEACTIVE
/usr/sbin/fdisk -e "${bootrdisk}" <<-MAKEACTIVE
print
flag "${bootslice}"
write
@ -148,18 +141,26 @@ y
quit
MAKEACTIVE
partitionactive=$( fdisk -d "${bootrdisk}" | grep -n "*" | awk -F: '{print $1}')
partitionactive=$( /usr/sbin/fdisk -d "${bootrdisk}" | grep -n "*" | awk -F: '{print $1}')
echo "New Active Partition: ${partitionactive}"
echo ""
fi
if [[ $journaled -ne 0 ]]; then
diskutil enableJournal "${disk}"
sleep 2
# Now try to remount the partition
if [[ -n "$mnt_pt" ]]; then
/usr/sbin/diskutil mount "$bootdev"
fi
rm -rf /tmp/Clover*
rm -rf /tmp/boot1*
rm -rf /tmp/boot2*
rm -rf /tmp/bootsec*
if [[ $journaled -ne 0 ]]; then
/usr/sbin/diskutil enableJournal "${disk}"
fi
/bin/rm -rf /tmp/Clover*
/bin/rm -rf /tmp/boot1*
/bin/rm -rf /tmp/boot2*
/bin/rm -rf /tmp/bootsec*
exit 0

View File

@ -431,6 +431,12 @@ int main(int argc, char * const * argv) {
/tmp/bootsectors-install disk4s1 hfs FDisk_partition_scheme boot0af boot1h
*/
NSTask *task = [[NSTask alloc] init];
NSPipe *pipe = [NSPipe new];
task.standardOutput = pipe;
task.standardError = pipe;
NSFileHandle * fh = [pipe fileHandleForReading];
[task setEnvironment:[[NSProcessInfo new] environment]];
[task setLaunchPath:bootSectorsInstall];
@ -442,6 +448,14 @@ int main(int argc, char * const * argv) {
}
};
[task launch];
//[task waitUntilExit];
NSData *data = [fh readDataToEndOfFile];
if (data) {
NSString *output = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
printf("%s\n", [output UTF8String]);
}
}
cleanUp();
exit(EXIT_SUCCESS);