GhostCoreSetup is a console application that installs Ghost-Core applications
such as Ghost-Gateway -Agent or -Monitor.
Internet access is needed to be able to Sign-In to grant access to Ghost Web-Api's. 
Machines that have no internet access need to copy an offline package
bundle to local machine and use that to install packages from.
GhostCoreSetup must be run with Administrator/root privileges as it will 
create/modify Windows Services or Linux Daemons.

Prereqs:
	.NET 6.0 SDK or ASP.NET Core Runtime 6.0 Hosting Bundle
	https://www.microsoft.com/net/download/Windows/run


Ghost application services startup methods:
===========================================================
Method 1 usage:
	dotnet.exe GhostCoreSetup.dll -jf:"<path>"
	dotnet.exe GhostCoreSetup.dll -j:"<json>"

Method 2 usage:
	dotnet.exe GhostCoreSetup.dll -g -c:<id> -p:<url> [optional args]
	dotnet.exe GhostCoreSetup.dll -a -c:<id> -p:<url> [optional args]
	dotnet.exe GhostCoreSetup.dll -m -c:<id> -p:<url> [optional args]
	dotnet.exe GhostCoreSetup.dll -z:"<path>" -c:<id> -p:<url> [optional args]

Mandatory Arguments:
	Method 1: (Settings in json file, Only one should be specified)
		-jf:"<path>"   Full path to json settings file.
		-j:"<json>"    Settings as a Json string.

	Method 2: (Settings as arguments, Only one should be specified)
		-g             Installs a GhostGateway.
		-a             Installs a GhostAgent.
		-m             Installs a GhostMonitor.
		-z:"<path>"    Full path to a bundle zip-file.

	Additional Mandatory arguments:
		-c:<id>          Customer id.
		-p:<url>         Parent Gateway Url.

If any mandatory argument is missing a "Step-By-Step" wizard 
will be invoked to complete mandatory arguments. Missing optional
arguments will have default values.


Optional arguments (any):
	-alias:<name>     Set an alternative name.
	-d:<descr>        Set description.
	-cid:<id>         Client id used for authentication.
	-cs:<secret>      Client secret used for authentication.
	-aba:<value>      Allow authentication via browser login.
	-pi:<id>          Parent Gateway Id. (only available for -g,-a and -m)
	-port:<port>      Specify only if the internal Web-Host port should be overrided.
	-scheme:<scheme>  Specify only if the internal Web-Host scheme should be overrided.
	-w:<value>        True or False to use ProcessWatcher.
	-certPath:<path>  Full path to a certificate.
	-certPwd:<pwd>    Password to specified certificate.
	-st:<value>       Service startup type.
	-usr:<name>       Service logon user.
	-pwd:<pwd>        Password for logon user.
	-f:<feed>         NuGet feed to use.
	-ap:<paths>       Additional probing paths to search for local packages.
	-au:<value>       Sets if auto-update is allowed.
	-aus:<value>      Sets if auto-update is allowed at service startup.
	-pr:<value>       Sets if pre-releases can be installed
	
	-swd:<days>       Service-Window will run on days.
	-swt:<time>       Service-Window will start at time.
	-frd:<days>       Force a restart at Service-Window on days.

	-pu:<usage>       Proxy usage.
	-udc:<value>      Default credentials. True or False.
	-bol:<value>      Bypass proxy on local. True or False.
	-pa:<uri>         Proxy address.
	-pusr:<name>      Proxy username.
	-ppwd:<pwd>       Proxy password.
	-eu:<url>         Environment Url
	-eau:<url>        Environment API Url (Deprecated, use '-eu:<url>' instead)
	-fr:<value>       Force Reinstall of any existing packages.
	-v:<version>      Version to install
	-sv:<value>       Select version to install from a list
	-ht:<value>       Http-Timeout in seconds

Optional arguments (Agent):
	-cmag:<value>     Create Agent-Group if it's missing.
	-aag:<id>         Add Agent to Agent-Group with unique-id.
	-aagn:<name>      Agent-Group name if it's being created.
	-aagm:<mode>      Agent-Group mode if it's being created.
	-sr:<value>       True or False to allow Roaming Agents and Links.
	-lsa:<value>      Run scheduler in Agent instead of in SourceProcessor.
	-fsec:<value>     Force links scheduled by seconds to be triggered in SourceProcessor.
	-fmin:<value>     Force links scheduled by minutes to be triggered in SourceProcessor.
	-fhr:<value>      Force links scheduled by hours to be triggered in SourceProcessor.

Ghost Account Creation:
===========================================================

Special startup for creating a new account:
	dotnet.exe GhostCoreSetup.dll -ca -an:"<accountName>"

