Run migration with proper user environment

Signed-off-by: Jeffrey Morgan <jmorganca@gmail.com>
This commit is contained in:
Jeffrey Morgan 2015-08-29 12:25:20 -07:00
parent a1733898c3
commit 6c547e9108
5 changed files with 19 additions and 14 deletions

View File

@ -53,7 +53,7 @@
1B4C91C31B85198100A06068 /* InstallerSections.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = InstallerSections.plist; sourceTree = "<group>"; };
1B8417E71B85261F00B1FA4D /* kitematic.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = kitematic.png; sourceTree = "<group>"; };
1B8417E81B85261F00B1FA4D /* quickstart.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = quickstart.png; sourceTree = "<group>"; };
1BDCE93A1B914EE2009C3488 /* informationplugin.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; name = informationplugin.bundle; path = /Users/jmorgan/workspace/toolbox/osx/installerplugins/build/Debug/informationplugin.bundle; sourceTree = "<absolute>"; };
1BBD8C711B9236E600E2B28A /* informationplugin.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; name = informationplugin.bundle; path = /Users/jmorgan/workspace/toolbox/osx/installerplugins/build/Debug/informationplugin.bundle; sourceTree = "<absolute>"; };
1BF102BB1B8BDEDA00FCB650 /* overviewplugin.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = overviewplugin.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
1BF102BE1B8BDEDA00FCB650 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
1BF102C01B8BDEDA00FCB650 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
@ -241,7 +241,7 @@
);
name = informationplugin;
productName = informationplugin;
productReference = 1BDCE93A1B914EE2009C3488 /* informationplugin.bundle */;
productReference = 1BBD8C711B9236E600E2B28A /* informationplugin.bundle */;
productType = "com.apple.product-type.bundle";
};
1BF102BA1B8BDEDA00FCB650 /* overviewplugin */ = {

View File

@ -20,7 +20,7 @@ NSString *vBoxManagePath = @"/Applications/VirtualBox.app/Contents/MacOS/VBoxMan
NSString *dockerMachinePath = @"/usr/local/bin/docker-machine";
- (BOOL) vmExists:(NSString*)name {
NSTask* task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/sudo" arguments:[NSArray arrayWithObjects:@"-u", NSUserName(), vBoxManagePath, @"showvminfo", name, nil]];
NSTask* task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/sudo" arguments:[NSArray arrayWithObjects:@"-i", @"-u", NSUserName(), vBoxManagePath, @"showvminfo", name, nil]];
[task waitUntilExit];
return [task terminationStatus] != 1;
}
@ -55,7 +55,7 @@ NSString *dockerMachinePath = @"/usr/local/bin/docker-machine";
self.migrating = YES;
// Remove existing vm if it exists (obviously user must have deleted the
NSTask* removeVMTask = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/sudo" arguments:[NSArray arrayWithObjects:@"-u", NSUserName(), dockerMachinePath, @"rm", @"-f", @"default", nil]];
NSTask* removeVMTask = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/sudo" arguments:[NSArray arrayWithObjects:@"-i", @"-u", NSUserName(), dockerMachinePath, @"rm", @"-f", @"default", nil]];
[removeVMTask waitUntilExit];
// Remove the VM dir in case there's anything left over
@ -65,16 +65,15 @@ NSString *dockerMachinePath = @"/usr/local/bin/docker-machine";
// Do the migration
NSTask* migrateTask = [[NSTask alloc] init];
migrateTask.launchPath = @"/usr/bin/sudo";
migrateTask.arguments = [NSArray arrayWithObjects:@"-u", NSUserName(), dockerMachinePath, @"-D", @"create", @"-d", @"virtualbox", @"--virtualbox-import-boot2docker-vm", @"boot2docker-vm", @"default", nil];
migrateTask.arguments = [NSArray arrayWithObjects:@"-i", @"-u", NSUserName(), dockerMachinePath, @"-D", @"create", @"-d", @"virtualbox", @"--virtualbox-memory", @"2048", @"--virtualbox-import-boot2docker-vm", @"boot2docker-vm", @"default", nil];
// Remove certificates, ssh keys from logs
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"BEGIN.*END" options:NSRegularExpressionDotMatchesLineSeparators error:NULL];
NSFont *font = [NSFont fontWithName:@"Menlo" size:10.0];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
NSMutableData* fullData = [[NSMutableData alloc] init];
migrateTask.standardOutput = [NSPipe pipe];
[[migrateTask.standardOutput fileHandleForReading] setReadabilityHandler:^(NSFileHandle *file) {
void (^appendOutput)(NSFileHandle*) = ^(NSFileHandle *file) {
NSData *data = [file availableData];
[fullData appendData:data];
NSMutableString *str = [[NSMutableString alloc] initWithData:fullData encoding:NSUTF8StringEncoding];
@ -84,7 +83,13 @@ NSString *dockerMachinePath = @"/usr/local/bin/docker-machine";
[self.migrationLogsTextView.textStorage setAttributedString:[[NSAttributedString alloc] initWithString:str attributes:attrsDictionary]];
[self.migrationLogsTextView scrollRangeToVisible:NSMakeRange([[self.migrationLogsTextView string] length], 0)];
});
}];
};
migrateTask.standardOutput = [NSPipe pipe];
migrateTask.standardError = [NSPipe pipe];
[[migrateTask.standardOutput fileHandleForReading] setReadabilityHandler:appendOutput];
[[migrateTask.standardError fileHandleForReading] setReadabilityHandler:appendOutput];
migrateTask.terminationHandler = ^(NSTask* task) {
dispatch_async(dispatch_get_main_queue(), ^{

View File

@ -31,15 +31,15 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView horizontalCompressionResistancePriority="250" editable="NO" importsGraphics="NO" verticallyResizable="NO" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" usesFontPanel="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="cgA-DY-Gw8">
<rect key="frame" x="0.0" y="0.0" width="223" height="283"/>
<rect key="frame" x="0.0" y="0.0" width="223" height="100"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="378" height="100"/>
<size key="maxSize" width="463" height="100"/>
<size key="minSize" width="378" height="190"/>
<size key="maxSize" width="463" height="190"/>
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="378" height="100"/>
<size key="maxSize" width="463" height="100"/>
<size key="minSize" width="378" height="190"/>
<size key="maxSize" width="463" height="190"/>
</textView>
</subviews>
<animations/>