forked from OctopusDeploy/OctopusDSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-virtualbox.sh
executable file
·87 lines (74 loc) · 2.5 KB
/
build-virtualbox.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
function check_plugin_installed() {
param=$1
vagrant plugin list | grep -i "$param " > /dev/null
if [ $? == 0 ]; then
echo "Vagrant plugin $param exists - good."
else
echo "Vagrant plugin $param not installed."
vagrant plugin install $param
fi
}
function check_env_var() {
param=$1
if [ -z "${!param}" ]; then
echo "Please set the $param environment variable"
exit 1
fi
}
#not required when running locally in VirtualBox?
#check_env_var AWS_ACCESS_KEY_ID
#check_env_var AWS_SECRET_ACCESS_KEY
#check_env_var AWS_SUBNET_ID
#check_env_var AWS_SECURITY_GROUP_ID
which vagrant > /dev/null
if [ $? != 0 ]; then
echo "Please install vagrant from vagrantup.com."
exit 1
fi
echo "Vagrant installed - good."
which VBoxManage > /dev/null
if [ $? != 0 ]; then
echo "Please install VirtualBox from virtualbox.org."
exit 1
fi
echo "VirtualBox installed - good."
POWERSHELL_INSTALLED=0
which powershell > /dev/null
if [ $? != 0 ]; then
POWERSHELL_INSTALLED=1
echo "Powershell does not appear to be installed. To install, see https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md."
else
echo "Powershell installed - good."
fi
#not required when running locally in VirtualBox?
#check_plugin_installed "vagrant-aws"
#check_plugin_installed "vagrant-aws-winrm"
check_plugin_installed "vagrant-dsc"
check_plugin_installed "vagrant-winrm"
check_plugin_installed "vagrant-winrm-syncedfolders"
if [ $POWERSHELL_INSTALLED == 0 ]; then
echo "Running PSScriptAnalyzer"
read -r -d '' SCRIPT << EOM
Import-Module PSScriptAnalyzer
\$excludedRules = @('PSUseShouldProcessForStateChangingFunctions', 'PSAvoidUsingPlainTextForPassword', 'PSAvoidUsingUserNameAndPassWordParams', 'PSAvoidUsingConvertToSecureStringWithPlainText')
\$results = Invoke-ScriptAnalyzer ./OctopusDSC/DSCResources -recurse -exclude \$excludedRules
write-output \$results
write-output "PSScriptAnalyzer found \$(\$results.length) issues"
exit \$results.length
EOM
powershell -command "$SCRIPT"
if [ $? != 0 ]; then
echo "Aborting as PSScriptAnalyzer found issues."
exit 1
fi
echo "Running Pester Tests"
powershell -command "Invoke-Pester -OutputFile PesterTestResults.xml -OutputFormat NUnitXml -EnableExit"
if [ $? != 0 ]; then
echo "Pester tests failed."
exit 1
fi
fi
echo "Running 'vagrant up --provider virtualbox'"
time vagrant up --provider virtualbox # --debug &> vagrant.log
echo "Dont forget to run 'vagrant destroy -f' when you have finished"