Browse Source

create list files, handle all different rootless iterations, force yes installs and more

Kevin Bradley 9 months ago
parent
commit
39f82cb6c0

+ 1 - 0
bootstrapTool/Classes/InputPackage.h

@@ -14,6 +14,7 @@
 @property (nonatomic, strong) NSString *path;
 @property (nonatomic, strong) NSString *appendedPrefix;
 @property (readwrite, assign) BOOL skipSignatureChecks;
+@property (readwrite, assign) BOOL forceOverwrite;
 @property (nonatomic, strong) NSString *validLDIDPath;
 
 

+ 51 - 9
bootstrapTool/Classes/InputPackage.m

@@ -50,6 +50,31 @@
     
 }
 
+- (BOOL)validateFileList:(NSArray *)fileList {
+    __block BOOL retv = true;
+    [fileList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        if ([obj length] > 1) {
+            NSString *sub = [obj substringToIndex:2];
+            if ([sub isEqualToString:@"./"]) {
+                *stop = true;
+                retv = false;
+            }
+        }
+    }];
+    return retv;
+}
+
+- (NSArray *)getFileListing {
+    NSString *listProcess = [NSString stringWithFormat:@"/usr/local/bin/dpkg-deb -c %@ | awk '{ print $6 }'" , self.path];
+    NSArray *fileList = [HelperClass returnForProcess:listProcess];
+    BOOL validated = [self validateFileList:fileList];
+    if (!validated) {
+        fileList = [HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg-deb -c %@ | awk '{ print $6 }' | cut -c 2-" , self.path]];
+    }
+    return fileList;
+}
+
+
 - (int)installToBootstrapPath:(NSString *)bootstrapPath {
     
     DLog(@"\nFound package: '%@' at version: '%@'...\n", self.packageName, self.version );
@@ -96,12 +121,12 @@
         {
             
             NSString *error = [NSString stringWithFormat:@" [WARNING] %@ will overwrite the following files: \n\n\t%@\n\n", self.path.lastPathComponent, [safePackage.overwriteFiles componentsJoinedByString:@"\n\t"]];
-            
-            if(![HelperClass shouldContinueWithError:error]){
-                
-                return -1;
+            if (!self.forceOverwrite) {
+                if(![HelperClass shouldContinueWithError:error]){
+                    
+                    return -1;
+                }
             }
-            
         } else if (safePackage.returnStatus == 2) //bail!!"
         {
             return 2;
@@ -116,9 +141,26 @@
     DLog(@"\nExtracting deb for processing...\n");
     [HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -x %@ %@", self.path, tmpPath]];
     
-    //NSString *bootstrapInfoPath = [bootstrapPath stringByAppendingPathComponent:@"Library/dpkg/info"];
+    NSArray *fileList = [self getFileListing];
     
-    //NSString *listFile = [bootstrapInfoPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.list", self.packageName]];
+    if (fileList.count > 0) {
+        
+        NSString *baseFile = [NSString stringWithFormat:@"%@.list", self.packageName];
+        
+        NSString *listFile = [bootstrapPath.relativeInfoFolderPath stringByAppendingPathComponent:baseFile];
+        NSString *listOutput = [fileList componentsJoinedByString:@"\n"];
+        DLog(@"\nCreating list file '%@'...\n", listFile);
+        DLog(@"list: %@", listOutput);
+        [[listOutput stringByAppendingString:@"\n"] writeToFile:listFile atomically:TRUE encoding:NSUTF8StringEncoding error:nil];
+    }
+    
+    /*
+     (dpkg-deb -c "$DEB" | awk "{ print $6}" | grep "\./" -c)
+     
+    NSString *process = [NSString stringWithFormat:@"/usr/local/bin/dpkg-deb -c %@ | awk '{ print $6 }'" , self.path];
+    NSArray *psc = [HelperClass returnForProcess:process];
+    DLog(@"psc: %@", psc);
+    */
     //NSString *md5s = [bootstrapInfoPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.md5sums", self.packageName]];
     
     //DLog(@"\nCreating list file '%@'...\n", listFile);
@@ -165,7 +207,7 @@
             }
             DLog(@"Copying file... %@\n\n", fullPath);
             NSString *fileName = [NSString stringWithFormat:@"%@.%@", self.packageName, obj];
-            NSString *newPath = [bootstrapPath stringByAppendingPathComponent:@"Library/dpkg/info"];
+            NSString *newPath = [bootstrapPath relativeInfoFolderPath];
             newPath = [newPath stringByAppendingPathComponent:fileName];
             //DLog(@"newPath: %@", newPath);
             [FM copyItemAtPath:fullPath toPath:newPath error:nil];
@@ -176,7 +218,7 @@
             
             [controlFile replaceOccurrencesOfString:@"iphoneos-arm" withString:@"appletvos-arm64" options:NSLiteralSearch range:NSMakeRange(0, [controlFile length])];
             
-            [controlFile appendString:@"Status: install ok installed"];
+            [controlFile appendString:@"Status: install ok installed\n"];
             
             //DLog(@"control file: -%@-\n", controlFile);
             

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

@@ -14,4 +14,5 @@
 - (NSArray *)properPathComponents;
 - (NSArray *)spaceDelimitedArray;
 - (NSString *)relativeStatusFilePath;
+- (NSString *)relativeInfoFolderPath;
 @end

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

@@ -19,6 +19,18 @@
 
 @implementation NSString (Additions)
 
+- (NSString *)relativeInfoFolderPath {
+    NSString *firstTry = [[self stringByExpandingTildeInPath] stringByAppendingPathComponent:@"Library/dpkg/info"];
+    if (![FM fileExistsAtPath:firstTry]){
+        firstTry = [[self stringByExpandingTildeInPath] stringByAppendingPathComponent:@"var/lib/dpkg/info"];
+        if (![FM fileExistsAtPath:firstTry]) {
+            DLog(@"no relative status file found!");
+            return nil;
+        }
+    }
+    return firstTry;
+}
+
 - (NSString *)relativeStatusFilePath {
     NSString *firstTry = [[self stringByExpandingTildeInPath] stringByAppendingPathComponent:@"Library/dpkg/status"];
     if (![FM fileExistsAtPath:firstTry]){

+ 19 - 4
bootstrapTool/main.m

@@ -16,7 +16,7 @@
 #import <sys/utsname.h>
 #import "HelperClass.h"
 
-#define OPTION_FLAGS "o:i:ld:hcrbp:su:"
+#define OPTION_FLAGS "o:i:ld:hcrbp:su:y"
 
 char *progname;
 char *path;
@@ -33,6 +33,7 @@ static struct option longopts[] = {
     { "prefix",                    required_argument,      NULL,   'p' },
     { "skip",                      no_argument,            NULL,   's' },
     { "unique",                    required_argument,      NULL,   'u' },
+    { "yes",                       no_argument,            NULL,   'y' },
     { NULL,                        0,                      NULL,    0  }
 };
 
@@ -48,7 +49,9 @@ void cmd_help(void){
     printf("  -r, --repackage\t\trepackage to fix bad locations and to change architecture\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("  -y, --yes\t\t\talways answer yes to prompts to overwrite files\n");
     printf("  -p, --prefix\t\t\tthe prefix to append to all packages when repackaging or bumping a version number\n");
+    
     printf("\n");
 }
 
@@ -70,6 +73,15 @@ int main(int argc, char **argv) {
         BOOL skip = FALSE;
         BOOL bump = FALSE;
         BOOL clean = FALSE;
+        BOOL forceYes = FALSE;
+        /*
+        NSString *searchPathString = @"/Users/bradleyk/.rbenv/shims:/Users/bradleyk/Library/Python/3.9/bin:/Users/bradleyk/Library/Python/3.8/bin:/usr/local/lib/ruby/gems/3.0.0/bin:/usr/local/lib/ruby/gems/bin:/usr/local/opt/ruby/bin:/opt/local/bin:/opt/local/sbin:/Users/bradleyk/local/bin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/Users/bradleyk/Projects/goprojects/bin:/Users/bradleyk/Projects/theos/bin:/usr/local/bin/:/usr/local/bin:/bin/:/sbin/:/usr/sbin/";
+        NSString *target = @"dpkg-deb";
+        NSString *gotIm = [target pathForBin:target searchPaths:searchPathString];
+        DLog(@"gotIm: %@", gotIm);
+        return 0;
+         */
+        NSString *up = nil;
         while ((flag = getopt_long(argc, argv, OPTION_FLAGS, longopts, NULL)) != -1) {
             switch(flag) {
                 case 'o':
@@ -79,6 +91,9 @@ int main(int argc, char **argv) {
                 case 'i':
                     debFile = [NSString stringWithUTF8String:optarg];
                     break;
+                case 'y':
+                    forceYes = TRUE;
+                    break;
                     
                 case 'l':
                     listPackage = TRUE;
@@ -122,7 +137,7 @@ int main(int argc, char **argv) {
             argc -= optind;
             argv += optind;
             bootstrapPath = [NSString stringWithUTF8String:argv[0]];
-            DLog(@"bootstrap path: %@?", bootstrapPath);
+            //yDLog(@"bootstrap path: %@?", bootstrapPath);
             //return 0;
         }
         
@@ -210,7 +225,7 @@ int main(int argc, char **argv) {
             StatusPackageModel *model = [[installedPackages filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"package == %@", deletePackage]] lastObject];
             if (model) {
                 NSString *listName = [NSString stringWithFormat:@"%@.list", deletePackage];
-                NSString *infoPath = [bootstrapPath stringByAppendingPathComponent:@"Library/dpkg/info"];
+                NSString *infoPath = [bootstrapPath relativeInfoFolderPath];
                 NSString *listFile = [infoPath stringByAppendingPathComponent:listName];
                 NSArray *listFiles = [FM contentsOfDirectoryAtPath:infoPath error:nil];
                 NSPredicate *blockPred = [NSPredicate predicateWithBlock:^BOOL(id  _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
@@ -254,7 +269,6 @@ int main(int argc, char **argv) {
                     [FM removeItemAtPath:obj error:nil];
                 }];
                 
-                //TODO: delete the files here!
                 NSString *statusFile = [bootstrapPath relativeStatusFilePath];
                 [FM copyItemAtPath:statusFile toPath:[statusFile stringByAppendingPathExtension:@"bak"] error:nil];
                 __block NSMutableString *newStatusFile = [NSMutableString new];
@@ -306,6 +320,7 @@ int main(int argc, char **argv) {
         if (debFile && bootstrapPath) {
             DLog(@"\nProcessing file: %@\n", debFile);
             InputPackage *output = [HelperClass packageForDeb:debFile];
+            output.forceOverwrite = forceYes;
             return [output installToBootstrapPath:bootstrapPath];
             
         } else if (debFile) {