Skip to content

Commit

Permalink
Fixed up some listing rules after installing SwiftLint on my new dev box
Browse files Browse the repository at this point in the history
refactor sha256sum to checksum
removed old preference definitions, some of which were being used in-code. Since these were never being populated they would not evaluate and conditional code was not being run as a result.
  • Loading branch information
Bart Reardon committed Jun 18, 2023
1 parent 2009177 commit e902c37
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 30 deletions.
8 changes: 4 additions & 4 deletions Outset.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 4.0.3;
MARKETING_VERSION = 4.0.4;
PRODUCT_BUNDLE_IDENTIFIER = io.macadmins.Outset;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -505,7 +505,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 4.0.3;
MARKETING_VERSION = 4.0.4;
PRODUCT_BUNDLE_IDENTIFIER = io.macadmins.Outset;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -543,7 +543,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 4.0.3;
MARKETING_VERSION = 4.0.4;
PRODUCT_BUNDLE_IDENTIFIER = io.macadmins.Outset;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -585,7 +585,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 4.0.3;
MARKETING_VERSION = 4.0.4;
PRODUCT_BUNDLE_IDENTIFIER = io.macadmins.Outset;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
10 changes: 6 additions & 4 deletions Outset/Functions/FileUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Bart Reardon on 3/12/2022.
//
// swiftlint:disable large_tuple line_length function_body_length
// swiftlint:disable large_tuple line_length

import Foundation
import CommonCrypto
Expand Down Expand Up @@ -333,14 +333,14 @@ func sha256(for url: URL) -> String? {
}
}

