Browse Source

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 1 year ago
parent
commit
8e6d77f275

+ 1 - 0
bootstrapTool/Classes/InputPackage.h

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

+ 19 - 21
bootstrapTool/Classes/InputPackage.m

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

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

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

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

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

+ 13 - 3
bootstrapTool/main.m

@@ -19,7 +19,7 @@
 #import "HelperClass.h"
 
 
-#define OPTION_FLAGS "o:i:ld:hcrbp:"
+#define OPTION_FLAGS "o:i:ld:hcrbp:s"
 
 
 char *progname;
@@ -35,6 +35,7 @@ static struct option longopts[] = {
     { "repackage",                 no_argument,            NULL,   'r' },
     { "bump",                      no_argument,            NULL,   'b' },
     { "prefix",                    required_argument,      NULL,   'p' },
+    { "skip",                      no_argument,            NULL,   's' },
     { 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("  -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("  -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");
 }
 
@@ -68,6 +70,7 @@ int main(int argc, char **argv) {
         NSString *prefix = nil;
         BOOL listPackage = FALSE;
         BOOL repackage = FALSE;
+        BOOL skip = FALSE;
         BOOL bump = FALSE;
         BOOL clean = FALSE;
         while ((flag = getopt_long(argc, argv, OPTION_FLAGS, longopts, NULL)) != -1) {
@@ -110,6 +113,11 @@ int main(int argc, char **argv) {
                 case 'p':
                     prefix = [NSString stringWithUTF8String:optarg];
                     break;
+                    
+                case 's':
+                    skip = TRUE;
+                    break;
+                    
                 default:
                     cmd_help();
                     return -1;
@@ -131,6 +139,7 @@ int main(int argc, char **argv) {
             DLog(@"\n [INFO] Bumping version number for file: %@...\n", debFile);
             InputPackage *output = [HelperClass packageForDeb:debFile];
             output.appendedPrefix = prefix;
+            output.skipSignatureChecks = skip;
             [output bumpVersionInCurrentDirectory];
             return 0;
         }
@@ -140,6 +149,7 @@ int main(int argc, char **argv) {
             DLog(@"\n [INFO] Repackaging file: %@...\n", debFile);
             InputPackage *output = [HelperClass packageForDeb:debFile];
             output.appendedPrefix = prefix;
+            output.skipSignatureChecks = skip;
             [output repackageInCurrentDirectoryWithArch:@"appletvos-arm64"];
             return 0;
         }