mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-12-23 03:40:08 +01:00
🐛 Don't use whoami and use NSHomeDirectory()
- This commit replaces the usage of `whoami` with `id -un`. - This also changes all `~` replacements with the result of calling the `NSHomeDirectory()` which may differ from `id -un` (#189)
This commit is contained in:
@@ -1687,7 +1687,7 @@
|
|||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 951;
|
CURRENT_PROJECT_VERSION = 955;
|
||||||
DEBUG = YES;
|
DEBUG = YES;
|
||||||
DEVELOPMENT_TEAM = 8M54J5J787;
|
DEVELOPMENT_TEAM = 8M54J5J787;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
@@ -1697,7 +1697,7 @@
|
|||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
||||||
MARKETING_VERSION = 5.5.0;
|
MARKETING_VERSION = 5.5.1;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
|
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
@@ -1714,7 +1714,7 @@
|
|||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 951;
|
CURRENT_PROJECT_VERSION = 955;
|
||||||
DEBUG = NO;
|
DEBUG = NO;
|
||||||
DEVELOPMENT_TEAM = 8M54J5J787;
|
DEVELOPMENT_TEAM = 8M54J5J787;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
@@ -1724,7 +1724,7 @@
|
|||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
||||||
MARKETING_VERSION = 5.5.0;
|
MARKETING_VERSION = 5.5.1;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
|
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class Paths {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
baseDir = App.architecture != "x86_64" ? .opt : .usr
|
baseDir = App.architecture != "x86_64" ? .opt : .usr
|
||||||
userName = String(Shell.pipe("whoami").split(separator: "\n")[0])
|
userName = String(Shell.pipe("id -un").split(separator: "\n")[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
public func detectBinaryPaths() {
|
public func detectBinaryPaths() {
|
||||||
@@ -57,6 +57,10 @@ public class Paths {
|
|||||||
return shared.userName
|
return shared.userName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static var homePath: String {
|
||||||
|
return NSHomeDirectory()
|
||||||
|
}
|
||||||
|
|
||||||
public static var cellarPath: String {
|
public static var cellarPath: String {
|
||||||
return "\(shared.baseDir.rawValue)/Cellar"
|
return "\(shared.baseDir.rawValue)/Cellar"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class Filesystem {
|
|||||||
*/
|
*/
|
||||||
public static func exists(_ path: String) -> Bool {
|
public static func exists(_ path: String) -> Bool {
|
||||||
return FileManager.default.fileExists(
|
return FileManager.default.fileExists(
|
||||||
atPath: path.replacingOccurrences(of: "~", with: "/Users/\(Paths.whoami)")
|
atPath: path.replacingOccurrences(of: "~", with: Paths.homePath)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,13 +26,29 @@ class Filesystem {
|
|||||||
public static func fileExists(_ path: String) -> Bool {
|
public static func fileExists(_ path: String) -> Bool {
|
||||||
var isDirectory: ObjCBool = true
|
var isDirectory: ObjCBool = true
|
||||||
let exists = FileManager.default.fileExists(
|
let exists = FileManager.default.fileExists(
|
||||||
atPath: path.replacingOccurrences(of: "~", with: "/Users/\(Paths.whoami)"),
|
atPath: path.replacingOccurrences(of: "~", with: Paths.homePath),
|
||||||
isDirectory: &isDirectory
|
isDirectory: &isDirectory
|
||||||
)
|
)
|
||||||
|
|
||||||
return exists && !isDirectory.boolValue
|
return exists && !isDirectory.boolValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Checks if a directory exists at the provided path.
|
||||||
|
*/
|
||||||
|
public static func directoryExists(_ path: String) -> Bool {
|
||||||
|
var isDirectory: ObjCBool = true
|
||||||
|
let exists = FileManager.default.fileExists(
|
||||||
|
atPath: path.replacingOccurrences(of: "~", with: Paths.homePath),
|
||||||
|
isDirectory: &isDirectory
|
||||||
|
)
|
||||||
|
|
||||||
|
return exists && isDirectory.boolValue
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Checks if a given file is a symbolic link.
|
||||||
|
*/
|
||||||
public static func fileIsSymlink(_ path: String) -> Bool {
|
public static func fileIsSymlink(_ path: String) -> Bool {
|
||||||
do {
|
do {
|
||||||
let attribs = try FileManager.default.attributesOfItem(atPath: path)
|
let attribs = try FileManager.default.attributesOfItem(atPath: path)
|
||||||
@@ -42,17 +58,4 @@ class Filesystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Checks if a directory exists at the provided path.
|
|
||||||
*/
|
|
||||||
public static func directoryExists(_ path: String) -> Bool {
|
|
||||||
var isDirectory: ObjCBool = true
|
|
||||||
let exists = FileManager.default.fileExists(
|
|
||||||
atPath: path.replacingOccurrences(of: "~", with: "/Users/\(Paths.whoami)"),
|
|
||||||
isDirectory: &isDirectory
|
|
||||||
)
|
|
||||||
|
|
||||||
return exists && isDirectory.boolValue
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ class PhpHelper {
|
|||||||
let dotless = version.replacingOccurrences(of: ".", with: "")
|
let dotless = version.replacingOccurrences(of: ".", with: "")
|
||||||
|
|
||||||
// Determine the dotless name for this PHP version
|
// Determine the dotless name for this PHP version
|
||||||
let destination = "/Users/\(Paths.whoami)/.config/phpmon/bin/pm\(dotless)"
|
let destination = "\(Paths.homePath)/.config/phpmon/bin/pm\(dotless)"
|
||||||
|
|
||||||
// Check if the ~/.config/phpmon/bin directory is in the PATH
|
// Check if the ~/.config/phpmon/bin directory is in the PATH
|
||||||
let inPath = Shell.user.PATH.contains("/Users/\(Paths.whoami)/.config/phpmon/bin")
|
let inPath = Shell.user.PATH.contains("\(Paths.homePath)/.config/phpmon/bin")
|
||||||
|
|
||||||
// Check if we can create symlinks (`/usr/local/bin` must be writable)
|
// Check if we can create symlinks (`/usr/local/bin` must be writable)
|
||||||
let canWriteSymlinks = FileManager.default.isWritableFile(atPath: "/usr/local/bin/")
|
let canWriteSymlinks = FileManager.default.isWritableFile(atPath: "/usr/local/bin/")
|
||||||
@@ -81,7 +81,7 @@ class PhpHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static func createSymlink(_ dotless: String) {
|
private static func createSymlink(_ dotless: String) {
|
||||||
let source = "/Users/\(Paths.whoami)/.config/phpmon/bin/pm\(dotless)"
|
let source = "\(Paths.homePath)/.config/phpmon/bin/pm\(dotless)"
|
||||||
let destination = "/usr/local/bin/pm\(dotless)"
|
let destination = "/usr/local/bin/pm\(dotless)"
|
||||||
|
|
||||||
if !Filesystem.fileExists(destination) {
|
if !Filesystem.fileExists(destination) {
|
||||||
|
|||||||
@@ -32,18 +32,11 @@ class PhpConfigurationFile: CreatedFromFile {
|
|||||||
|
|
||||||
/** Resolves a PHP configuration file (.ini) */
|
/** Resolves a PHP configuration file (.ini) */
|
||||||
static func from(filePath: String) -> Self? {
|
static func from(filePath: String) -> Self? {
|
||||||
let path = filePath.replacingOccurrences(
|
let path = filePath.replacingOccurrences(of: "~", with: Paths.homePath)
|
||||||
of: "~",
|
|
||||||
with: "/Users/\(Paths.whoami)"
|
|
||||||
)
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let fileContents = try String(contentsOfFile: path)
|
let fileContents = try String(contentsOfFile: path)
|
||||||
|
return Self.init(path: path, contents: fileContents)
|
||||||
return Self.init(
|
|
||||||
path: path,
|
|
||||||
contents: fileContents
|
|
||||||
)
|
|
||||||
} catch {
|
} catch {
|
||||||
Log.warn("Could not read the PHP configuration file at: `\(filePath)`")
|
Log.warn("Could not read the PHP configuration file at: `\(filePath)`")
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -21,18 +21,12 @@ class NginxConfigurationFile: CreatedFromFile {
|
|||||||
|
|
||||||
/** Resolves an nginx configuration file (.conf) */
|
/** Resolves an nginx configuration file (.conf) */
|
||||||
static func from(filePath: String) -> Self? {
|
static func from(filePath: String) -> Self? {
|
||||||
let path = filePath.replacingOccurrences(
|
let path = filePath.replacingOccurrences(of: "~", with: Paths.homePath)
|
||||||
of: "~",
|
|
||||||
with: "/Users/\(Paths.whoami)"
|
|
||||||
)
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let fileContents = try String(contentsOfFile: path)
|
let fileContents = try String(contentsOfFile: path)
|
||||||
|
|
||||||
return Self.init(
|
return Self.init(path: path, contents: fileContents)
|
||||||
path: path,
|
|
||||||
contents: fileContents
|
|
||||||
)
|
|
||||||
} catch {
|
} catch {
|
||||||
Log.warn("Could not read the nginx configuration file at: `\(filePath)`")
|
Log.warn("Could not read the nginx configuration file at: `\(filePath)`")
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class ValetSite: DomainListable {
|
|||||||
/// replacing the user's home folder with ~.
|
/// replacing the user's home folder with ~.
|
||||||
lazy var absolutePathRelative: String = {
|
lazy var absolutePathRelative: String = {
|
||||||
return self.absolutePath
|
return self.absolutePath
|
||||||
.replacingOccurrences(of: "/Users/\(Paths.whoami)", with: "~")
|
.replacingOccurrences(of: Paths.homePath, with: "~")
|
||||||
}()
|
}()
|
||||||
|
|
||||||
/// The TLD used to locate this site.
|
/// The TLD used to locate this site.
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ class Preferences {
|
|||||||
moveOutdatedConfigurationFile()
|
moveOutdatedConfigurationFile()
|
||||||
|
|
||||||
// Attempt to load the file if it exists
|
// Attempt to load the file if it exists
|
||||||
let url = URL(fileURLWithPath: "/Users/\(Paths.whoami)/.config/phpmon/config.json")
|
let url = URL(fileURLWithPath: "\(Paths.homePath)/.config/phpmon/config.json")
|
||||||
if Filesystem.fileExists(url.path) {
|
if Filesystem.fileExists(url.path) {
|
||||||
|
|
||||||
Log.info("A custom ~/.config/phpmon/config.json file was found. Attempting to parse...")
|
Log.info("A custom ~/.config/phpmon/config.json file was found. Attempting to parse...")
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ struct Preset: Codable, Equatable {
|
|||||||
|
|
||||||
try! String(data: data, encoding: .utf8)!
|
try! String(data: data, encoding: .utf8)!
|
||||||
.write(
|
.write(
|
||||||
toFile: "/Users/\(Paths.whoami)/.config/phpmon/preset_revert.json",
|
toFile: "\(Paths.homePath)/.config/phpmon/preset_revert.json",
|
||||||
atomically: true,
|
atomically: true,
|
||||||
encoding: .utf8
|
encoding: .utf8
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class PresetHelper {
|
|||||||
|
|
||||||
public static func loadRollbackPresetFromFile() {
|
public static func loadRollbackPresetFromFile() {
|
||||||
guard let revert = try? String(
|
guard let revert = try? String(
|
||||||
contentsOfFile: "/Users/\(Paths.whoami)/.config/phpmon/preset_revert.json",
|
contentsOfFile: "\(Paths.homePath)/.config/phpmon/preset_revert.json",
|
||||||
encoding: .utf8
|
encoding: .utf8
|
||||||
) else {
|
) else {
|
||||||
PresetHelper.rollbackPreset = nil
|
PresetHelper.rollbackPreset = nil
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class WarningManager {
|
|||||||
),
|
),
|
||||||
Warning(
|
Warning(
|
||||||
command: {
|
command: {
|
||||||
return !Shell.user.PATH.contains("/Users/\(Paths.whoami)/.config/phpmon/bin") &&
|
return !Shell.user.PATH.contains("\(Paths.homePath)/.config/phpmon/bin") &&
|
||||||
!FileManager.default.isWritableFile(atPath: "/usr/local/bin/")
|
!FileManager.default.isWritableFile(atPath: "/usr/local/bin/")
|
||||||
},
|
},
|
||||||
name: "Helpers cannot be symlinked and not in PATH",
|
name: "Helpers cannot be symlinked and not in PATH",
|
||||||
|
|||||||
Reference in New Issue
Block a user