From e226e7410010b1d0f385568e14c2be981017ce12 Mon Sep 17 00:00:00 2001 From: Daniel Goldberg Date: Mon, 3 Feb 2020 12:18:02 +0200 Subject: [PATCH] No more need for run_script.bat. Cleaned up README.md visually --- deployment_scripts/README.md | 12 ++++++++---- deployment_scripts/deploy_windows.ps1 | 19 ++++++++++++++++--- deployment_scripts/run_script.bat | 8 -------- 3 files changed, 24 insertions(+), 15 deletions(-) delete mode 100644 deployment_scripts/run_script.bat diff --git a/deployment_scripts/README.md b/deployment_scripts/README.md index 750979a4d..812337eba 100644 --- a/deployment_scripts/README.md +++ b/deployment_scripts/README.md @@ -3,13 +3,17 @@ Before running the script you must have git installed.
`Invoke-WebRequest https://raw.githubusercontent.com/guardicore/monkey/develop/deployment_scripts/deploy_windows.ps1 -OutFile deploy_windows.ps1` + Then execute the resulting script with your shell. First argument is an empty directory (script can create one) and second is branch you want to clone. + Example usages:
-`./run_script.bat` (Sets up monkey in current directory under .\infection_monkey)
-`./run_script.bat "C:\test"` (Sets up monkey in C:\test)
-`powershell -ExecutionPolicy ByPass -Command ". .\deploy_windows.ps1; Deploy-Windows -monkey_home C:\test"` (Same as above)
-`./run_script.bat "" "master"` (Sets up master branch instead of develop in current dir) +`.\deploy_windows.ps1` (Sets up monkey in current directory under .\infection_monkey)
+`.\deploy_windows.ps1 -monkey_home "C:\test"` (Sets up monkey in C:\test)
+`.\deploy_windows.ps1 -branch "master"` (Sets up master branch instead of develop in current dir) + +If you run into Execution Policy warnings, you can disable them by prefixing the following snippet +`powershell -ExecutionPolicy ByPass -Command "[original command here]"` Don't forget to add python to PATH or do so while installing it via this script.
diff --git a/deployment_scripts/deploy_windows.ps1 b/deployment_scripts/deploy_windows.ps1 index 987a9b70b..9272533fd 100644 --- a/deployment_scripts/deploy_windows.ps1 +++ b/deployment_scripts/deploy_windows.ps1 @@ -1,18 +1,28 @@ +param( + [Parameter(Mandatory = $false, Position = 0)] + [String] $monkey_home = (Get-Item -Path ".\").FullName, + + [Parameter(Mandatory = $false, Position = 1)] + [System.String] + $branch = "develop" +) function Deploy-Windows([String] $monkey_home = (Get-Item -Path ".\").FullName, [String] $branch = "develop") { - + Write-Output "Downloading to $monkey_home" + Write-Output "Branch $branch" # Set variables for script execution [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $webClient = New-Object System.Net.WebClient # Import the config variables + $config_filename = New-TemporaryFile $config_filename = "config.ps1" $config_url = "https://raw.githubusercontent.com/guardicore/monkey/" + $branch + "/deployment_scripts/config.ps1" $webClient.DownloadFile($config_url, $config_filename) . ./config.ps1 "Config variables from config.ps1 imported" - Remove-Item $config_filename + #Remove-Item $config_filename # If we want monkey in current dir we need to create an empty folder for source files @@ -35,7 +45,9 @@ function Deploy-Windows([String] $monkey_home = (Get-Item -Path ".\").FullName, } # Download the monkey - $output = cmd.exe /c "git clone --single-branch -b $branch $MONKEY_GIT_URL $monkey_home 2>&1" + $command = "git clone --single-branch -b $branch $MONKEY_GIT_URL $monkey_home 2>&1" + Write-Output $command + $output = cmd.exe /c $command $binDir = (Join-Path -Path $monkey_home -ChildPath $MONKEY_ISLAND_DIR | Join-Path -ChildPath "\bin") if ($output -like "*already exists and is not an empty directory.*") { @@ -242,3 +254,4 @@ function Deploy-Windows([String] $monkey_home = (Get-Item -Path ".\").FullName, "Script finished" } +Deploy-Windows -monkey_home $monkey_home -branch $branch \ No newline at end of file diff --git a/deployment_scripts/run_script.bat b/deployment_scripts/run_script.bat deleted file mode 100644 index 3dcd62760..000000000 --- a/deployment_scripts/run_script.bat +++ /dev/null @@ -1,8 +0,0 @@ -SET command=. .\deploy_windows.ps1; Deploy-Windows -if NOT "%~1" == "" ( - SET "command=%command% -monkey_home %~1" -) -if NOT "%~2" == "" ( - SET "command=%command% -branch %~2" -) -powershell -ExecutionPolicy ByPass -Command %command% \ No newline at end of file