Просмотр исходного кода

defer moving the files until after the initial file processing loop is finished, added ability to skip code sign checks, still need code sign checks to use ldid install of jtool

Kevin Bradley лет назад: 3
Родитель
Сommit
8e6d77f275

+ 1 - 0
bootstrapTool/Classes/InputPackage.h

@@ -11,6 +11,7 @@
 @property (nonatomic, strong) NSString *version;
 @property (nonatomic, strong) NSString *version;
 @property (nonatomic, strong) NSString *path;
 @property (nonatomic, strong) NSString *path;
 @property (nonatomic, strong) NSString *appendedPrefix;
 @property (nonatomic, strong) NSString *appendedPrefix;
+@property (readwrite, assign) BOOL skipSignatureChecks;
 
 
 
 
 - (void)bumpVersionInCurrentDirectory;
 - (void)bumpVersionInCurrentDirectory;

+ 19 - 21
bootstrapTool/Classes/InputPackage.m

@@ -324,7 +324,7 @@
 }
 }
 
 
 - (void)validateSignaturesInPath:(NSString *)thePath {
 - (void)validateSignaturesInPath:(NSString *)thePath {
-    
+    if (self.skipSignatureChecks) { return; }
     [self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
     [self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
         NSString *file = [thePath stringByAppendingPathComponent:obj.path];
         NSString *file = [thePath stringByAppendingPathComponent:obj.path];
         NSLog(@"check sig file: %@", file);
         NSLog(@"check sig file: %@", file);
@@ -339,7 +339,7 @@
     NSString *pwd = [HelperClass singleLineReturnForProcess:@"/bin/pwd"];
     NSString *pwd = [HelperClass singleLineReturnForProcess:@"/bin/pwd"];
     DLog(@"\nProcessing file: %@\n", self.path);
     DLog(@"\nProcessing file: %@\n", self.path);
     InputPackage *output = self;
     InputPackage *output = self;
-    
+    NSMutableArray *moveRoot = [NSMutableArray new];
     DLog(@"\nFound package: '%@' at version: '%@'...\n", output.packageName, output.version );
     DLog(@"\nFound package: '%@' at version: '%@'...\n", output.packageName, output.version );
     
     
     NSString *tmpPath = [pwd stringByAppendingPathComponent:output.packageName];
     NSString *tmpPath = [pwd stringByAppendingPathComponent:output.packageName];
@@ -396,19 +396,15 @@
                 [FM removeItemAtPath:fullPath error:nil];
                 [FM removeItemAtPath:fullPath error:nil];
                 
                 
             }
             }
-            if (self.appendedPrefix.length > 0) {
+            
+            if (self.appendedPrefix.length > 0 && [obj.path properPathComponents].count == 1) {
                 if (![obj.path containsString:self.appendedPrefix]){
                 if (![obj.path containsString:self.appendedPrefix]){
+                    [moveRoot addObject:obj.path];
                     DLog(@"[INFO] %@ doesnt have the prefix!", obj.path);
                     DLog(@"[INFO] %@ doesnt have the prefix!", obj.path);
-                    NSString *oldPath = [tmpPath stringByAppendingPathComponent:obj.path];
-                    NSString *newPath = [newRoot stringByAppendingPathComponent:obj.path];
-                    DLog(@"[INFO] moving %@ to %@", oldPath, newPath);
-                    [FM moveItemAtPath:oldPath toPath:newPath error:nil];
-                    
                 }
                 }
             }
             }
             NSArray *pathComponents = [obj.path pathComponents];
             NSArray *pathComponents = [obj.path pathComponents];
             if ([pathComponents count] > 1) {
             if ([pathComponents count] > 1) {
-                
                 NSString *rootPath = pathComponents[1];
                 NSString *rootPath = pathComponents[1];
                 //DLog(@"\n Checking root path: %@ for file %@\n", rootPath, obj.path);
                 //DLog(@"\n Checking root path: %@ for file %@\n", rootPath, obj.path);
                 if ([forbiddenRoots containsObject:rootPath]) {
                 if ([forbiddenRoots containsObject:rootPath]) {
@@ -426,6 +422,12 @@
             }
             }
         }
         }
     }];
     }];
