Skip to content

Commit

Permalink
feat: add preinstall script for installer
Browse files Browse the repository at this point in the history
  • Loading branch information
willswire committed Oct 1, 2024
1 parent 68efed4 commit ac6431a
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 283 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
--version "${{ github.ref }}" \
--install-location "/" \
--sign="Developer ID Installer: William Walker (QSQY64SHJ5)" \
--scripts "scripts/" \
cosmic.pkg
- name: Notarize package
Expand Down Expand Up @@ -102,7 +103,7 @@ jobs:
draft: false
prerelease: false

- name: Upload binary
- name: Upload pkg installer
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 0 additions & 1 deletion Cosmic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
Common/Utils.swift,
Cosmic.swift,
Subcommands/Add.swift,
Subcommands/Setup.swift,
);
target = 6BD783982C98FBFF009EEB33 /* CosmicTests */;
};
Expand Down
87 changes: 42 additions & 45 deletions Cosmic/Common/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ extension Digest {
/// Array of bytes representing the digest.
var bytes: [UInt8] { Array(makeIterator()) }

/// Data representation of the digest.
var data: Data { Data(bytes) }

/// Hexadecimal string representation of the digest.
var hexStr: String { bytes.map { String(format: "%02X", $0) }.joined() }
}
Expand Down Expand Up @@ -100,48 +97,48 @@ func unarchive(from sourcePath: String, for name: String, strip: Bool) throws ->
/// - name: Name of the package being extracted.
/// - Returns: URL of the extracted files' directory.
/// - Throws: `ExtractionError` in case of issues during the extraction.
func unzip(from sourcePath: String, for name: String) throws -> URL {
let fileManager = FileManager.default

// Check if the source file exists
guard fileManager.fileExists(atPath: sourcePath) else {
throw ExtractionError.fileDoesNotExist("File does not exist at \(sourcePath)")
}

// Set up the temporary directory path for extraction
let destinationURL = fileManager.temporaryDirectory.appendingPathComponent(name)

// Create the destination directory
do {
try fileManager.createDirectory(
at: destinationURL, withIntermediateDirectories: true, attributes: nil)
} catch {
throw ExtractionError.failedToCreateDirectory(
"Failed to create destination directory: \(error.localizedDescription)")
}

// Configure the `unzip` process for extraction
let process = Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/unzip")
process.arguments = [sourcePath, "-d", destinationURL.path]
process.standardOutput = nil
process.standardError = nil

// Execute the `unzip` process and handle its result
do {
try process.run()
process.waitUntilExit()

guard process.terminationStatus == 0 else {
throw ExtractionError.extractionFailed(process.terminationStatus)
}

return destinationURL
} catch {
throw ExtractionError.extractionProcessFailed(
"Failed to run extraction process: \(error.localizedDescription)")
}
}
//func unzip(from sourcePath: String, for name: String) throws -> URL {
// let fileManager = FileManager.default
//
// // Check if the source file exists
// guard fileManager.fileExists(atPath: sourcePath) else {
// throw ExtractionError.fileDoesNotExist("File does not exist at \(sourcePath)")
// }
//
// // Set up the temporary directory path for extraction
// let destinationURL = fileManager.temporaryDirectory.appendingPathComponent(name)
//
// // Create the destination directory
// do {
// try fileManager.createDirectory(
// at: destinationURL, withIntermediateDirectories: true, attributes: nil)
// } catch {
// throw ExtractionError.failedToCreateDirectory(
// "Failed to create destination directory: \(error.localizedDescription)")
// }
//
// // Configure the `unzip` process for extraction
// let process = Process()
// process.executableURL = URL(fileURLWithPath: "/usr/bin/unzip")
// process.arguments = [sourcePath, "-d", destinationURL.path]
// process.standardOutput = nil
// process.standardError = nil
//
// // Execute the `unzip` process and handle its result
// do {
// try process.run()
// process.waitUntilExit()
//
// guard process.terminationStatus == 0 else {
// throw ExtractionError.extractionFailed(process.terminationStatus)
// }
//
// return destinationURL
// } catch {
// throw ExtractionError.extractionProcessFailed(
// "Failed to run extraction process: \(error.localizedDescription)")
// }
//}

func setExecutablePermission(for fileURL: URL) throws {
let attributes = try FileManager.default.attributesOfItem(atPath: fileURL.path)
Expand Down
2 changes: 1 addition & 1 deletion Cosmic/Cosmic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import PklSwift
@main struct Cosmic: AsyncParsableCommand {
static var configuration = CommandConfiguration(
abstract: "A package manager for macOS.",
subcommands: [Setup.self, Add.self])
subcommands: [Add.self])

struct Options: ParsableArguments {
@Flag var verbose: Bool = false
Expand Down
5 changes: 3 additions & 2 deletions Cosmic/Subcommands/Add.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ extension Cosmic {
case .binary:
resultURL = url
case .zip:
resultURL = try unzip(from: url.path(), for: package.name)
//resultURL = try unzip(from: url.path(), for: package.name)
throw AddError.invalidPackage
case .archive:
resultURL = try unarchive(
from: url.path(), for: package.name, strip: package.isBundle)
Expand Down Expand Up @@ -173,7 +174,7 @@ extension Cosmic {
func install(package: Package.Module, from url: URL) async throws {
log("Installing package...")
let homePackagesPath = fileManager.homeDirectoryForCurrentUser
.appendingPathComponent("Packages")
.appendingPathComponent(".cosmic")

if !fileManager.fileExists(atPath: homePackagesPath.path) {
try fileManager.createDirectory(
Expand Down
201 changes: 0 additions & 201 deletions Cosmic/Subcommands/Setup.swift

This file was deleted.

Loading

0 comments on commit ac6431a

Please sign in to comment.