Browse Source

repackages bad debs now

Kevin Bradley 5 years ago
parent
commit
3adb8afd5e

+ 56 - 0
bootstrapTool.xcodeproj/project.pbxproj

@@ -8,6 +8,13 @@
 
 /* Begin PBXBuildFile section */
 		3249302B20E4E29700E99767 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3249302A20E4E29700E99767 /* main.m */; };
+		325A24B920E83F09001D1BAD /* HelperClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 325A24B020E83EF8001D1BAD /* HelperClass.m */; };
+		325A24BC20E83F46001D1BAD /* ErrorReturn.m in Sources */ = {isa = PBXBuildFile; fileRef = 325A24BB20E83F46001D1BAD /* ErrorReturn.m */; };
+		325A24BD20E83F7E001D1BAD /* InputPackage.m in Sources */ = {isa = PBXBuildFile; fileRef = 325A24B620E83EF8001D1BAD /* InputPackage.m */; };
+		325A24BE20E83F8C001D1BAD /* StatusPackageModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 325A24AE20E83EF8001D1BAD /* StatusPackageModel.m */; };
+		325A24BF20E83F95001D1BAD /* NSObject+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 325A24B220E83EF8001D1BAD /* NSObject+Additions.m */; };
+		325A24C020E83F97001D1BAD /* NSString+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 325A24B420E83EF8001D1BAD /* NSString+Additions.m */; };
+		325A24C120E83FCA001D1BAD /* InputPackageFIle.m in Sources */ = {isa = PBXBuildFile; fileRef = 325A24B820E83EF8001D1BAD /* InputPackageFIle.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXCopyFilesBuildPhase section */
@@ -25,6 +32,21 @@
 /* Begin PBXFileReference section */
 		3249302720E4E29700E99767 /* bootstrapTool */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = bootstrapTool; sourceTree = BUILT_PRODUCTS_DIR; };
 		3249302A20E4E29700E99767 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+		325A24AD20E83EF8001D1BAD /* StatusPackageModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StatusPackageModel.h; sourceTree = "<group>"; };
+		325A24AE20E83EF8001D1BAD /* StatusPackageModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = StatusPackageModel.m; sourceTree = "<group>"; };
+		325A24AF20E83EF8001D1BAD /* HelperClass.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HelperClass.h; sourceTree = "<group>"; };
+		325A24B020E83EF8001D1BAD /* HelperClass.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HelperClass.m; sourceTree = "<group>"; };
+		325A24B120E83EF8001D1BAD /* NSObject+Additions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSObject+Additions.h"; sourceTree = "<group>"; };
+		325A24B220E83EF8001D1BAD /* NSObject+Additions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSObject+Additions.m"; sourceTree = "<group>"; };
+		325A24B320E83EF8001D1BAD /* NSString+Additions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+Additions.h"; sourceTree = "<group>"; };
+		325A24B420E83EF8001D1BAD /* NSString+Additions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+Additions.m"; sourceTree = "<group>"; };
+		325A24B520E83EF8001D1BAD /* InputPackage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InputPackage.h; sourceTree = "<group>"; };
+		325A24B620E83EF8001D1BAD /* InputPackage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InputPackage.m; sourceTree = "<group>"; };
+		325A24B720E83EF8001D1BAD /* InputPackageFIle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InputPackageFIle.h; sourceTree = "<group>"; };
+		325A24B820E83EF8001D1BAD /* InputPackageFIle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InputPackageFIle.m; sourceTree = "<group>"; };
+		325A24BA20E83F46001D1BAD /* ErrorReturn.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ErrorReturn.h; sourceTree = "<group>"; };
+		325A24BB20E83F46001D1BAD /* ErrorReturn.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ErrorReturn.m; sourceTree = "<group>"; };
+		325A24C220E84033001D1BAD /* Defines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Defines.h; path = Classes/Defines.h; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -57,11 +79,34 @@
 		3249302920E4E29700E99767 /* bootstrapTool */ = {
 			isa = PBXGroup;
 			children = (
+				325A24C220E84033001D1BAD /* Defines.h */,
+				325A24AC20E83EF8001D1BAD /* Classes */,
 				3249302A20E4E29700E99767 /* main.m */,
 			);
 			path = bootstrapTool;
 			sourceTree = "<group>";
 		};
