summaryrefslogtreecommitdiff
path: root/postinst.mm
blob: 6e02dafd52b19bea44ad1550939c3f26f3408ce6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <strings.h>
#include <Sources.h>

#include <sys/types.h>
#include <sys/sysctl.h>

#include <CydiaSubstrate/CydiaSubstrate.h>

_H<NSMutableDictionary> Sources_;
bool Changed_;

_H<NSString> System_;

int main(int argc, const char *argv[]) {
    if (argc < 2 || strcmp(argv[1], "configure") != 0)
        return 0;

    NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);

    size_t size;
    sysctlbyname("kern.osversion", NULL, &size, NULL, 0);
    char *osversion = new char[size];
    if (sysctlbyname("kern.osversion", osversion, &size, NULL, 0) != -1)
        System_ = [NSString stringWithUTF8String:osversion];

    NSDictionary *metadata([[[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/metadata.plist"] autorelease]);
    NSUInteger version(0);

    if (metadata != nil) {
        Sources_ = [metadata objectForKey:@"Sources"];

        if (NSNumber *number = [metadata objectForKey:@"Version"])
            version = [number unsignedIntValue];
    }

    if (Sources_ == nil)
        Sources_ = [NSMutableDictionary dictionaryWithCapacity:8];

    if (version == 0) {
        CydiaAddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
        CydiaAddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
        CydiaAddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
        CydiaAddSource(@"http://repo666.ultrasn0w.com/", @"./");
    }

    CydiaWriteSources();

    [pool release];
    return 0;
}