Browse Source

creating packages from bootstrap folder fully working now

Kevin Bradley 7 months ago
parent
commit
43c6ecb7ee

+ 2 - 1
bootstrapTool/Classes/HelperClass.h

@@ -15,9 +15,10 @@
 + (int)runCommand:(NSString *)call environment:(NSDictionary *)env currentPath:(NSString *)currentPath verbose:(BOOL)verbose;
 + (NSString *)validLDIDPath;
 + (int)bumpPackageAtPath:(NSString *)debFile withPrefix:(NSString *)prefix sigChecks:(BOOL)skip;
-+ (int)repackagePackageAtPath:(NSString *)debFile withPrefix:(NSString *)prefix sigChecks:(BOOL)skip arch:(NSString *)arch;
++ (int)repackagePackageAtPath:(NSString *)debFile withPrefix:(NSString *)prefix sigChecks:(BOOL)skip arch:(NSString *)arch excludeFile:(NSString *)excludeFile;
 + (int)cleanBootstrapAtPath:(NSString *)bootstrapPath;
 + (int)deletePackage:(NSString *)deletePackage inBootstrap:(NSString *)bootstrapPath;
 + (int)createNewBootstrap:(NSString *)bootstrapPath withPackages:(NSString *)packagesFolder;
 + (NSInteger)getNumberFromPrompt:(NSString *)prompt;
++ (InputPackageFile *)packageFileFromLine:(NSString *)inputLine;
 @end

+ 3 - 2
bootstrapTool/Classes/HelperClass.m

@@ -171,11 +171,12 @@
     
 }
 
