Skip to content

Commit

Permalink
WIP on app booting.
Browse files Browse the repository at this point in the history
  • Loading branch information
patr1ck committed Apr 25, 2013
1 parent 1882b77 commit 768b114
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
4 changes: 4 additions & 0 deletions Tokaido.xcodeproj/project.pbxproj
Expand Up @@ -47,6 +47,7 @@
CD8285AE16559D96000CB252 /* Red.png in Resources */ = {isa = PBXBuildFile; fileRef = CD8285AB16559D96000CB252 /* Red.png */; };
CD8285B11655A696000CB252 /* down_arrow.png in Resources */ = {isa = PBXBuildFile; fileRef = CD8285B01655A696000CB252 /* down_arrow.png */; };
CD8285DF1655B7DF000CB252 /* TKDAppCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = CD8285DD1655B670000CB252 /* TKDAppCollectionView.m */; };
CDB963F617288901002A8A43 /* tokaido-gems.zip in Resources */ = {isa = PBXBuildFile; fileRef = CDB963F517288901002A8A43 /* tokaido-gems.zip */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -132,6 +133,7 @@
CD8285B01655A696000CB252 /* down_arrow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = down_arrow.png; sourceTree = "<group>"; };
CD8285DC1655B670000CB252 /* TKDAppCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TKDAppCollectionView.h; sourceTree = "<group>"; };
CD8285DD1655B670000CB252 /* TKDAppCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TKDAppCollectionView.m; sourceTree = "<group>"; };
CDB963F517288901002A8A43 /* tokaido-gems.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = "tokaido-gems.zip"; sourceTree = "<group>"; };
E4032CA2B44246FFAF8D38DF /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -273,6 +275,7 @@
3AD6934E1637557D005AF81E /* Ruby Bundles */ = {
isa = PBXGroup;
children = (
CDB963F517288901002A8A43 /* tokaido-gems.zip */,
CD5A898D171CC96000217D8A /* tokaido-bootstrap.zip */,
3AD6934F16375589005AF81E /* 1.9.3-p194.zip */,
);
Expand Down Expand Up @@ -432,6 +435,7 @@
CD5A8934170B84EA00217D8A /* Yellow.png in Resources */,
CD5A8982171380E500217D8A /* EditAppWindow.xib in Resources */,
CD5A898E171CC96000217D8A /* tokaido-bootstrap.zip in Resources */,
CDB963F617288901002A8A43 /* tokaido-gems.zip in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 4 additions & 2 deletions Tokaido/SetupTokaido.sh
Expand Up @@ -6,9 +6,11 @@
# Created by Patrick B. Gibson on 10/23/12.
# Copyright (c) 2012 Tilde. All rights reserved.

export PATH=$TOKAIDO_PATH:$PATH
BIN="/bin"
export GEM_HOME=$TOKAIDO_GEM_HOME
export GEM_PATH=$TOKAIDO_GEM_HOME
export GEM_PATH=$TOKAIDO_GEM_HOME$BIN
export PATH=$TOKAIDO_PATH:$GEM_PATH:$PATH


cd "$TOKAIDO_APP_DIR"

Expand Down
39 changes: 32 additions & 7 deletions Tokaido/TKDAppDelegate.m
Expand Up @@ -26,7 +26,7 @@ @implementation TKDAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self ensureTokaidoAppSupportDirectoryIsUpToDate];
[self ensureTokaidoBootstrapGemsAreInstalled];
[self ensureTokaidoInstallIsInstalled];
[self ensureTokaidoBootstrapIsInstalled];
sleep(1);
[self stopTokaidoBootstrap];
Expand Down Expand Up @@ -207,7 +207,7 @@ - (void)ensureTokaidoBootstrapIsInstalled
}


- (void)ensureTokaidoBootstrapGemsAreInstalled
- (void)ensureTokaidoInstallIsInstalled
{
// Check if tokaido-bootstrap is where we expect it to be
NSString *bootstrapDir = [TKDAppDelegate tokaidoInstalledBootstrapDirectory];
Expand Down Expand Up @@ -367,7 +367,7 @@ + (NSString *)tokaidoBundledRubiesDirectory;

+ (NSString *)tokaidoBundledGemsFile;
{
NSString *tokaidoBundledRubiesDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"gems-default.zip"];
NSString *tokaidoBundledRubiesDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"tokaido-gems.zip"];
return tokaidoBundledRubiesDirectory;
}

Expand All @@ -380,19 +380,38 @@ + (NSString *)tokaidoBundledBootstrapFile

+ (NSString *)tokaidoAppSupportDirectory;
{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *applicationSupportDirectory = [paths objectAtIndex:0];
NSString *tokaidoDirectory = [NSString stringWithFormat:@"%@/Tokaido", applicationSupportDirectory];
[self createDirectoryAtPathIfNonExistant:tokaidoDirectory];
return tokaidoDirectory;


NSString *homeDirectory = NSHomeDirectory();
NSString *tokaidoDirectorySymlink = [homeDirectory stringByAppendingPathComponent:@"/.tokaido"];

NSFileManager *fm = [NSFileManager defaultManager];
if (![fm fileExistsAtPath:tokaidoDirectorySymlink]) {
NSError *error = nil;
[fm createSymbolicLinkAtPath:tokaidoDirectorySymlink withDestinationPath:tokaidoDirectory error:&error];
if (error) {
NSLog(@"ERROR: Couldn't create the .tokaido symlink.");
}
}

return tokaidoDirectorySymlink;
}

- (void)startTokaidoBootstrap
{
NSString *executablePath = [[@"~/Library/Application Support/Tokaido/ruby" stringByExpandingTildeInPath] stringByResolvingSymlinksInPath];
NSString *setupScriptPath = [[TKDAppDelegate tokaidoInstalledBootstrapDirectory]stringByAppendingPathComponent:@"bundle/bundler/setup.rb"];
NSString *executablePath = [[TKDAppDelegate tokaidoAppSupportDirectory] stringByAppendingPathComponent:@"/ruby"];
NSString *executableDirectory = [TKDAppDelegate tokaidoAppSupportDirectory];
NSString *setupScriptPath = [[TKDAppDelegate tokaidoInstalledBootstrapDirectory] stringByAppendingPathComponent:@"bundle/bundler/setup.rb"];
NSString *tokadioBootstrapScriptPath = [[TKDAppDelegate tokaidoInstalledBootstrapDirectory] stringByAppendingPathComponent:@"bin/tokaido-bootstrap"];
NSString *firewallPath = [TKDAppDelegate tokaidoInstalledFirewallDirectory];
NSString *gemHome = [TKDAppDelegate tokaidoInstalledGemsDirectory];
NSString *gemPath = [[TKDAppDelegate tokaidoInstalledGemsDirectory] stringByAppendingPathComponent:@"/bin"];
NSString *path = [executableDirectory stringByAppendingFormat:@":%@", gemPath];


NSMutableDictionary *plist = [NSMutableDictionary dictionary];
Expand All @@ -401,7 +420,13 @@ - (void)startTokaidoBootstrap
[plist setObject:@"/tmp/bootstrap.out" forKey:@"StandardOutPath"];
[plist setObject:@"/tmp/bootstrap.err" forKey:@"StandardErrorPath"];
[plist setObject:[NSNumber numberWithBool:YES] forKey:@"AbandonProcessGroup"];
[plist setObject:@{@"TOKAIDO_TMPDIR": firewallPath} forKey:@"EnvironmentVariables"];
[plist setObject:@{
@"TOKAIDO_TMPDIR": firewallPath,
@"PATH": path,
@"GEM_HOME": gemHome,
@"GEM_PATH": gemHome // Think we need this? Not really sure.
} forKey:@"EnvironmentVariables"];

[plist setObject:@[ executablePath, @"-r", setupScriptPath, tokadioBootstrapScriptPath ]
forKey:@"ProgramArguments"];

Expand Down
5 changes: 3 additions & 2 deletions Tokaido/TKDMuxrManager.m
Expand Up @@ -83,8 +83,10 @@ - (BOOL)readFromSocket:(int)fd
NSLog(@"size to read: %ld", estimated);

if (estimated == 1) {
NSLog(@"No more data to read, closing.");
NSLog(@"No more data to read.");
dispatch_source_cancel(readSource);
[self readFromSocket:fd];
return;
}

// Read the data into a text buffer.
Expand Down Expand Up @@ -150,7 +152,6 @@ - (void)addApp:(TKDApp *)app;
{
NSString *command = [NSString stringWithFormat:@"ADD \"%@\" \"%@\"\n", app.appDirectoryPath, app.appHostname];
[self issueCommand:command];
// [self issueCommand:command];
}

- (void)removeApp:(TKDApp *)app;
Expand Down
Binary file added Tokaido/tokaido-gems.zip
Binary file not shown.

0 comments on commit 768b114

Please sign in to comment.