+    [moveRoot enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        NSString *oldPath = [tmpPath stringByAppendingPathComponent:obj];
+        NSString *newPath = [newRoot stringByAppendingPathComponent:obj];
+        DLog(@"[INFO] moving %@ to %@", oldPath, newPath);
+        [FM moveItemAtPath:oldPath toPath:newPath error:nil];
+    }];
     NSString *depArchiveInfo = [NSString stringWithFormat:@"/usr/local/bin/dpkg -b %@", self.packageName];
     NSString *depArchiveInfo = [NSString stringWithFormat:@"/usr/local/bin/dpkg -b %@", self.packageName];
     if (fakeRoot) {
     if (fakeRoot) {
         depArchiveInfo = [NSString stringWithFormat:@"%@ /usr/local/bin/dpkg -b %@", fakeRoot, self.packageName];
         depArchiveInfo = [NSString stringWithFormat:@"%@ /usr/local/bin/dpkg -b %@", fakeRoot, self.packageName];
@@ -446,6 +448,7 @@
     NSString *tmpPath = [pwd stringByAppendingPathComponent:output.packageName];
     NSString *tmpPath = [pwd stringByAppendingPathComponent:output.packageName];
     NSString *debian = [tmpPath stringByAppendingPathComponent:@"DEBIAN"];
     NSString *debian = [tmpPath stringByAppendingPathComponent:@"DEBIAN"];
     NSString *newRoot = nil;
     NSString *newRoot = nil;
+    NSMutableArray *moveRoot = [NSMutableArray new];
     if (self.appendedPrefix) {
     if (self.appendedPrefix) {
         newRoot = [tmpPath stringByAppendingPathComponent:self.appendedPrefix];
         newRoot = [tmpPath stringByAppendingPathComponent:self.appendedPrefix];
         [FM createDirectoryAtPath:newRoot withIntermediateDirectories:true attributes:nil error:nil];
         [FM createDirectoryAtPath:newRoot withIntermediateDirectories:true attributes:nil error:nil];
@@ -552,10 +555,7 @@
             if (self.appendedPrefix.length > 0) {
             if (self.appendedPrefix.length > 0) {
                 if (![obj.path containsString:self.appendedPrefix]){
                 if (![obj.path containsString:self.appendedPrefix]){
                     DLog(@"[INFO] %@ doesnt have the prefix!", obj.path);
                     DLog(@"[INFO] %@ doesnt have the prefix!", obj.path);
-                    NSString *oldPath = [tmpPath stringByAppendingPathComponent:obj.path];
-                    NSString *newPath = [newRoot stringByAppendingPathComponent:obj.path];
-                    DLog(@"[INFO] moving %@ to %@", oldPath, newPath);
-                    [FM moveItemAtPath:oldPath toPath:newPath error:nil];
+                    [moveRoot addObject:obj.path];
                 }
                 }
             }
             }
             NSArray *pathComponents = [obj.path pathComponents];
             NSArray *pathComponents = [obj.path pathComponents];
@@ -577,18 +577,16 @@
                     NSString *newPath = [privateDir stringByAppendingPathComponent:rootPath];
                     NSString *newPath = [privateDir stringByAppendingPathComponent:rootPath];
                     DLog(@"\n [INFO] Moving %@ to %@...", badPath, newPath);
                     DLog(@"\n [INFO] Moving %@ to %@...", badPath, newPath);
                     [FM moveItemAtPath:badPath toPath:newPath error:nil];
                     [FM moveItemAtPath:badPath toPath:newPath error:nil];
-                    
-                    
                 }
                 }
             }
             }
-            
-            
         }
         }
-        
-        
     }];
     }];
