Skip to content

Commit

Permalink
v0.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
rimusz committed Jul 5, 2016
1 parent 7c32e19 commit 53d315e
Show file tree
Hide file tree
Showing 17 changed files with 474 additions and 16 deletions.
Binary file added src/bin/corectl
Binary file not shown.
Binary file added src/bin/corectld
Binary file not shown.
Binary file added src/bin/corectld.runner
Binary file not shown.
19 changes: 19 additions & 0 deletions src/copy_corectl_blobs.command
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

#
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "${DIR}"/functions.sh

res_folder=$1

# copy blobs
# get password for sudo
my_password=$(security find-generic-password -wa coreosctl-app)
# reset sudo
sudo -k > /dev/null 2>&1

printf '%s\n' "$my_password" | sudo -Sv > /dev/null 2>&1

# copy blobs
echo "Copying files ..."
sudo cp -f "${res_folder}"/* /usr/local/sbin
36 changes: 34 additions & 2 deletions src/corectl.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
1366053F1D23D6C700D497A0 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1366053E1D23D6C700D497A0 /* Cocoa.framework */; };
136605431D23E85800D497A0 /* fetch_latest_iso_beta.command in Resources */ = {isa = PBXBuildFile; fileRef = 136605411D23E85800D497A0 /* fetch_latest_iso_beta.command */; };
136605441D23E85800D497A0 /* fetch_latest_iso_stable.command in Resources */ = {isa = PBXBuildFile; fileRef = 136605421D23E85800D497A0 /* fetch_latest_iso_stable.command */; };
1375975B1D2BA78E000CB88F /* bin in Resources */ = {isa = PBXBuildFile; fileRef = 1375975A1D2BA78E000CB88F /* bin */; };
1375975F1D2BA816000CB88F /* get_go_binaries in Resources */ = {isa = PBXBuildFile; fileRef = 1375975E1D2BA816000CB88F /* get_go_binaries */; };
137597631D2BC9CF000CB88F /* update_corectl_blobs.command in Resources */ = {isa = PBXBuildFile; fileRef = 137597621D2BC9CF000CB88F /* update_corectl_blobs.command */; };
137597651D2BD5A6000CB88F /* copy_corectl_blobs.command in Resources */ = {isa = PBXBuildFile; fileRef = 137597641D2BD5A5000CB88F /* copy_corectl_blobs.command */; };
137597671D2BE71C000CB88F /* sudo_password.command in Resources */ = {isa = PBXBuildFile; fileRef = 137597661D2BE71C000CB88F /* sudo_password.command */; };
1375976B1D2BF306000CB88F /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1375976A1D2BF306000CB88F /* Security.framework */; };
1375976D1D2BF361000CB88F /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1375976C1D2BF361000CB88F /* Keychain.swift */; };
1375976F1D2C05AA000CB88F /* start_corectld.command in Resources */ = {isa = PBXBuildFile; fileRef = 1375976E1D2C05AA000CB88F /* start_corectld.command */; };
13CAFC2A1D2272B000E57ED4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13CAFC291D2272B000E57ED4 /* AppDelegate.swift */; };
13CAFC2C1D2272B000E57ED4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13CAFC2B1D2272B000E57ED4 /* Assets.xcassets */; };
13CAFC2F1D2272B000E57ED4 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13CAFC2D1D2272B000E57ED4 /* MainMenu.xib */; };
Expand All @@ -27,6 +35,14 @@
1366053E1D23D6C700D497A0 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
136605411D23E85800D497A0 /* fetch_latest_iso_beta.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = fetch_latest_iso_beta.command; sourceTree = "<group>"; };
136605421D23E85800D497A0 /* fetch_latest_iso_stable.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = fetch_latest_iso_stable.command; sourceTree = "<group>"; };
1375975A1D2BA78E000CB88F /* bin */ = {isa = PBXFileReference; lastKnownFileType = folder; path = bin; sourceTree = "<group>"; };
1375975E1D2BA816000CB88F /* get_go_binaries */ = {isa = PBXFileReference; lastKnownFileType = folder; path = get_go_binaries; sourceTree = "<group>"; };
137597621D2BC9CF000CB88F /* update_corectl_blobs.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = update_corectl_blobs.command; sourceTree = "<group>"; };
137597641D2BD5A5000CB88F /* copy_corectl_blobs.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = copy_corectl_blobs.command; sourceTree = "<group>"; };
137597661D2BE71C000CB88F /* sudo_password.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = sudo_password.command; sourceTree = "<group>"; };
1375976A1D2BF306000CB88F /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
1375976C1D2BF361000CB88F /* Keychain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Keychain.swift; sourceTree = "<group>"; };
1375976E1D2C05AA000CB88F /* start_corectld.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = start_corectld.command; sourceTree = "<group>"; };
13CAFC261D2272B000E57ED4 /* corectl.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = corectl.app; sourceTree = BUILT_PRODUCTS_DIR; };
13CAFC291D2272B000E57ED4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
13CAFC2B1D2272B000E57ED4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand All @@ -39,6 +55,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1375976B1D2BF306000CB88F /* Security.framework in Frameworks */,
1366053F1D23D6C700D497A0 /* Cocoa.framework in Frameworks */,
1366053D1D23D6B800D497A0 /* AppKit.framework in Frameworks */,
1366053B1D23D6AD00D497A0 /* Foundation.framework in Frameworks */,
Expand All @@ -51,9 +68,13 @@
136605351D23CC9A00D497A0 /* scripts */ = {
isa = PBXGroup;
children = (
1375976E1D2C05AA000CB88F /* start_corectld.command */,
136605361D23CCB200D497A0 /* fetch_latest_iso_alpha.command */,
136605411D23E85800D497A0 /* fetch_latest_iso_beta.command */,
136605421D23E85800D497A0 /* fetch_latest_iso_stable.command */,
137597621D2BC9CF000CB88F /* update_corectl_blobs.command */,
137597641D2BD5A5000CB88F /* copy_corectl_blobs.command */,
137597661D2BE71C000CB88F /* sudo_password.command */,
136605371D23CCB200D497A0 /* functions.sh */,
);
name = scripts;
Expand All @@ -62,6 +83,7 @@
136605401D23D6F600D497A0 /* Frameworks */ = {
isa = PBXGroup;
children = (
1375976A1D2BF306000CB88F /* Security.framework */,
1366053E1D23D6C700D497A0 /* Cocoa.framework */,
1366053C1D23D6B800D497A0 /* AppKit.framework */,
1366053A1D23D6AD00D497A0 /* Foundation.framework */,
Expand All @@ -73,6 +95,8 @@
isa = PBXGroup;
children = (
13CAFC281D2272B000E57ED4 /* corectl */,
1375975A1D2BA78E000CB88F /* bin */,
1375975E1D2BA816000CB88F /* get_go_binaries */,
136605351D23CC9A00D497A0 /* scripts */,
136605401D23D6F600D497A0 /* Frameworks */,
13CAFC271D2272B000E57ED4 /* Products */,
Expand All @@ -91,6 +115,7 @@
isa = PBXGroup;
children = (
13CAFC291D2272B000E57ED4 /* AppDelegate.swift */,
1375976C1D2BF361000CB88F /* Keychain.swift */,
13CAFC2B1D2272B000E57ED4 /* Assets.xcassets */,
13CAFC2D1D2272B000E57ED4 /* MainMenu.xib */,
13CAFC301D2272B000E57ED4 /* Info.plist */,
Expand Down Expand Up @@ -157,12 +182,18 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
137597631D2BC9CF000CB88F /* update_corectl_blobs.command in Resources */,
1375975F1D2BA816000CB88F /* get_go_binaries in Resources */,
136605441D23E85800D497A0 /* fetch_latest_iso_stable.command in Resources */,
13CAFC2C1D2272B000E57ED4 /* Assets.xcassets in Resources */,
13CAFC2F1D2272B000E57ED4 /* MainMenu.xib in Resources */,
136605391D23CCB200D497A0 /* functions.sh in Resources */,
137597651D2BD5A6000CB88F /* copy_corectl_blobs.command in Resources */,
1375975B1D2BA78E000CB88F /* bin in Resources */,
136605381D23CCB200D497A0 /* fetch_latest_iso_alpha.command in Resources */,
137597671D2BE71C000CB88F /* sudo_password.command in Resources */,
136605431D23E85800D497A0 /* fetch_latest_iso_beta.command in Resources */,
1375976F1D2C05AA000CB88F /* start_corectld.command in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -174,6 +205,7 @@
buildActionMask = 2147483647;
files = (
13CAFC2A1D2272B000E57ED4 /* AppDelegate.swift in Sources */,
1375976D1D2BF361000CB88F /* Keychain.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -281,7 +313,7 @@
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = corectl/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = linxos.net.corectl;
PRODUCT_BUNDLE_IDENTIFIER = linxos.net.corectl.app;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -294,7 +326,7 @@
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = corectl/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = linxos.net.corectl;
PRODUCT_BUNDLE_IDENTIFIER = linxos.net.corectl.app;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand Down
Binary file not shown.
146 changes: 137 additions & 9 deletions src/corectl/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Cocoa
import Foundation
import Security

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
Expand All @@ -23,8 +24,19 @@ class AppDelegate: NSObject, NSApplicationDelegate {
statusItem.image = icon
statusItem.menu = statusMenu

// check if App runs from DMG
check_for_dmg()

check_sudo_password()

// check if corectl blobs are in place
check_for_corectl_blobs()

// enable launch at login
addToLoginItems()
ServerStart()

// start corectld server
ServerStartShell()

// create menu programmaticly
// let Quit : NSMenuItem = NSMenuItem(title: "Quit", action: #selector(AppDelegate.Quit(_:)), keyEquivalent: "")
Expand All @@ -33,7 +45,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}


// start corectld server
func ServerStart() {
// send stop to corectld just in case it was left running
ServerStop()

let menuItem : NSStatusItem = statusItem

// start corectld server
Expand All @@ -47,6 +63,24 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}


func ServerStartShell() {
// send stop to corectld just in case it was left running
ServerStop()

let menuItem : NSStatusItem = statusItem

// start corectld server
let task: NSTask = NSTask()
let launchPath = NSBundle.mainBundle().resourcePath! + "/start_corectld.command"
task.launchPath = launchPath
task.launch()
//
menuItem.menu?.itemWithTag(1)?.title = "Server is running"
menuItem.menu?.itemWithTag(1)?.state = NSOnState
}


// stop corectld server
func ServerStop() {
let menuItem : NSStatusItem = statusItem

Expand All @@ -66,6 +100,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}


// restart corectld server
@IBAction func Restart(sender: NSMenuItem) {
let menuItem : NSStatusItem = statusItem
menuItem.menu?.itemWithTag(1)?.title = "Server is stopping"
Expand All @@ -78,20 +113,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {

menuItem.menu?.itemWithTag(1)?.title = "Server is starting"
// start corectld server
ServerStart()
ServerStartShell()
}



// check and download updates for corectl
@IBAction func checkForUpdates(sender: NSMenuItem) {
// send a notification on to the screen
let notification: NSUserNotification = NSUserNotification()
notification.title = "Corectl"
notification.informativeText = "corectl binaries will be updated"
NSUserNotificationCenter.defaultUserNotificationCenter().deliverNotification(notification)

// run the script
runTerminal(NSBundle.mainBundle().resourcePath! + "/update_corectl_blobs.command")
}


// fetch latest ISOs

@IBAction func fetchLatestISOAlpha(sender: NSMenuItem) {

// send a notification on to the screen
let notification: NSUserNotification = NSUserNotification()
notification.title = "Corectl"
Expand All @@ -100,10 +140,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {

// run the script
runTerminal(NSBundle.mainBundle().resourcePath! + "/fetch_latest_iso_alpha.command")

}


@IBAction func fetchLatestISOBeta(sender: NSMenuItem) {
// send a notification on to the screen
let notification: NSUserNotification = NSUserNotification()
Expand All @@ -115,7 +153,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
runTerminal(NSBundle.mainBundle().resourcePath! + "/fetch_latest_iso_beta.command")
}


@IBAction func fetchLatestISOStable(sender: NSMenuItem) {
// send a notification on to the screen
let notification: NSUserNotification = NSUserNotification()
Expand All @@ -127,8 +164,18 @@ class AppDelegate: NSObject, NSApplicationDelegate {
runTerminal(NSBundle.mainBundle().resourcePath! + "/fetch_latest_iso_stable.command")
}
//


// About App
@IBAction func About(sender: NSMenuItem) {
let version = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString")as? String
let mText: String = "Corectl for macOS v" + version!
let infoText: String = "It is a simple wrapper around the corectld server, which allows to have a control via the Status Bar App !!!"
displayWithMessage(mText, infoText: infoText)
}


// Quit App
@IBAction func Quit(sender: NSMenuItem) {
// send a notification on to the screen
let notification: NSUserNotification = NSUserNotification()
Expand All @@ -145,15 +192,93 @@ class AppDelegate: NSObject, NSApplicationDelegate {

// helping functions

// check sudo password
func check_sudo_password() {
let app_keychain_value = Keychain.get("coreosctl-app")

if ( app_keychain_value == nil )
{
print("there is no such keychain value ...")
// run the script
runTerminal(NSBundle.mainBundle().resourcePath! + "/sudo_password.command")
}
}


// check if app runs from dmg
func check_for_dmg() {
// get the App's main bundle path
let resoucesPathFromApp = NSBundle.mainBundle().resourcePath!
NSLog("applicationDirectory: '%@'", resoucesPathFromApp)
//
let dmgPath: String = "/Volumes/corectl/corectl.app/Contents/Resources"
NSLog("DMG resource path: '%@'", dmgPath)
// check resourcePath and exit the App if it runs from the dmg
if resoucesPathFromApp.isEqual(dmgPath) {
// show alert message
let mText: String = "\("Corectl App cannot be started from DMG !!!")"
let infoText: String = "Please copy App to your Applications folder ..."
displayWithMessage(mText, infoText: infoText)
// exiting App
NSApplication.sharedApplication().terminate(self)
}
}


// check if corectl blobs exist
func check_for_corectl_blobs() {
let resoucesPathFromApp = NSBundle.mainBundle().resourcePath!
let bin_folder = resoucesPathFromApp + "/bin"

print(bin_folder)

let filePath1 = "/usr/local/sbin/corectl"
if (NSFileManager.defaultManager().fileExistsAtPath(filePath1))
{
print("corectl available");
}
else
{
print("corectl not available");
runScript("copy_corectl_blobs.command", arguments: bin_folder )
}

let filePath2 = "/usr/local/sbin/corectld"
if (NSFileManager.defaultManager().fileExistsAtPath(filePath2))
{
print("corectld available");
}
else
{
print("corectld not available");
runScript("copy_corectl_blobs.command", arguments: bin_folder )
}

let filePath3 = "/usr/local/sbin/corectld.runner"
if (NSFileManager.defaultManager().fileExistsAtPath(filePath3))
{
print("corectld.runner available");
}
else
{
print("corectld.runner not available");
runScript("copy_corectl_blobs.command", arguments: bin_folder )
}
}


// run script
func runScript(scriptName: String, arguments: String) {
let task: NSTask = NSTask()
task.launchPath = "\(NSBundle.mainBundle().pathForResource(scriptName, ofType: "command")!)"
let launchPath = NSBundle.mainBundle().resourcePath! + "/" + scriptName
task.launchPath = launchPath
task.arguments = [arguments]
task.launch()
task.waitUntilExit()
}


// terminal/iterm app
func runTerminal(arguments: String) {
let fileManager = NSFileManager.defaultManager()
// Check if file exists, given its path
Expand All @@ -167,11 +292,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}


// run an app
func runApp(appName: String, arguments: String) {
// lunch an external App
NSWorkspace.sharedWorkspace().openFile(arguments, withApplication: appName)
}


// notifications
func userNotificationCenter(center: NSUserNotificationCenter, shouldPresentNotification notification: NSUserNotification) -> Bool {
return true
Expand Down Expand Up @@ -202,5 +329,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
)
}


}

Loading

0 comments on commit 53d315e

Please sign in to comment.