If account was successfully created GhostCoreSetup will close.
Re-run GhostCoreSetup and login again to get new claims to created account.
(You should close all web-browsers to get a new login page or it will be cached)



Json Settings and Argument descriptions:
========================================================================================

Account creation:
===========================
"IsCreateAccount": true|false
-ca
	If set to true and a NewAccountName is specified a new account will be created.

"NewAccountName": "<accountName"
-an
	New account name to create.



Mandatory to run unattended:
===========================

"IsGateway": true|false
-g
-gateway
	If specified a GhostGateway will be installed. Requires an active internet connection.

"IsAgent": true|false
-a
-agent
	If specified a GhostAgent will be installed. Requires an active internet connection.

"IsMonitor": true|false
-m
-monitor
	If specified a GhostMonitor will be installed. Requires an active internet connection.

"ZipPackagePath": "<path>"
-z:"<path>"
-zipPath:"<path>"
	This is the full path to the offline bundle zip file to unpack. 
	Do not specify -a or -g when using -z. The zip bundle will decide which will be installed.

"ClientId": "<id>"
-cid:<id>
-clientId:<uid>
	Client-id used for authentication. Should be used for unattended installations or where no web-browser can be displayed.

"ClientSecret": "<secret>"
-cs:<secret>
-clientSecret:<secret>
	Client secret used for authentication. Should be used for unattended installations or where no web-browser can be displayed.

"AllowBrowserAuth": "true|false"
-aba:<value>
-allowBrowserAuth:<value>
	If authentication is allowed via a browser login.

"CustomerId": "<uid>"
-c:<uid>
-customerId:<uid>
	The unique customer-id that the Gateway or agent will be connected to.

"ParentGatewayId": "<uid>"
-pi:<uid>
-parentId:<uid>
	Specifies the "Parent Gateway id" that is used to communicate up to the central Azure Gateway and its database.
	This argument overrides the -p (parentUrl) argument.

"ParentGatewayUrl": "<url>"
-p:<url>
-parentUrl:<url>
	Specifies the "Parent Gateway url" that is used to communicate up to the central Azure Gateway and its database.
	Agents should always point to a local gateway on the local network.


Optional:
=========
"AliasName": "<name>"
-alias:<name>
-aliasName:<name>
    Set an alternative name.

"Description": "<name>"
-d:<descr>
-description:<descr>
    Set description.

"ForceReinstall": "true|false"
-fr:<name>
-forceReinstall:<name>
    Set an alternative name

"Port": <port>
-port:<port>
	Specifies which port to use.
	Default values; Gateway=44300, Agent=44400 and Monitor=44500

"Scheme": "http|https"
-scheme:http|https
	Specifies if the service should use http or https. Please note if https is used a cert and cert password is needed.
	Default value: http

"CertificatePath": "<path>"
-certPath:"<path>"
	Full path to certificate to use.
	Default value: <empty>

"CertificatePassword": "<password>"
-certPwd:<password>
	Password to specified certificate.
	Default value: <empty>

"StartupType": "Automatic|DelayedAutomatic|Manual|Disabled"
-st:Automatic|DelayedAutomatic|Manual|Disabled
-startupType:Automatic|DelayedAutomatic|Manual|Disabled
	Specifies the Windows Service startup type.
	Possible values are: 'Automatic', 'DelayedAutomatic', 'Manual' or 'Disabled'
	Default value is 'Automatic'.

"RunAsUser": "<name>"
-usr:<name>
-serviceUser:<name>
	User that the service will run as.
	User should be specified with the format as {DOMAIN}\{User}.
	This user needs to have Administrators access and be allowed to access the Parent Gateway url via http.
	If left blank Local Admin is used.
	Default value is blank.

"RunAsPassword": "<password>"
-pwd:<password>
-servicePwd:<password>
	Password for service user.
	Default value: <empty>

"UseProcessWatcher": "true|false"
-w:true|false
-useWatcher:true|false
	True or False to specify if the ProcessWatcher should be used. 
	True: Will require that service user should have WMI access to Win32_ProcessStartTrace and Win32_ProcessStopTrace.
	False: Will use a file based process monitor instead. On Linux systems this will always be set to False.
	Default value: 'True'

"AdditionalProbingPaths": "<paths>"
-ap:<paths>
-additionalPaths:<paths>
	Additional probing paths to search for local packages.
	A number of paths separated by ;
	Default is no additional paths.

"FeedName": "<name>"
-f:<name>
-feedName:<name>
	NuGet feed to use for Ghost-Core packages.
	Default value is 'ghost-core'