func shaAllFiles() {
// compute sha256sum for all files in the outset directory
func checksumAllFiles() {
// compute checksum (SHA256) for all files in the outset directory
// returns data in two formats to stdout:
// plaintext
// as plist format ready for import into an MDM or converting to a .mobileconfig

let url = URL(fileURLWithPath: outsetDirectory)
writeLog("SHASUM", logLevel: .info)
writeLog("CHECKSUM", logLevel: .info)
var shasumPlist = FileHashes()
if let enumerator = FileManager.default.enumerator(at: url, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) {
for case let fileURL as URL in enumerator {
Expand Down Expand Up @@ -392,3 +392,5 @@ extension URL {
(try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true
}
}

// swiftlint:enable large_tuple line_length
2 changes: 2 additions & 0 deletions Outset/Functions/Processing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@ func processItems(_ path: String, deleteItems: Bool=false, once: Bool=false, ove
}

}

// swiftlint:enable function_body_length cyclomatic_complexity
2 changes: 2 additions & 0 deletions Outset/Functions/Services.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ class ServiceManager {
status(loginWindowAgent)
}
}

// swiftlint:enable line_length
6 changes: 4 additions & 2 deletions Outset/Functions/SystemUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ func waitForNetworkUp(timeout: Double) -> Bool {
}

func loginWindowUpdateState(_ action: Action) {
var cmd : String
var loginWindowPlist : String = "/System/Library/LaunchDaemons/com.apple.loginwindow.plist"
var cmd: String
let loginWindowPlist: String = "/System/Library/LaunchDaemons/com.apple.loginwindow.plist"
switch action {
case .enable:
writeLog("Enabling loginwindow process", logLevel: .debug)
Expand Down Expand Up @@ -328,3 +328,5 @@ func writeSysReport() {
writeLog("OS: \(getOSVersion())", logLevel: .debug)
writeLog("Build: \(getOSBuildVersion())", logLevel: .debug)
}

// swiftlint:enable line_length
48 changes: 28 additions & 20 deletions Outset/Outset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ArgumentParser
import OSLog

let author = "Bart Reardon - Adapted from outset by Joseph Chilcote (chilcote@gmail.com) https://github.com/chilcote/outset"
let outsetVersion: AnyObject? = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as AnyObject
let outsetVersion: AnyObject = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as AnyObject

// Outset specific directories
let outsetDirectory = "/usr/local/outset/"
Expand Down Expand Up @@ -41,10 +41,6 @@ let requiredExecutablePermissions: NSNumber = 0o755
var debugMode: Bool = false
var loginwindowState: Bool = true
var consoleUser: String = getConsoleUserInfo().username
var networkWait: Bool = true
var networkTimeout: Int = 180
var ignoredUsers: [String] = []
var loginOnceOverride: [String: Date] = [String: Date]()
var continueFirstBoot: Bool = true
var prefs = loadPreferences()

Expand Down Expand Up @@ -98,12 +94,19 @@ struct Outset: ParsableCommand {
@Option(help: ArgumentHelp("Remove one or more scripts from override list", valueName: "script"), completion: .file())
var removeOveride: [String] = []

@Option(help: ArgumentHelp("Compute the SHA256 hash of the given file. Use the keyword 'all' to compute all SHA values and generate a formatted configuration plist", valueName: "file"), completion: .file())
// removed from view in favour for checksum. retained to support backward compatability
@Option(help: .hidden, completion: .file())
var computeSHA: [String] = []

@Option(help: ArgumentHelp("Compute the checksum (SHA256) hash of the given file. Use the keyword 'all' to compute all values and generate a formatted configuration plist", valueName: "file"), completion: .file())
var checksum: [String] = []

@Flag(help: .hidden)
var shasumReport = false

@Flag(help: .hidden)
var checksumReport = false

@Flag(help: .hidden)
var enableServices = false

Expand Down Expand Up @@ -143,10 +146,10 @@ struct Outset: ParsableCommand {
writePreferences(prefs: prefs)

if !folderContents(path: bootOnceDir).isEmpty {
if networkWait {
if prefs.waitForNetwork {
loginwindowState = false
loginWindowUpdateState(.disable)
continueFirstBoot = waitForNetworkUp(timeout: floor(Double(networkTimeout) / 10))
continueFirstBoot = waitForNetworkUp(timeout: floor(Double(prefs.networkTimeout) / 10))
}
if continueFirstBoot {
writeSysReport()
Expand Down Expand Up @@ -176,7 +179,7 @@ struct Outset: ParsableCommand {

if login {
writeLog("Processing scheduled runs for login", logLevel: .debug)
if !ignoredUsers.contains(consoleUser) {
if !prefs.ignoredUsers.contains(consoleUser) {
if !folderContents(path: loginOnceDir).isEmpty {
processItems(loginOnceDir, once: true, override: prefs.overrideLoginOnce)
}
Expand All @@ -195,7 +198,7 @@ struct Outset: ParsableCommand {
if checkFileExists(path: loginPrivilegedTrigger) {
pathCleanup(pathname: loginPrivilegedTrigger)
}
if !ignoredUsers.contains(consoleUser) {
if !prefs.ignoredUsers.contains(consoleUser) {
if !folderContents(path: loginOncePrivilegedDir).isEmpty {
processItems(loginOncePrivilegedDir, once: true, override: prefs.overrideLoginOnce)
}
Expand Down Expand Up @@ -231,7 +234,7 @@ struct Outset: ParsableCommand {

if loginEvery {
writeLog("Processing scripts in login-every", logLevel: .debug)
if !ignoredUsers.contains(consoleUser) {
if !prefs.ignoredUsers.contains(consoleUser) {
if !folderContents(path: loginEveryDir).isEmpty {
processItems(loginEveryDir)
}
Expand All @@ -240,7 +243,7 @@ struct Outset: ParsableCommand {

if loginOnce {
writeLog("Processing scripts in login-once", logLevel: .debug)
if !ignoredUsers.contains(consoleUser) {
if !prefs.ignoredUsers.contains(consoleUser) {
if !folderContents(path: loginOnceDir).isEmpty {
processItems(loginOnceDir, once: true)
}
Expand Down Expand Up @@ -305,31 +308,36 @@ struct Outset: ParsableCommand {
writePreferences(prefs: prefs)
}

if !computeSHA.isEmpty {
if computeSHA[0].lowercased() == "all" {
shaAllFiles()
if !checksum.isEmpty || !computeSHA.isEmpty {
if checksum.isEmpty {
checksum = computeSHA
}
if checksum[0].lowercased() == "all" {
checksumAllFiles()
} else {
for fileToHash in computeSHA {
for fileToHash in checksum {
let url = URL(fileURLWithPath: fileToHash)
if let hash = sha256(for: url) {
print("SHA256 for file \(fileToHash): \(hash)")
print("Checksum for file \(fileToHash): \(hash)")
}
}
}
}

if shasumReport {
writeLog("sha256sum report", logLevel: .info)
if shasumReport || checksumReport {
writeLog("Checksum report", logLevel: .info)
for (filename, shasum) in shasumLoadApprovedFileHashList() {
writeLog("\(filename) : \(shasum)", logLevel: .info)
}
}

if version {
print(outsetVersion ?? "4.0")
print(outsetVersion)
if debugMode {
writeSysReport()
}
}
}
}

// swiftlint:enable line_length function_body_length cyclomatic_complexity

0 comments on commit e902c37

Please sign in to comment.