+		325A24AC20E83EF8001D1BAD /* Classes */ = {
+			isa = PBXGroup;
+			children = (
+				325A24BA20E83F46001D1BAD /* ErrorReturn.h */,
+				325A24BB20E83F46001D1BAD /* ErrorReturn.m */,
+				325A24AD20E83EF8001D1BAD /* StatusPackageModel.h */,
+				325A24AE20E83EF8001D1BAD /* StatusPackageModel.m */,
+				325A24AF20E83EF8001D1BAD /* HelperClass.h */,
+				325A24B020E83EF8001D1BAD /* HelperClass.m */,
+				325A24B120E83EF8001D1BAD /* NSObject+Additions.h */,
+				325A24B220E83EF8001D1BAD /* NSObject+Additions.m */,
+				325A24B320E83EF8001D1BAD /* NSString+Additions.h */,
+				325A24B420E83EF8001D1BAD /* NSString+Additions.m */,
+				325A24B520E83EF8001D1BAD /* InputPackage.h */,
+				325A24B620E83EF8001D1BAD /* InputPackage.m */,
+				325A24B720E83EF8001D1BAD /* InputPackageFIle.h */,
+				325A24B820E83EF8001D1BAD /* InputPackageFIle.m */,
+			);
+			path = Classes;
+			sourceTree = "<group>";
+		};
 /* End PBXGroup section */
 
 /* Begin PBXNativeTarget section */
@@ -119,7 +164,14 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				325A24C020E83F97001D1BAD /* NSString+Additions.m in Sources */,
+				325A24BD20E83F7E001D1BAD /* InputPackage.m in Sources */,
+				325A24BC20E83F46001D1BAD /* ErrorReturn.m in Sources */,
+				325A24B920E83F09001D1BAD /* HelperClass.m in Sources */,
+				325A24C120E83FCA001D1BAD /* InputPackageFIle.m in Sources */,
+				325A24BF20E83F95001D1BAD /* NSObject+Additions.m in Sources */,
 				3249302B20E4E29700E99767 /* main.m in Sources */,
