diff --git a/src/bin/corectl b/src/bin/corectl new file mode 100755 index 0000000..3e1cd79 Binary files /dev/null and b/src/bin/corectl differ diff --git a/src/bin/corectld b/src/bin/corectld new file mode 100755 index 0000000..598d57e Binary files /dev/null and b/src/bin/corectld differ diff --git a/src/bin/corectld.runner b/src/bin/corectld.runner new file mode 100755 index 0000000..39cfc4f Binary files /dev/null and b/src/bin/corectld.runner differ diff --git a/src/copy_corectl_blobs.command b/src/copy_corectl_blobs.command new file mode 100755 index 0000000..e783ed6 --- /dev/null +++ b/src/copy_corectl_blobs.command @@ -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 diff --git a/src/corectl.xcodeproj/project.pbxproj b/src/corectl.xcodeproj/project.pbxproj index 9ee0c7e..a8e3628 100644 --- a/src/corectl.xcodeproj/project.pbxproj +++ b/src/corectl.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 = ""; }; 136605421D23E85800D497A0 /* fetch_latest_iso_stable.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = fetch_latest_iso_stable.command; sourceTree = ""; }; + 1375975A1D2BA78E000CB88F /* bin */ = {isa = PBXFileReference; lastKnownFileType = folder; path = bin; sourceTree = ""; }; + 1375975E1D2BA816000CB88F /* get_go_binaries */ = {isa = PBXFileReference; lastKnownFileType = folder; path = get_go_binaries; sourceTree = ""; }; + 137597621D2BC9CF000CB88F /* update_corectl_blobs.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = update_corectl_blobs.command; sourceTree = ""; }; + 137597641D2BD5A5000CB88F /* copy_corectl_blobs.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = copy_corectl_blobs.command; sourceTree = ""; }; + 137597661D2BE71C000CB88F /* sudo_password.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = sudo_password.command; sourceTree = ""; }; + 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 = ""; }; + 1375976E1D2C05AA000CB88F /* start_corectld.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = start_corectld.command; sourceTree = ""; }; 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 = ""; }; 13CAFC2B1D2272B000E57ED4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -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 */, @@ -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; @@ -62,6 +83,7 @@ 136605401D23D6F600D497A0 /* Frameworks */ = { isa = PBXGroup; children = ( + 1375976A1D2BF306000CB88F /* Security.framework */, 1366053E1D23D6C700D497A0 /* Cocoa.framework */, 1366053C1D23D6B800D497A0 /* AppKit.framework */, 1366053A1D23D6AD00D497A0 /* Foundation.framework */, @@ -73,6 +95,8 @@ isa = PBXGroup; children = ( 13CAFC281D2272B000E57ED4 /* corectl */, + 1375975A1D2BA78E000CB88F /* bin */, + 1375975E1D2BA816000CB88F /* get_go_binaries */, 136605351D23CC9A00D497A0 /* scripts */, 136605401D23D6F600D497A0 /* Frameworks */, 13CAFC271D2272B000E57ED4 /* Products */, @@ -91,6 +115,7 @@ isa = PBXGroup; children = ( 13CAFC291D2272B000E57ED4 /* AppDelegate.swift */, + 1375976C1D2BF361000CB88F /* Keychain.swift */, 13CAFC2B1D2272B000E57ED4 /* Assets.xcassets */, 13CAFC2D1D2272B000E57ED4 /* MainMenu.xib */, 13CAFC301D2272B000E57ED4 /* Info.plist */, @@ -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; }; @@ -174,6 +205,7 @@ buildActionMask = 2147483647; files = ( 13CAFC2A1D2272B000E57ED4 /* AppDelegate.swift in Sources */, + 1375976D1D2BF361000CB88F /* Keychain.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -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; @@ -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; diff --git a/src/corectl.xcodeproj/project.xcworkspace/xcuserdata/rmocevicius.xcuserdatad/UserInterfaceState.xcuserstate b/src/corectl.xcodeproj/project.xcworkspace/xcuserdata/rmocevicius.xcuserdatad/UserInterfaceState.xcuserstate index 47470ad..2f4b0df 100644 Binary files a/src/corectl.xcodeproj/project.xcworkspace/xcuserdata/rmocevicius.xcuserdatad/UserInterfaceState.xcuserstate and b/src/corectl.xcodeproj/project.xcworkspace/xcuserdata/rmocevicius.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/src/corectl/AppDelegate.swift b/src/corectl/AppDelegate.swift index 9c1b415..1428c83 100644 --- a/src/corectl/AppDelegate.swift +++ b/src/corectl/AppDelegate.swift @@ -8,6 +8,7 @@ import Cocoa import Foundation +import Security @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { @@ -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: "") @@ -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 @@ -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 @@ -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" @@ -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" @@ -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() @@ -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() @@ -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() @@ -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 @@ -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 @@ -202,5 +329,6 @@ class AppDelegate: NSObject, NSApplicationDelegate { ) } + } diff --git a/src/corectl/Base.lproj/MainMenu.xib b/src/corectl/Base.lproj/MainMenu.xib index 327da6a..64e5e9a 100644 --- a/src/corectl/Base.lproj/MainMenu.xib +++ b/src/corectl/Base.lproj/MainMenu.xib @@ -719,6 +719,13 @@ + + + + + + + @@ -726,7 +733,7 @@ - + diff --git a/src/corectl/Info.plist b/src/corectl/Info.plist index 2ffa60d..468c776 100644 --- a/src/corectl/Info.plist +++ b/src/corectl/Info.plist @@ -17,11 +17,13 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.0.7 + 0.0.8 CFBundleSignature ???? CFBundleVersion - 29 + 55 + LSApplicationCategoryType + public.app-category.utilities LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) LSUIElement diff --git a/src/corectl/Keychain.swift b/src/corectl/Keychain.swift new file mode 100644 index 0000000..f0c459d --- /dev/null +++ b/src/corectl/Keychain.swift @@ -0,0 +1,86 @@ +// +// Keychain.swift +// corectl +// +// Created by Rimantas Mocevicius on 05/07/2016. +// Copyright © 2016 The New Normal. All rights reserved. +// copied from https://swift.unicorn.tv/articles/dead-simple-keychain-access +// + +import Foundation +import Security + +public class Keychain +{ + public class func set(key: String, value: String) -> Bool + { + if let data = value.dataUsingEncoding(NSUTF8StringEncoding) + { + return set(key, value: data) + } + + return false + } + + public class func set(key: String, value: NSData) -> Bool + { + let query = [ + (kSecClass as String) : kSecClassGenericPassword, + (kSecAttrAccount as String) : key, + (kSecValueData as String) : value + ] + + SecItemDelete(query as CFDictionaryRef) + + return SecItemAdd(query as CFDictionaryRef, nil) == noErr + } + + public class func get(key: String) -> NSString? + { + if let data = getData(key) + { + return NSString(data: data, encoding: NSUTF8StringEncoding) + } + + return nil + } + + public class func getData(key: String) -> NSData? + { + let query = [ + (kSecClass as String) : kSecClassGenericPassword, + (kSecAttrAccount as String) : key, + (kSecReturnData as String) : kCFBooleanTrue, + (kSecMatchLimit as String) : kSecMatchLimitOne + ] + + var dataTypeRef: AnyObject? + let status = SecItemCopyMatching(query, &dataTypeRef) + + if status == noErr && dataTypeRef != nil + { + return dataTypeRef as? NSData + } + + return nil + } + + public class func delete(key: String) -> Bool + { + let query = [ + (kSecClass as String) : kSecClassGenericPassword, + (kSecAttrAccount as String) : key + ] + + return SecItemDelete(query as CFDictionaryRef) == noErr + } + + public class func clear() -> Bool + { + let query = [ + (kSecClass as String): kSecClassGenericPassword + ] + + return SecItemDelete(query as CFDictionaryRef) == noErr + } +} diff --git a/src/functions.sh b/src/functions.sh index 4d9a1e4..fa92725 100755 --- a/src/functions.sh +++ b/src/functions.sh @@ -1,16 +1,96 @@ #!/bin/bash # shared functions library - DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) - function pause(){ read -p "$*" } +function save_password(){ +# save user's password to Keychain +echo " " +echo "Your Mac user's password will be saved in to 'Keychain' " +echo "and later one used for 'sudo' command to start 'corectld' server !!!" +echo " " +echo "Please type your Mac user's password followed by [ENTER]:" +read -s -r my_password +passwd_ok=0 + +# check if sudo password is correct +while [ ! $passwd_ok = 1 ] +do + # reset sudo + sudo -k + # check sudo + printf '%s\n' "$my_password" | sudo -Sv > /dev/null 2>&1 + CAN_I_RUN_SUDO=$(sudo -n uptime 2>&1|grep "load"|wc -l) + if [ ${CAN_I_RUN_SUDO} -gt 0 ] + then + echo "The sudo password is fine !!!" + echo " " + passwd_ok=1 + else + echo " " + echo "The password you entered does not match your Mac user password !!!" + echo "Please type your Mac user's password followed by [ENTER]:" + read -s -r my_password + fi +done + +security add-generic-password -a coreosctl-app -s coreosctl-app -w $my_password -U + +} + + +function download_corectl_blobs(){ + +# get installed version +INSTALLED_VERSION=v$(/usr/local/sbin/corectld version | grep "Version:" | head -1 | awk '{print $2}' | tr -d '\r') +# get remote version +CORECTL_VERSION=$(curl -Ss https://api.github.com/repos/TheNewNormal/corectl/releases | grep "tag_name" | awk '{print $2}' | sed -e 's/"\(.*\)"./\1/' | head -1) +MATCH=$(echo "${INSTALLED_VERSION}" | grep -c "${CORECTL_VERSION}") + +if [ $MATCH -eq 0 ]; then +# the version is different + mkdir -p ~/tmp/corectl > /dev/null 2>&1 + cd ~/tmp/corectl + + # download latest version of corectl for macOS + echo "Downloading corectl $CORECTL_VERSION for macOS" + curl -L -o corectl.tar.gz https://github.com/TheNewNormal/corectl/releases/download/$CORECTL_VERSION/corectl-$CORECTL_VERSION-osx-amd64.tar.gz + tar xzvf corectl.tar.gz > /dev/null 2>&1 + rm -f corectl.tar.gz + chmod +x * + + # 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 * /usr/local/sbin + + # + cd ~/ + rm -fr ~/tmp/corectl > /dev/null 2>&1 + + # + echo "Download has finished !!!" + echo "You need to restart `corectld` server, but Halt all your VMs first !!! " +else + echo " " + echo "corectl is up to date ..." + echo " " +fi + +pause 'Press [Enter] key to continue...' + +} diff --git a/src/get_go_binaries/compile_from_source_corectl.sh b/src/get_go_binaries/compile_from_source_corectl.sh new file mode 100755 index 0000000..5b14e62 --- /dev/null +++ b/src/get_go_binaries/compile_from_source_corectl.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# compile corectl and corectld binaries + +current_folder=$(pwd) + +# clean up go folders +rm -rf $GOPATH/src/github.com/TheNewNormal/corectl +# +mkdir -p $GOPATH/src/github.com/TheNewNormal + +# +cd $GOPATH/src/github.com/TheNewNormal +# +git clone https://github.com/TheNewNormal/corectl +cd corectl +git checkout golang + +# +opam init --yes +opam pin add qcow-format git://github.com/mirage/ocaml-qcow#master --yes +opam install --yes uri qcow-format ocamlfind +eval `opam config env` + +# build +make hyperkit +make + +# +cd $current_folder +cp -f $GOPATH/src/github.com/TheNewNormal/corectl/bin/corectld.runner ../bin +cp -f $GOPATH/src/github.com/TheNewNormal/corectl/bin/corectld ../bin +cp -f $GOPATH/src/github.com/TheNewNormal/corectl/bin/corectl ../bin diff --git a/src/get_go_binaries/get_corectl.sh b/src/get_go_binaries/get_corectl.sh new file mode 100755 index 0000000..d6f6473 --- /dev/null +++ b/src/get_go_binaries/get_corectl.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# download corectl and corectld binaries + +# get remote version +CORECTL_VERSION=$(curl -Ss https://api.github.com/repos/TheNewNormal/corectl/releases | grep "tag_name" | awk '{print $2}' | sed -e 's/"\(.*\)"./\1/' | head -1) + +# download latest version of corectl for macOS +echo "Downloading corectl $CORECTL_VERSION for macOS" +curl -L -o corectl.tar.gz https://github.com/TheNewNormal/corectl/releases/download/$CORECTL_VERSION/corectl-$CORECTL_VERSION-osx-amd64.tar.gz +tar xzvf corectl.tar.gz > /dev/null 2>&1 +rm -f corectl.tar.gz +chmod +x * + +# copy blobs +echo "Move files to ../bin" +# +mv -f corectld.runner ../bin +mv -f corectld ../bin +mv -f corectl ../bin + + diff --git a/src/nohup.out b/src/nohup.out new file mode 100644 index 0000000..7086a5d --- /dev/null +++ b/src/nohup.out @@ -0,0 +1,6 @@ +---> checking nfs host settings +---> '/Users/rimantasmocevicius' now available to VMs' network via nfs +---> registering locally available images +---> server starting... +---> Sky must be falling. Shutting down... +---> gone! diff --git a/src/start_corectld.command b/src/start_corectld.command new file mode 100755 index 0000000..aab4f7a --- /dev/null +++ b/src/start_corectld.command @@ -0,0 +1,16 @@ +#!/bin/bash +# start corectld + +# +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source "${DIR}"/functions.sh + +# 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 + +# start corectld +sudo nohup /usr/local/sbin/corectld start --user $(whoami) diff --git a/src/sudo_password.command b/src/sudo_password.command new file mode 100755 index 0000000..a18a3a2 --- /dev/null +++ b/src/sudo_password.command @@ -0,0 +1,13 @@ +#!/bin/bash +# + +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source "${DIR}"/functions.sh + +# check for saved sudo password +my_password=$(security 2>&1 > /dev/null find-generic-password -wa coreosctl-app) + +if [[ "${my_password}" == *"could not be found"* ]] +then + save_password +fi diff --git a/src/update_corectl_blobs.command b/src/update_corectl_blobs.command new file mode 100755 index 0000000..70f2a73 --- /dev/null +++ b/src/update_corectl_blobs.command @@ -0,0 +1,14 @@ +#!/bin/bash + +# update macOS clients +# + +# +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source "${DIR}"/functions.sh + + +# check and download latest version of corectl blobs +download_corectl_blobs +# +