"AutoUpdateAllowed": "true|false"
-au:true|false
-autoUpdate:true|false
	Sets if auto-update is allowed.
	Default value: 'True'

"AllowUpdateAtServiceStart": "true|false"
-aus:true|false
-autoUpdateStartup:true|false
	Sets if auto-update is allowed at service startup.
	Default value: 'True'

"AllowPrerelease": "true|false"
-pr:true|false
-preReleases:true|false
	Sets if auto-update to a Pre-Release is allowed.
	Default value: 'True'

"ServiceWindowDays": "<days>"
-swd:<days>
-serviceWindowDays:<days>
	Service-Window will run on specified days.
	Possible values: None, All, WeekEnds or specific/combination of day(s)
		Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
	Default value: 'All'

"ServiceWindowStartTime": "<time>"
-swt:<time>
-serviceWindowStartTime:<time>
	Service-Window will start at specified time.
	Possible values: Any or a specific time in format HH:mm
	Default value: 'Any'

"ForceRestartDays": "<days>"
-frd:<days>
-forceRestartDays:<days>
	Force a restart at Service-Window on specified days.
	Possible values: None, All, WeekEnds or specific/combination of day(s)
		Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
	Default value: 'None'

"AllowDirectAgentAccessCheck": "true|false"
-adac::true|false
-allowDirectAgentAccessCheck
	Sets if direct agent access checks are permitted.
	Default value: 'True'

"DirectAgentAccessCheckRepeatInterval": "<value>"
-dacri:<value>
-directAgentAccessCheckRepeatInterval:<value>
	Sets interval in seconds on how often direct agent access checks should be triggered.
	Default value: 300

"PingRepeatInterval": "<value>"
-pri:<value>
-pingRepeatInterval:<value>
	Sets interval in seconds on how often Ping should be sent.
	Default value: 60

"SyncLinksRepeatInterval": "true|false"
-slri::true|false
-syncLinksRepeatInterval
	Sets interval in seconds on how often Links should be synched.
	Default value: 60

"ProxyUsage": "NoProxy|System|Custom"
-pu:NoProxy|System|Custom
-proxyUsage:NoProxy|System|Custom
	Specified if a web proxy should be used.
	Possible values are: 'NoProxy', 'System' or 'Custom'
	Default value is 'NoProxy'.

"UseDefaultCredentials": "true|false"
-udc:true|false
-useDefaultCredentials:true|false
	Sets whether default credentials are to be used to access a Web proxy server.
	Default value is True

"BypassOnLocal": "true|false"
-bol:true|false
-bypassOnLocal:true|false
	Specifies whether the proxy is bypassed for local resources.
	Default value is 'True'

"ProxyAddress": "<address>"
-pa:<address>
-proxyAddress:<address>
	URI that identifies the Web proxy server to use.
	Default value is blank.

"ProxyUser": "<name>"
-pusr:<name>
-proxyUser:<name>
	Specifies the user that should be used when connecting trough the proxy.
	User sould be specified with the format as {DOMAIN}\{User}.
	Default value is blank.

"ProxyPassword": "<password>"
-ppwd:<password>
-proxyPassword:<password>
	Password for proxy user.
	Default value is blank.

"EnvironmentUrl": "<url>"
-eu:<url>
-environmentUrl:<url>
	Overrides the base API url to point to a specific Environment.

"InstallVersion": "<version>"
-v:<version>
-version:<version>
	Specifies wich version to install. If not specified the latest version will be used.

"SelectVersion": "true|false"
-sv:true|false
-selectVersion:true|false
	If set to true a list of versions will be displayed to select from.
	Default value is 'False'

"HttpTimeout": <seconds>
-ht:<seconds>
-httptimeout:<seconds>
	Http-Timeout in seconds.
	Default value is 100 seconds

-cmag:<value>     Create Agent-Group if it's missing.
-aag:<id>         Add Agent to Agent-Group with unique-id.
-aagn:<name>      Agent-Group name if it's being created.
-aagm:<mode>      Agent-Group mode if it's being created.


Agent Optional:
===============
"CreateMissingAgentGroups": "true|false"
-cmag:true|false
-addAgentToAgentGroup:true|false
    Create Agent-Group if it's missing. If set to true AddAgentToAgentGroupName should also be specified (if not the group unique id will be used).
	Default value is 'false'

"AddAgentToAgentGroupName": "name"
-aagn:name
-addAgentToAgentGroupName:name
    Agent-Group name if it's being created.