+				325A24BE20E83F8C001D1BAD /* StatusPackageModel.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -234,6 +286,8 @@
 			buildSettings = {
 				CODE_SIGN_STYLE = Automatic;
 				DEVELOPMENT_TEAM = 9EUFEA5U7G;
+				GCC_PRECOMPILE_PREFIX_HEADER = YES;
+				GCC_PREFIX_HEADER = "$(SRCROOT)/bootstrapTool/Classes/Defines.h";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Debug;
@@ -243,6 +297,8 @@
 			buildSettings = {
 				CODE_SIGN_STYLE = Automatic;
 				DEVELOPMENT_TEAM = 9EUFEA5U7G;
+				GCC_PRECOMPILE_PREFIX_HEADER = YES;
+				GCC_PREFIX_HEADER = "$(SRCROOT)/bootstrapTool/Classes/Defines.h";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Release;

BIN
bootstrapTool.xcodeproj/project.xcworkspace/xcuserdata/kevinbradley.xcuserdatad/UserInterfaceState.xcuserstate


+ 2 - 1
bootstrapTool/Classes/HelperClass.m

@@ -68,7 +68,7 @@
     if (call==nil)
         return 0;
     char line[200];
-    //DDLogInfo(@"running process: %@", call);
+    DLog(@"\nRunning process: %@\n", call);
     FILE* fp = popen([call UTF8String], "r");
     NSMutableArray *lines = [[NSMutableArray alloc]init];
     if (fp)
@@ -267,6 +267,7 @@
     
     InputPackage *pkg = [InputPackage new];
     pkg.files = finalArray;
+    pkg.path = debFile;
     pkg.packageName = packageName;
     pkg.version = packageVersion;
     return pkg;

+ 2 - 0
bootstrapTool/Classes/InputPackage.h

@@ -9,7 +9,9 @@
 @property (nonatomic, strong) NSArray  *controlFiles;
 @property (nonatomic, strong) NSString *packageName;
 @property (nonatomic, strong) NSString *version;
+@property (nonatomic, strong) NSString *path;
 
+- (void)repackageInCurrentDirectoryWithArch:(NSString *)newArch;
 - (ErrorReturn *)errorReturnForBootstrap:(NSString *)bootstrapPath;
 - (NSString *)listfile;
 @end

+ 56 - 30
bootstrapTool/Classes/InputPackage.m

@@ -36,11 +36,12 @@
     
 }
 
-- (void)repackageFile:(StatusPackageModel *)file arch:(NSString *)newArch {
-/*
+- (void)repackageInCurrentDirectoryWithArch:(NSString *)newArch {
+
+    NSString *fakeRoot = [[HelperClass returnForProcess:@"/usr/bin/which fakeroot"] componentsJoinedByString:@"\n"];
     NSString *pwd = [[HelperClass returnForProcess:@"/bin/pwd"] componentsJoinedByString:@"\n"];
-    DLog(@"\nProcessing file: %@\n", file);
-    Package *output = [HelperClass packageForDeb:repackage];
+    DLog(@"\nProcessing file: %@\n", self.path);
+    InputPackage *output = self;
     
     DLog(@"\nFound package: '%@' at version: '%@'...\n", output.packageName, output.version );
     
@@ -48,47 +49,63 @@
     NSString *debian = [tmpPath stringByAppendingPathComponent:@"DEBIAN"];
     [FM createDirectoryAtPath:tmpPath withIntermediateDirectories:TRUE attributes:nil error:nil];
     DLog(@"\nExtracting package contents for processing...\n");
-    [HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -x %@ %@", debFile, tmpPath]];
+    [HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -x %@ %@", self.path, tmpPath]];
     [FM createDirectoryAtPath:debian withIntermediateDirectories:TRUE attributes:nil error:nil];
     DLog(@"\nExtracting DEBIAN files for processing...\n");
-    [HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -e %@ %@", debFile, debian]];
-    
-    NSString *controlPath = [debian stringByAppendingPathComponent:@"control"];
-    
-    NSMutableString *controlFile = [[NSMutableString alloc] initWithContentsOfFile:controlPath encoding:NSUTF8StringEncoding error:nil];
+    [HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -e %@ %@", self.path, debian]];
     
-    [controlFile replaceOccurrencesOfString:@"iphoneos-arm" withString:@"appletvos-arm64" options:NSLiteralSearch range:NSMakeRange(0, [controlFile length])];
     
-    [controlFile writeToFile:controlPath atomically:TRUE];
+    if (newArch != nil) {
+        
+        NSString *controlPath = [debian stringByAppendingPathComponent:@"control"];
+        
+        NSMutableString *controlFile = [[NSMutableString alloc] initWithContentsOfFile:controlPath encoding:NSUTF8StringEncoding error:nil];
+        //@"appletvos-arm64"
+        [controlFile replaceOccurrencesOfString:@"iphoneos-arm" withString:newArch options:NSLiteralSearch range:NSMakeRange(0, [controlFile length])];
+        
+        [controlFile writeToFile:controlPath atomically:TRUE];
+    }
     
+    //at this point we have the files extracted, time to determine what needs to be changed
     
     NSArray *ignoreFiles = @[@".fauxsu", @".DS_Store"];
     NSArray *forbiddenRoots = @[@"etc", @"var", @"tmp"];
-    NSFileManager *man = [NSFileManager defaultManager];
-    __block NSInteger returnValue = 0; //0 = good to go 1 = over write warning, 2 = no go
-    __block NSMutableArray *_overwriteArray = [NSMutableArray new];
-    [self.files enumerateObjectsUsingBlock:^(PackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+    //__block NSMutableArray *_overwriteArray = [NSMutableArray new];
+    [self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
         
-        if ([obj.fileType isEqualToString:@"file"]){
+        if (obj.type == BSPackageFileTypeFile || obj.type == BSPackageFileTypeDirectory){
             
-            NSString *fullPath = [bootstrapPath stringByAppendingPathComponent:obj.path];
-            if ([man fileExistsAtPath:fullPath] && ![ignoreFiles containsObject:obj.basename]){
+            
+            NSString *fullPath = [tmpPath stringByAppendingPathComponent:obj.path];
+            
+            if ([ignoreFiles containsObject:obj.path.lastPathComponent]){
+                
+                DLog(@"in ignore file list, purge");
+                [FM removeItemAtPath:fullPath error:nil];
                 
-                //DLog(@"[WARNING] overwriting a file that already exists and isn't DS_Store or .fauxsu: %@", fullPath);
-                [_overwriteArray addObject:obj.path];
-                //*stop = TRUE;//return FALSE;
-                returnValue = 1;
             }
             
             NSArray *pathComponents = [obj.path pathComponents];
             if ([pathComponents count] > 1)
             {
+                
                 NSString *rootPath = [pathComponents objectAtIndex:1];
+                DLog(@"\n Checking root path: %@ for file %@\n", rootPath, obj.path);
                 if ([forbiddenRoots containsObject:rootPath])
                 {
-                    DLog(@"\n [ERROR] package file: '%@' would overwrite symbolic link at '%@'! Exiting!\n\n", obj.path, rootPath);
-                    *stop = TRUE;
-                    returnValue = 2;
+                    DLog(@"\n [ERROR] package file: '%@' would overwrite symbolic link at '%@'\n\n", obj.path, rootPath);
+                    NSString *privateDir = [tmpPath stringByAppendingPathComponent:@"private"];
+                    if (![FM fileExistsAtPath:privateDir]){
+                        [FM createDirectoryAtPath:privateDir withIntermediateDirectories:TRUE attributes:nil error:nil];
+                        
+                    }
+                    //take <package_name>/[rootPath] (could be etc, var, tmp) and move to <package_name>/private/[rootPath]
+                    NSString *badPath = [tmpPath stringByAppendingPathComponent:rootPath];
+                    NSString *newPath = [privateDir stringByAppendingPathComponent:rootPath];
+                    DLog(@"\n [INFO] Moving %@ to %@...", badPath, newPath);
+                    [FM moveItemAtPath:badPath toPath:newPath error:nil];
+                    
+
                 }
             }
             
@@ -98,10 +115,19 @@
         
     }];
     
-    ErrorReturn *er = [ErrorReturn new];
-    er.returnStatus = returnValue;
-    er.overwriteFiles = _overwriteArray;
-    */
+    
+    NSString *depArchiveInfo = [NSString stringWithFormat:@"/usr/local/bin/dpkg -b %@", self.packageName];
+    
+    if (fakeRoot) {
+        
+        depArchiveInfo = [NSString stringWithFormat:@"%@ /usr/local/bin/dpkg -b %@", fakeRoot, self.packageName];
+        
+        
+    }
+    
+    [[HelperClass returnForProcess:depArchiveInfo] componentsJoinedByString:@"\n"];
+    
+    
     //return er;
 }
 

