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 static void FixPermissions() {
28 DIR *stash(opendir("/var/stash"));
32 while (dirent *entry = readdir(stash)) {
33 const char *folder(entry->d_name);
34 if (strlen(folder) != 8)
36 if (strncmp(folder, "_.", 2) != 0)
40 sprintf(path, "/var/stash/%s", folder);
43 if (lstat(path, &stat) == -1)
45 if (!S_ISDIR(stat.st_mode))
54 #define APPLICATIONS "/Applications"
55 static bool FixApplications() {
57 ssize_t length(readlink(APPLICATIONS, target, sizeof(target)));
61 if (length >= sizeof(target)) // >= "just in case" (I'm nervous)
63 target[length] = '\0';
65 if (strlen(target) != 30)
67 if (memcmp(target, "/var/stash/Applications.", 24) != 0)
69 if (strchr(target + 24, '/') != NULL)
73 if (lstat(target, &stat) == -1)
75 if (!S_ISDIR(stat.st_mode))
78 char temp[] = "/var/stash/_.XXXXXX";
79 if (mkdtemp(temp) == NULL)
87 if (chmod(temp, 0755) == -1)
90 char destiny[strlen(temp) + 32];
91 sprintf(destiny, "%s%s", temp, APPLICATIONS);
93 if (unlink(APPLICATIONS) == -1)
96 if (rename(target, destiny) == -1) {
97 if (symlink(target, APPLICATIONS) == -1)
98 fprintf(stderr, "/Applications damaged -- DO NOT REBOOT\n");
102 if (symlink(destiny, APPLICATIONS) != -1)
105 fprintf(stderr, "/var/stash/Applications damaged -- DO NOT REBOOT\n");
109 // unneccessary, but feels better (I'm nervous)
110 symlink(destiny, target);
112 [@APPLICATIONS writeToFile:[NSString stringWithFormat:@"%s.lnk", temp] atomically:YES encoding:NSNonLossyASCIIStringEncoding error:NULL];
117 _H<NSMutableDictionary> Sources_;
120 _H<NSString> System_;
122 int main(int argc, const char *argv[]) {
123 if (argc < 2 || strcmp(argv[1], "configure") != 0)
126 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
129 sysctlbyname("kern.osversion", NULL, &size, NULL, 0);
130 char *osversion = new char[size];
131 if (sysctlbyname("kern.osversion", osversion, &size, NULL, 0) != -1)
132 System_ = [NSString stringWithUTF8String:osversion];
134 NSDictionary *metadata([[[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/metadata.plist"] autorelease]);
135 NSUInteger version(0);
137 if (metadata != nil) {
138 Sources_ = [metadata objectForKey:@"Sources"];
140 if (NSNumber *number = [metadata objectForKey:@"Version"])
141 version = [number unsignedIntValue];
145 Sources_ = [NSMutableDictionary dictionaryWithCapacity:8];
148 CydiaAddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
149 CydiaAddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
150 CydiaAddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
151 CydiaAddSource(@"http://repo666.ultrasn0w.com/", @"./");
158 if (FixApplications())