Skip to content

Commit ce59935

Browse files
authored
Model additional system commands (#332)
Model the pkgbuild command with the usual structure used for other commands. Provide a custom string convertible implementation for configuration so that the configuration can be easily converted into a string for logging and comparison purposes. Create a runEcho() implementation for the build swiftly release script so that commands can output their command-line to the log for reproducibility. Add custom string capabilities to Configuration and Arguments to support this. Model the Linux getent command. Model a small subset of the git command. Replace array += with append to save on allocations.
1 parent d15d77a commit ce59935

File tree

6 files changed

+490
-78
lines changed

6 files changed

+490
-78
lines changed

Sources/LinuxPlatform/Linux.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22
import SwiftlyCore
33
import SystemPackage
44

5+
typealias sys = SwiftlyCore.SystemCommand
56
typealias fs = SwiftlyCore.FileSystem
67

78
/// `Platform` implementation for Linux systems.
@@ -605,15 +606,8 @@ public struct Linux: Platform {
605606

606607
public func getShell() async throws -> String {
607608
let userName = ProcessInfo.processInfo.userName
608-
let prefix = "\(userName):"
609-
if let passwds = try await runProgramOutput("getent", "passwd") {
610-
for line in passwds.components(separatedBy: "\n") {
611-
if line.hasPrefix(prefix) {
612-
if case let comps = line.components(separatedBy: ":"), comps.count > 1 {
613-
return comps[comps.count - 1]
614-
}
615-
}
616-
}
609+
if let entry = try await sys.getent(database: "passwd", keys: userName).entries(self).first {
610+
if let shell = entry.last { return shell }
617611
}
618612

619613
// Fall back on bash on Linux and other Unixes

0 commit comments

Comments
 (0)