-+ (int)repackagePackageAtPath:(NSString *)debFile withPrefix:(NSString *)prefix sigChecks:(BOOL)skip arch:(NSString *)arch {
++ (int)repackagePackageAtPath:(NSString *)debFile withPrefix:(NSString *)prefix sigChecks:(BOOL)skip arch:(NSString *)arch excludeFile:(NSString *)excludeFile {
     DLog(@"\n [INFO] Repackaging file: %@...\n", debFile);
     InputPackage *output = [HelperClass packageForDeb:debFile];
     output.appendedPrefix = prefix;
     output.skipSignatureChecks = skip;
+    output.excludeFile = excludeFile;
     if (!arch) {
         arch = @"appletvos-arm64";
     }
@@ -358,7 +359,7 @@
     NSArray *args = [call componentsSeparatedByString:@" "];
     NSString *taskBinary = args[0];
     NSArray *taskArguments = [args subarrayWithRange:NSMakeRange(1, args.count-1)];
-    //DDLogInfo(@"%@ %@", taskBinary, [taskArguments componentsJoinedByString:@" "]);
+    DLog(@"%@ %@", taskBinary, [taskArguments componentsJoinedByString:@" "]);
     NSTask *task = [[NSTask alloc] init];
     NSPipe *pipe = [[NSPipe alloc] init];
     NSFileHandle *handle = [pipe fileHandleForReading];

+ 3 - 0
bootstrapTool/Classes/InputPackage.h

@@ -17,6 +17,8 @@
 @property (readwrite, assign) BOOL forceOverwrite;
 @property (nonatomic, strong) NSString *validLDIDPath;
 @property (nonatomic, strong) NSString *arch; //if repackaging.
+@property (nonatomic, strong) NSString *excludeFile;
+@property (nonatomic, strong) NSArray *excludedFiles; //created from excluded file during package installation
 
 
 - (void)bumpVersionInCurrentDirectory;
@@ -25,4 +27,5 @@
 - (ErrorReturn *)errorReturnForBootstrap:(NSString *)bootstrapPath;
 - (NSString *)listfile;
 - (NSArray *)rootPaths;
++ (InputPackage *)packageForDeb:(NSString *)debFile excludes:(NSString *)excludesFile;
 @end

+ 98 - 4
bootstrapTool/Classes/InputPackage.m

@@ -6,6 +6,38 @@
 
 @implementation InputPackage
 
++ (InputPackage *)packageForDeb:(NSString *)debFile {
+    return [self packageForDeb:debFile excludes:nil];
+}
+
++ (InputPackage *)packageForDeb:(NSString *)debFile excludes:(NSString *)excludesFile {
+    
+    NSString *dpkg = [@"dpkg" runPathForSearchPath];
+    NSString *packageName = [HelperClass singleLineReturnForProcess:@"%@ -f %@ Package",dpkg, debFile];
+    NSString *packageVersion = [HelperClass singleLineReturnForProcess:@"%@ -f %@ Version", dpkg, debFile];
+    NSArray <InputPackageFile *> *fileList = [HelperClass returnForProcess:[NSString stringWithFormat:@"%@ -c %@", dpkg, debFile]];
+    
+    __block NSMutableArray *finalArray = [NSMutableArray new];
+    
+    [fileList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        InputPackageFile *file = [HelperClass packageFileFromLine:obj];
+        if (file) {
+            //DLog(@"%@", file);
+            [finalArray addObject:file];
+        }
+    }];
+    
+    InputPackage *pkg = [InputPackage new];
+    pkg.excludeFile = excludesFile;
+    pkg.files = finalArray;
+    pkg.path = debFile;
+    pkg.packageName = packageName;
+    pkg.version = packageVersion;
+    pkg.validLDIDPath = [HelperClass validLDIDPath];
+    return pkg;
+    
+}
+
 - (NSString*) description {
     
     NSString *orig = [super description];
@@ -56,7 +88,6 @@
     [fileList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
         if ([obj length] > 1) {
             NSString *sub = [obj substringToIndex:2];
-            DLog(@"sub: %@", sub);
             if ([sub isEqualToString:@"./"]) {
                 invalidCount++;
                 if (invalidCount > 1){
@@ -82,10 +113,29 @@
         [_mutableList removeObject:@"/"];
         fileList = [_mutableList copy];
     }
+    NSArray *excludeArray = [self.excludeFile excludeArrayFromFile];
+    if (excludeArray) {
+        __block NSMutableArray *filesToRemove = [NSMutableArray new];
+        [excludeArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+            if ([obj length] > 0){
+                NSArray *items = [fileList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF LIKE[c] %@", obj]];
+                if (items.count > 0) {
+                    //DLog(@"found items to remove: %@", items);
+                    [filesToRemove addObjectsFromArray:items];
+                }
+            }
+        }];
+        //DLog(@"\nShould remove the following: %@", filesToRemove);
+        self.excludedFiles = filesToRemove;
+        NSMutableArray *_mutableList = [fileList mutableCopy];
+        [_mutableList removeObjectsInArray:filesToRemove];
+        fileList = [_mutableList copy];
+    }
     return fileList;
 }
 
 
+
 - (int)installToBootstrapPath:(NSString *)bootstrapPath {
     
     DLog(@"\nFound package: '%@' at version: '%@'...\n", self.packageName, self.version );
@@ -161,7 +211,7 @@
         NSString *listFile = [bootstrapPath.relativeInfoFolderPath stringByAppendingPathComponent:baseFile];
         NSString *listOutput = [fileList componentsJoinedByString:@"\n"];
         DLog(@"\nCreating list file '%@'...\n", listFile);
-        DLog(@"list: %@", listOutput);
+        //DLog(@"list: %@", listOutput);
         [[listOutput stringByAppendingString:@"\n"] writeToFile:listFile atomically:TRUE encoding:NSUTF8StringEncoding error:nil];
     }
     
@@ -265,8 +315,25 @@
         DLog(@"\n [WARNING] We found a postinst file, will not run this due to potential unexpected consequences in your run environment! Displaying contents so you can determine if any additional steps are necessary. Contents will be delimited by a line -----\n");
         DLog(@"\n%@ Contents:\n\n---------------------\n\n%@\n\n---------------------\n\n", postInstFile, [NSString stringWithContentsOfFile:postInstFile encoding:NSASCIIStringEncoding error:nil]);
     }
+    NSArray *excludeArray = self.excludedFiles;//[self.excludeFile excludeArrayFromFile];
+    if (excludeArray) {
+        DLog(@"\nRemoving excluded files...\n\n");
+        [excludeArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+            if ([obj length] > 0){
+                NSString *filePath = [bootstrapPath stringByAppendingPathComponent:obj];
+                if ([FM fileExistsAtPath:filePath]) {
+                    NSString *commandToRun = [NSString stringWithFormat:@"/bin/rm -r %@", filePath];
+                    DLog(@"%@", commandToRun);
+                    [HelperClass singleLineReturnForProcess:commandToRun];
+                } else {
+                    DLog(@"file doesn't exist at %@", filePath);
+                }
+                //DLog(@"returned: %@", deets);
+            }
+        }];
+    }
     [FM removeItemAtPath:tmpPath error:nil];
-    DLog(@"Done!\n\n");
+    DLog(@"\nDone!\n\n");
     return 0;
 }
 
@@ -396,6 +463,17 @@
     [FM createDirectoryAtPath:debian withIntermediateDirectories:TRUE attributes:nil error:nil];
     DLog(@"\nExtracting DEBIAN files for processing...\n");
     [HelperClass returnForProcess:[NSString stringWithFormat:@"%@ -e %@ %@",dpkg, self.path, debian]];
+    NSArray *excludeArray = [self.excludeFile excludeArrayFromFile];
+    if (excludeArray) {
+        [excludeArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+            if ([obj length] > 0){
+                NSString *commandToRun = [NSString stringWithFormat:@"/bin/rm %@/%@", tmpPath, obj];
+                //DLog(@"%@", commandToRun);
+                NSString *deets = [HelperClass singleLineReturnForProcess:commandToRun];
+                DLog(@"returned: %@", deets);
+            }
+        }];
+    }
     NSString *controlPath = [debian stringByAppendingPathComponent:@"control"];
     NSMutableString *controlFile = [[NSMutableString alloc] initWithContentsOfFile:controlPath encoding:NSASCIIStringEncoding error:nil];
     //@"appletvos-arm64"
