7 #include <sys/sysctl.h>
10 #include <Menes/ObjectHandle.h>
12 void Finish(const char *finish) {
16 const char *cydia(getenv("CYDIA"));
20 int fd([[[[NSString stringWithUTF8String:cydia] componentsSeparatedByString:@" "] objectAtIndex:0] intValue]);
22 FILE *fout(fdopen(fd, "w"));
23 fprintf(fout, "finish:%s\n", finish);
27 #define APPLICATIONS "/Applications"
28 static bool FixApplications() {
30 ssize_t length(readlink(APPLICATIONS, target, sizeof(target)));
34 if (length >= sizeof(target)) // >= "just in case" (I'm nervous)
36 target[length] = '\0';
38 if (strlen(target) != 30)
40 if (memcmp(target, "/var/stash/Applications.", 24) != 0)
42 if (strchr(target + 24, '/') != NULL)
46 if (lstat(target, &stat) == -1)
48 if (!S_ISDIR(stat.st_mode))
51 char temp[] = "/var/stash/_.XXXXXX";
52 if (mkdtemp(temp) == NULL)
60 if (chmod(temp, 0755) == -1)
63 char destiny[strlen(temp) + 32];
64 sprintf(destiny, "%s%s", temp, APPLICATIONS);
66 if (unlink(APPLICATIONS) == -1)
69 if (rename(target, destiny) == -1) {
70 if (symlink(target, APPLICATIONS) == -1)
71 fprintf(stderr, "/Applications damaged -- DO NOT REBOOT\n");
74 if (symlink(destiny, APPLICATIONS) == -1)
75 fprintf(stderr, "/var/stash/Applications damaged -- DO NOT REBOOT\n");
77 // unneccessary, but feels better (I'm nervous)
78 symlink(destiny, target);
80 [@APPLICATIONS writeToFile:[NSString stringWithFormat:@"%s.lnk", temp] atomically:YES encoding:NSNonLossyASCIIStringEncoding error:NULL];
85 _H<NSMutableDictionary> Sources_;
90 int main(int argc, const char *argv[]) {
91 if (argc < 2 || strcmp(argv[1], "configure") != 0)
94 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
97 sysctlbyname("kern.osversion", NULL, &size, NULL, 0);
98 char *osversion = new char[size];
99 if (sysctlbyname("kern.osversion", osversion, &size, NULL, 0) != -1)
100 System_ = [NSString stringWithUTF8String:osversion];
102 NSDictionary *metadata([[[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/metadata.plist"] autorelease]);
103 NSUInteger version(0);
105 if (metadata != nil) {
106 Sources_ = [metadata objectForKey:@"Sources"];
108 if (NSNumber *number = [metadata objectForKey:@"Version"])
109 version = [number unsignedIntValue];
113 Sources_ = [NSMutableDictionary dictionaryWithCapacity:8];
116 CydiaAddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
117 CydiaAddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
118 CydiaAddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
119 CydiaAddSource(@"http://repo666.ultrasn0w.com/", @"./");
124 if (FixApplications())