diff --git a/admin/osx/mac-crafter/Sources/Utils/Codesign.swift b/admin/osx/mac-crafter/Sources/Utils/Codesign.swift index 426d3ce05a4d6..405371f1106d4 100644 --- a/admin/osx/mac-crafter/Sources/Utils/Codesign.swift +++ b/admin/osx/mac-crafter/Sources/Utils/Codesign.swift @@ -70,11 +70,12 @@ func recursivelyCodesign( } for case let enumeratedItem as String in pathEnumerator { - let isExecutableFile = try isExecutable(fm.currentDirectoryPath + "/" + path + "/" + enumeratedItem) + let enumeratedItemPath = "\(path)/\(enumeratedItem)" + let isExecutableFile = try isExecutable(enumeratedItemPath) guard isLibrary(enumeratedItem) || isAppExtension(enumeratedItem) || isExecutableFile else { continue } - try codesign(identity: identity, path: "\(path)/\(enumeratedItem)", options: options) + try codesign(identity: identity, path: enumeratedItemPath, options: options) } } @@ -144,6 +145,15 @@ func codesignClientAppBundle( } // Now we do the final codesign bit + let binariesDir = "\(clientContentsDir)/MacOS" print("Code-signing Nextcloud Desktop Client binaries...") - try recursivelyCodesign(path: "\(clientContentsDir)/MacOS/", identity: codeSignIdentity) + try recursivelyCodesign(path: binariesDir, identity: codeSignIdentity) + + guard let appName = clientAppDir.components(separatedBy: "/").last, clientAppDir.hasSuffix(".app") else { + throw AppBundleSigningError.couldNotEnumerate("Failed to determine main executable name.") + } + + // Sign the main executable last + let mainExecutableName = String(appName.dropLast(".app".count)) + try codesign(identity: codeSignIdentity, path: "\(binariesDir)/\(mainExecutableName)") } diff --git a/admin/osx/mac-crafter/Sources/main.swift b/admin/osx/mac-crafter/Sources/main.swift index 3d2f48f93acb7..1507e8350753b 100644 --- a/admin/osx/mac-crafter/Sources/main.swift +++ b/admin/osx/mac-crafter/Sources/main.swift @@ -267,7 +267,10 @@ struct Codesign: ParsableCommand { var codeSignIdentity: String mutating func run() throws { - try codesignClientAppBundle(at: appBundlePath, withCodeSignIdentity: codeSignIdentity) + let absolutePath = appBundlePath.hasPrefix("/") + ? appBundlePath + : "\(FileManager.default.currentDirectoryPath)/\(appBundlePath)" + try codesignClientAppBundle(at: absolutePath, withCodeSignIdentity: codeSignIdentity) } }