@@ -486,6 +564,10 @@
     DLog(@"\nDone!\n\n");
 }
 
+- (NSString *)excludeContents {
+    return @"path-exclude=*/share/info/*\npath-exclude=*/share/doc/*\npath-exclude=*/share/man/*";
+}
+
 - (void)repackageInCurrentDirectoryWithArch:(NSString *)newArch {
     
     NSString *fakeRoot = [HelperClass singleLineReturnForProcess:@"/usr/bin/which fakeroot"];
@@ -508,7 +590,19 @@
     [FM createDirectoryAtPath:debian withIntermediateDirectories:TRUE attributes:nil error:nil];
     DLog(@"\nExtracting DEBIAN files for processing...\n");
     [HelperClass returnForProcess:[NSString stringWithFormat:@"%@ -e %@ %@", dpkg, self.path, debian]];
-    
+    NSArray *excludeArray = [self.excludeFile excludeArrayFromFile];
+    if (excludeArray) {
+        DLog(@"excludeARray: %@", excludeArray);
+        [excludeArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+            if ([obj length] > 0){
+                NSString *commandToRun = [NSString stringWithFormat:@"/bin/rm %@/%@", tmpPath, obj];
+                //DLog(@"%@", commandToRun);
+                NSString *deets = [HelperClass singleLineReturnForProcess:commandToRun];
+                DLog(@"returned: %@", deets);
+            }
+            //[HelperClass returnForProcess:[NSString stringWithFormat:@"/bin/rm %@/%@", tmpPath, obj]];
+        }];
+    }
     //clean up any calls to uicache
     NSString *postinst = [debian stringByAppendingPathComponent:@"postinst"];
     //DLog(@"post inst: %@", postinst);

+ 1 - 1
bootstrapTool/Classes/NSString+Additions.m

@@ -18,7 +18,7 @@
 @end
 
 @implementation NSString (Additions)