+ 10 - 33
bootstrapTool/main.m

@@ -27,7 +27,7 @@
 
 
 
-#define OPTION_FLAGS "o:f:b:l:d:hc"
+#define OPTION_FLAGS "o:i:b:l:d:hcr"
 
 
 char *progname;
@@ -41,7 +41,7 @@ static struct option longopts[] = {
     { "delete",                    required_argument,      NULL,   'd' },
     { "help",                      no_argument,            NULL,   'h' },
     { "clean",                     no_argument,            NULL,   'c' },
-    { "repackage",                 required_argument,      NULL,   'r' },
+    { "repackage",                 no_argument,      NULL,   'r' },
     { NULL,                        0,                      NULL,    0  }
 };
 
@@ -73,7 +73,7 @@ int main(int argc, const char * argv[]) {
         NSString *bootstrapPath = nil;
         NSString *bootstrapListPath = nil;
         NSString *deletePackage = nil;
-        NSString *repackage = nil;
+        BOOL repackage = FALSE;
         BOOL clean = FALSE;
         while ((flag = getopt_long(argc, argv, OPTION_FLAGS, longopts, NULL)) != -1) {
             switch(flag) {
@@ -81,7 +81,7 @@ int main(int argc, const char * argv[]) {
                     octalFile = [NSString stringWithUTF8String:optarg];
                     break;
                     
-                case 'f':
+                case 'i':
                     
                     debFile = [NSString stringWithUTF8String:optarg];
                     break;
@@ -103,7 +103,7 @@ int main(int argc, const char * argv[]) {
                     
                 case 'r':
                     
-                    repackage = [NSString stringWithUTF8String:optarg];
+                    repackage = TRUE;
                     break;
                     
                 case 'c':
@@ -118,35 +118,12 @@ int main(int argc, const char * argv[]) {
             }
         }
         
-        if (repackage) {
-            
-            NSString *pwd = [[HelperClass returnForProcess:@"/bin/pwd"] componentsJoinedByString:@"\n"];
-            DLog(@"\nProcessing file: %@\n", repackage);
-            InputPackage *output = [HelperClass packageForDeb:repackage];
-            
-            DLog(@"\nFound package: '%@' at version: '%@'...\n", output.packageName, output.version );
-            
-            NSString *tmpPath = [pwd stringByAppendingPathComponent:output.packageName];
-            NSString *debian = [tmpPath stringByAppendingPathComponent:@"DEBIAN"];
-            [FM createDirectoryAtPath:tmpPath withIntermediateDirectories:TRUE attributes:nil error:nil];
-            DLog(@"\nExtracting package contents for processing...\n");
-            [HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -x %@ %@", debFile, tmpPath]];
-            [FM createDirectoryAtPath:debian withIntermediateDirectories:TRUE attributes:nil error:nil];
-            DLog(@"\nExtracting DEBIAN files for processing...\n");
-            [HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -e %@ %@", debFile, debian]];
-            
-            NSString *controlPath = [debian stringByAppendingPathComponent:@"control"];
-            
-            NSMutableString *controlFile = [[NSMutableString alloc] initWithContentsOfFile:controlPath encoding:NSUTF8StringEncoding error:nil];
-            
-            [controlFile replaceOccurrencesOfString:@"iphoneos-arm" withString:@"appletvos-arm64" options:NSLiteralSearch range:NSMakeRange(0, [controlFile length])];
-            
-            [controlFile writeToFile:controlPath atomically:TRUE];
-            
-            
-            
-    
+        if (repackage == TRUE && debFile) {
             
+            DLog(@"\n [INFO] Repackaging file: %@...\n", debFile);
+            InputPackage *output = [HelperClass packageForDeb:debFile];
+            [output repackageInCurrentDirectoryWithArch:@"appletvos-arm64"];
+            return 0;
         }
         
         //DLog(@"folder: %@ project: %@", folder, project);