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");
75 if (symlink(destiny, APPLICATIONS) != -1)
78 fprintf(stderr, "/var/stash/Applications damaged -- DO NOT REBOOT\n");
82 // unneccessary, but feels better (I'm nervous)
83 symlink(destiny, target);
85 [@APPLICATIONS writeToFile:[NSString stringWithFormat:@"%s.lnk", temp] atomically:YES encoding:NSNonLossyASCIIStringEncoding error:NULL];
90 _H<NSMutableDictionary> Sources_;
95 int main(int argc, const char *argv[]) {
96 if (argc < 2 || strcmp(argv[1], "configure") != 0)
99 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
102 sysctlbyname("kern.osversion", NULL, &size, NULL, 0);
103 char *osversion = new char[size];
104 if (sysctlbyname("kern.osversion", osversion, &size, NULL, 0) != -1)
105 System_ = [NSString stringWithUTF8String:osversion];
107 NSDictionary *metadata([[[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/metadata.plist"] autorelease]);
108 NSUInteger version(0);
110 if (metadata != nil) {
111 Sources_ = [metadata objectForKey:@"Sources"];
113 if (NSNumber *number = [metadata objectForKey:@"Version"])
114 version = [number unsignedIntValue];
118 Sources_ = [NSMutableDictionary dictionaryWithCapacity:8];
121 CydiaAddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
122 CydiaAddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
123 CydiaAddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
124 CydiaAddSource(@"http://repo666.ultrasn0w.com/", @"./");
129 if (FixApplications())