-    
-    
+    [moveRoot enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        NSString *oldPath = [tmpPath stringByAppendingPathComponent:obj];
+        NSString *newPath = [newRoot stringByAppendingPathComponent:obj];
+        DLog(@"[INFO] moving %@ to %@", oldPath, newPath);
+        [FM moveItemAtPath:oldPath toPath:newPath error:nil];
+    }];
     NSString *depArchiveInfo = [NSString stringWithFormat:@"/usr/local/bin/dpkg -b %@", self.packageName];
     NSString *depArchiveInfo = [NSString stringWithFormat:@"/usr/local/bin/dpkg -b %@", self.packageName];
     
     
     if (fakeRoot) {
     if (fakeRoot) {

+ 2 - 1
bootstrapTool/Classes/NSString+Additions.h

@@ -4,5 +4,6 @@
 
 
 - (void)writeToFileWithoutAttributes:(NSString *)theFile;
 - (void)writeToFileWithoutAttributes:(NSString *)theFile;
 - (NSString *)nextVersionNumber;
 - (NSString *)nextVersionNumber;
-
+- (NSString *)trimmedString;
+- (NSArray *)properPathComponents;
 @end
 @end

+ 10 - 0
bootstrapTool/Classes/NSString+Additions.m

@@ -4,6 +4,16 @@
 
 
 @implementation NSString (Additions)
 @implementation NSString (Additions)
 
 
+- (NSArray *)properPathComponents {
+    NSMutableArray *newSet = [[self componentsSeparatedByString:@"/"] mutableCopy];
+    [newSet removeObject:@""];
+    return [newSet copy];
+}
+
+- (NSString *)trimmedString {
+    return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+}
+
 - (NSString *)nextVersionNumber {
 - (NSString *)nextVersionNumber {
     
     
     NSArray *comp = [self componentsSeparatedByString:@"-"];
     NSArray *comp = [self componentsSeparatedByString:@"-"];

+ 13 - 3
bootstrapTool/main.m

@@ -19,7 +19,7 @@
 #import "HelperClass.h"
 #import "HelperClass.h"
 
 
 
 
-#define OPTION_FLAGS "o:i:ld:hcrbp:"
+#define OPTION_FLAGS "o:i:ld:hcrbp:s"
 
 
 
 
 char *progname;
 char *progname;
@@ -35,6 +35,7 @@ static struct option longopts[] = {
     { "repackage",                 no_argument,            NULL,   'r' },
     { "repackage",                 no_argument,            NULL,   'r' },
     { "bump",                      no_argument,            NULL,   'b' },
     { "bump",                      no_argument,            NULL,   'b' },
     { "prefix",                    required_argument,      NULL,   'p' },
     { "prefix",                    required_argument,      NULL,   'p' },
+    { "skip",                      no_argument,            NULL,   's' },
     { NULL,                        0,                      NULL,    0  }
     { NULL,                        0,                      NULL,    0  }
 };
 };
 
 
@@ -48,8 +49,9 @@ void cmd_help(void){
     printf("  -l, --list\t\t\tlist all the packages installed on this bootstrap\n");
     printf("  -l, --list\t\t\tlist all the packages installed on this bootstrap\n");
     printf("  -c, --clean\t\t\tclean a bad status file from duplicate entries\n");
     printf("  -c, --clean\t\t\tclean a bad status file from duplicate entries\n");
     printf("  -r, --repackage\t\trepackage to fix bad locations and to change architecture\n");
     printf("  -r, --repackage\t\trepackage to fix bad locations and to change architecture\n");
-    printf("  -b, --bump\t\trepackage and bump by one - number (ie 1.0-1 -> 1.0-2)\n");
-    printf("  -p, --prefix\t\tthe prefix to append to all packages when repackaging or bumping a version number\n");
+    printf("  -b, --bump\t\t\trepackage and bump by one - number (ie 1.0-1 -> 1.0-2)\n");
+    printf("  -s, --skip\t\t\tskip code signature checks when bumping and repackaging\n");
+    printf("  -p, --prefix\t\t\tthe prefix to append to all packages when repackaging or bumping a version number\n");
     printf("\n");
     printf("\n");
 }
 }
 
 
@@ -68,6 +70,7 @@ int main(int argc, char **argv) {
         NSString *prefix = nil;
         NSString *prefix = nil;
         BOOL listPackage = FALSE;
         BOOL listPackage = FALSE;
         BOOL repackage = FALSE;
         BOOL repackage = FALSE;
+        BOOL skip = FALSE;
         BOOL bump = FALSE;
         BOOL bump = FALSE;
         BOOL clean = FALSE;
         BOOL clean = FALSE;
         while ((flag = getopt_long(argc, argv, OPTION_FLAGS, longopts, NULL)) != -1) {
         while ((flag = getopt_long(argc, argv, OPTION_FLAGS, longopts, NULL)) != -1) {
@@ -110,6 +113,11 @@ int main(int argc, char **argv) {
                 case 'p':
                 case 'p':
                     prefix = [NSString stringWithUTF8String:optarg];
                     prefix = [NSString stringWithUTF8String:optarg];
                     break;
                     break;
+                    
+                case 's':
+                    skip = TRUE;
+                    break;
+                    
                 default:
                 default:
                     cmd_help();
                     cmd_help();
                     return -1;
                     return -1;
@@ -131,6 +139,7 @@ int main(int argc, char **argv) {
             DLog(@"\n [INFO] Bumping version number for file: %@...\n", debFile);
             DLog(@"\n [INFO] Bumping version number for file: %@...\n", debFile);
             InputPackage *output = [HelperClass packageForDeb:debFile];
             InputPackage *output = [HelperClass packageForDeb:debFile];
             output.appendedPrefix = prefix;
             output.appendedPrefix = prefix;
+            output.skipSignatureChecks = skip;
             [output bumpVersionInCurrentDirectory];
             [output bumpVersionInCurrentDirectory];
             return 0;
             return 0;
         }
         }
@@ -140,6 +149,7 @@ int main(int argc, char **argv) {
             DLog(@"\n [INFO] Repackaging file: %@...\n", debFile);
             DLog(@"\n [INFO] Repackaging file: %@...\n", debFile);
             InputPackage *output = [HelperClass packageForDeb:debFile];
             InputPackage *output = [HelperClass packageForDeb:debFile];
             output.appendedPrefix = prefix;
             output.appendedPrefix = prefix;
+            output.skipSignatureChecks = skip;
             [output repackageInCurrentDirectoryWithArch:@"appletvos-arm64"];
             [output repackageInCurrentDirectoryWithArch:@"appletvos-arm64"];
             return 0;
             return 0;
         }
         }