-
+//@"path-exclude=*/share/info/*\npath-exclude=*/share/doc/*\npath-exclude=*/share/man/*"
 - (NSArray *)excludeArrayFromFile {
     NSString *fileContents = [NSString stringWithContentsOfFile:self encoding:NSUTF8StringEncoding error:nil];
     return [fileContents componentsSeparatedByString:@"\n"];

+ 26 - 0
bootstrapTool/Classes/StatusPackageModel.m

@@ -1,4 +1,6 @@
 
+#import "HelperClass.h"
+
 @implementation StatusPackageModel
 
 - (NSArray <InputPackageFile *>*)files {
@@ -64,6 +66,30 @@
                 [FM copyItemAtPath:fromFile toPath:destinationPath error:nil];
             }
         }];
+        NSString *pwd = [[HelperClass returnForProcess:@"/bin/pwd"] componentsJoinedByString:@"\n"];
+        DLog(@"pwd: %@", pwd);
+        //file_5.39-1_appletvos-arm64.deb
+        NSString *fileName = [NSString stringWithFormat:@"%@_%@_%@.deb", self.package, self.version, self.architecture];
+        NSString *newFile = [pwd stringByAppendingPathComponent:fileName];
+        if ([FM fileExistsAtPath:newFile]){
+            DLog(@"this file already exists: %@", newFile);
+        } else {
+            //NSString *which = [@"which" runPathForSearchPath];
+            //NSString *process = [NSString stringWithFormat:@"%@ dm.pl", which];
+            //NSString *dpkgDeb = [HelperClass singleLineReturnForProcess:process];
+            //if (!dpkgDeb){
+            NSString *dpkgDeb = [@"dpkg-deb" runPathForSearchPath];
+            //}
+            DLog(@"dpkg-deb: %@", dpkgDeb);
+            NSString *chown = [@"chown" runPathForSearchPath];
+            NSString *chownCom = [NSString stringWithFormat:@"%@ -R root:wheel %@", chown, tmpFolder];
+            DLog(@"%@", chownCom);
+            [HelperClass singleLineReturnForProcess:chownCom];
+            NSString *command = [NSString stringWithFormat:@"%@ -b %@ %@", dpkgDeb, tmpFolder, newFile];
+            DLog(@"command: %@", command);
+            NSString *output = [HelperClass singleLineReturnForProcess:command];
+            DLog(@"output: %@", output);
+        }
     }
 }
 

+ 14 - 1
bootstrapTool/main.m

@@ -190,12 +190,20 @@ int main(int argc, char **argv) {
         }
         
         if (bump == TRUE && debFile) {
+            if (![FM fileExistsAtPath:debFile]){
+                DLog(@"%@ doesnt exist!, exiting...", debFile);
+                return -1;
+            }
             DLog(@"skip signature checks: %d", skip);
             return [HelperClass bumpPackageAtPath:debFile withPrefix:prefix sigChecks:skip];
         }
         
         if (repackage == TRUE && debFile) {
-            return [HelperClass repackagePackageAtPath:debFile withPrefix:prefix sigChecks:skip arch:arch];
+            if (![FM fileExistsAtPath:debFile]){
+                DLog(@"%@ doesnt exist!, exiting...", debFile);
+                return -1;
+            }
+            return [HelperClass repackagePackageAtPath:debFile withPrefix:prefix sigChecks:skip arch:arch excludeFile:excludeFile];
         }
         
         //DLog(@"folder: %@ project: %@", folder, project);
@@ -265,9 +273,14 @@ int main(int argc, char **argv) {
         }
         
         if (debFile && bootstrapPath) {
+            if (![FM fileExistsAtPath:debFile]){
+                DLog(@"%@ doesnt exist!, exiting...", debFile);
+                return -1;
+            }
             DLog(@"\nProcessing file: %@\n", debFile);
             InputPackage *output = [HelperClass packageForDeb:debFile];
             output.forceOverwrite = forceYes;
+            output.excludeFile = excludeFile;
             return [output installToBootstrapPath:bootstrapPath];
             
         } else if (debFile) {