X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/0c0a966bea2bf3b32d0a5abb2658dd22215e9c7f..a02d4e989ec1ecf82da7044375b4010f1b572883:/postinst.mm diff --git a/postinst.mm b/postinst.mm index 45a7da37..f826f4ff 100644 --- a/postinst.mm +++ b/postinst.mm @@ -1,3 +1,5 @@ +#include "CyteKit/UCPlatform.h" + #include #include @@ -28,46 +30,52 @@ static bool setnsfpn(const char *path) { return system([[NSString stringWithFormat:@"/usr/libexec/cydia/setnsfpn %s", path] UTF8String]) == 0; } -static bool MoveStash() { +enum StashStatus { + StashDone, + StashFail, + StashGood, +}; + +static StashStatus MoveStash() { struct stat stat; if (lstat("/var/stash", &stat) == -1) - return errno == ENOENT; + return errno == ENOENT ? StashGood : StashFail; else if (S_ISLNK(stat.st_mode)) - return true; + return StashGood; else if (!S_ISDIR(stat.st_mode)) - return false; + return StashFail; if (lstat("/var/db/stash", &stat) == -1) { if (errno == ENOENT) goto move; - else return false; + else return StashFail; } else if (S_ISLNK(stat.st_mode)) // XXX: this is fixable - return false; + return StashFail; else if (!S_ISDIR(stat.st_mode)) - return false; + return StashFail; else { if (!setnsfpn("/var/db/stash")) - return false; + return StashFail; if (system("mv -t /var/stash /var/db/stash/*") != 0) - return false; + return StashFail; if (rmdir("/var/db/stash") == -1) - return false; + return StashFail; } move: if (!setnsfpn("/var/stash")) - return false; + return StashFail; if (rename("/var/stash", "/var/db/stash") == -1) - return false; + return StashFail; if (symlink("/var/db/stash", "/var/stash") != -1) - return true; + return StashDone; if (rename("/var/db/stash", "/var/stash") != -1) - return false; + return StashFail; fprintf(stderr, "/var/stash misplaced -- DO NOT REBOOT\n"); - return false; + return StashFail; } static bool FixProtections() { @@ -171,11 +179,6 @@ static bool FixApplications() { } } -_H Sources_; -bool Changed_; - -_H System_; - int main(int argc, const char *argv[]) { if (argc < 2 || strcmp(argv[1], "configure") != 0) return 0; @@ -187,42 +190,18 @@ int main(int argc, const char *argv[]) { if (kCFCoreFoundationVersionNumber >= 1000) { if (!FixProtections()) return 1; - if (MoveStash()) - restart = true; - else { - fprintf(stderr, "failed to move stash\n"); - return 1; + switch (MoveStash()) { + case StashDone: + restart = true; + break; + case StashFail: + fprintf(stderr, "failed to move stash\n"); + return 1; + case StashGood: + break; } } - 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(); - #define OldCache_ "/var/root/Library/Caches/com.saurik.Cydia" if (access(OldCache_, F_OK) == 0) system("rm -rf " OldCache_); @@ -240,6 +219,15 @@ int main(int argc, const char *argv[]) { #define Cytore_ "/metadata.cb0" + #define CYDIA_LIST "/etc/apt/sources.list.d/cydia.list" + unlink(CYDIA_LIST); + [[NSString stringWithFormat:@ + "deb http://apt.saurik.com/ ios/%.2f main\n" + "deb http://apt.thebigboss.org/repofiles/cydia/ stable main\n" + "deb http://cydia.zodttd.com/repo/cydia/ stable main\n" + "deb http://apt.modmyi.com/ stable main\n" + , kCFCoreFoundationVersionNumber] writeToFile:@ CYDIA_LIST atomically:YES]; + if (access(NewLibrary_ Cytore_, F_OK) != 0 && errno == ENOENT) { if (access(NewCache_ Cytore_, F_OK) == 0) system("mv -f " NewCache_ Cytore_ " " NewLibrary_);