"AddAgentToAgentGroupMode": Clustered|AgentFailOver|LinkFailOver
-aagm:Clustered|AgentFailOver|LinkFailOver
-addAgentToAgentGroupMode:Clustered|AgentFailOver|LinkFailOver
    Agent-Group mode if it's being created.
	Default value is 'Clustered'

"AddAgentToAgentGroup": "uid"
-aag:<uid>
-addAgentToAgentGroup:<uid>
    Agent-Group unique-id to add agent to.

"SupportsRoaming": "true|false"
-sr:true|false
-supportsRoaming:true|false
    Set to True to enable this Agent to support roaming agents and links.

"LinkSchedulerInAgent": "true|false"
-lsa:<name>
    Set to True to let the Agent handle custom Link scheduling instead of in the SourceProcessor.
	Default value is 'true'

"ForceSchedulerBySecondsInProcess": "true|false"
-fsec:<name>
    Force links scheduled by seconds to be triggered in SourceProcessor.
	Default value is 'true'

"ForceSchedulerByMinutesInProcess": "true|false"
-fmin:<name>
    Force links scheduled by minutes to be triggered in SourceProcessor.
	Default value is 'true'

"ForceSchedulerByHoursInProcess": "true|false"
-fhr:<name>
    Force links scheduled by hours to be triggered in SourceProcessor.
	Default value is 'true'


========================================================================================
====	Examples:
========================================================================================

Json Settings Examples:

Example 1: 
Install a Gateway with CustomerId=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 
prompting for authentication and missing mandatory arguments.

{
  "IsGateway": true,
  "CustomerId": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
}


Example 2: 
Install an Agent with CustomerId=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX having a 
local gateway named MYSERVER as Parent-Gateway prompting for missing mandatory arguments.

{
  "IsAgent": true,
  "CustomerId": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
  "ClientId": "MyClient",
  "ClientSecret": "super$ecretPassw0rd",
  "ParentGatewayUrl": "http://MYSERVER:44300",
}


 Complete Json Settings with default values:
========================================================================================
{
  "IsGateway": true,
  "IsAgent": false,
  "IsMonitor": false,
  "ZipPackagePath": "",
  "EnvironmentUrl": ""
  "CustomerId": "",
  "ClientId": "",
  "ClientSecret": "",
  "AllowBrowserAuth": false,
  "ForceReinstall": false,
  "Port": 44300,
  "Scheme": "http",
  "ParentGatewayId": ""
  "ParentGatewayUrl": "",
  "AutoUpdateAllowed": true,
  "AllowUpdateAtServiceStart": true,
  "AllowPrerelease": true,
  "UseProcessWatcher": true,
  "StartupType": "Automatic",
  "FeedName": "ghost-core",
  "AliasName": "",
  "LinkSchedulerInAgent": true,
  "ForceSchedulerBySecondsInProcess": true,
  "ForceSchedulerByMinutesInProcess": false,
  "ForceSchedulerByHoursInProcess": false,
  "ProxyUsage": "NoProxy",
  "UseDefaultCredentials": true,
  "BypassOnLocal": true,
  "UseSystemDefault": false,
}



Method 3 Examples:

1: Install a Gateway with CustomerId=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX and the Ghost Azure Gateway as Parent-Gateway.
	dotnet.exe GhostCoreSetup.dll -g -c:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -p:https://gwp.ghostnodes.com/

2: Install a Gateway with CustomerId=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX having a local gateway as Parent-Gateway
	dotnet.exe GhostCoreSetup.dll -g -c:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -p:http://myparentgateway.com:44300/

3: Install an Agent with CustomerId=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX and a local gateway as Parent-Gateway.
	dotnet.exe GhostCoreSetup.dll -a -c:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -p:http://myparentgateway.com:44300/

4: Install an Agent with CustomerId=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX and with Parent-Gateway with the UniqueId=YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY.
	dotnet.exe GhostCoreSetup.dll -a -c:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -pi:YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY

5: Install a Gateway from a zip-file with CustomerId=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX and the Ghost Azure Gateway as Parent-Gateway.
	dotnet.exe GhostCoreSetup.dll -z:"C:\Temp\GhostGateway-Offline-Bundle.zip" -c:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -p:https://gwp.ghostnodes.com/

6: Install a Agent from a zip-file with CustomerId=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX and a local Gateway as Parent-Gateway, also setting some startup arguments.
	dotnet.exe GhostCoreSetup.dll -z:"C:\GhostAgent-Offline-Bundle.zip" -c:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -p:http://myparentgateway.com:44300/ -st:manual -usr:MYDOMAIN\MyUser -pwd:mysecretpwd

Please note that examples 1-4 will install the latest Ghost-Core version available, 
while examples 5-6 will install the version contained in the zip-file.