forked from mitre/saf-training-lab-environment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-lab.sh
executable file
·150 lines (105 loc) · 3.98 KB
/
build-lab.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
source ./set-prettyOutputVariables.sh
if [[ ! $0 =~ .*/bash ]]
then
echo -e "\n${WARN}You did not run this script by executing${RSET} ${VERB}source $0${RSET} ${WARN}or${RSET} ${VERB}. $0${RSET} ${WARN}Please try again.${RSET}\n"
exit 1
fi
echo -e "${LINE_ASCII_CONSOLE}\n"
echo -e "${VERB}Setting up the lab environment...${RSET}"
alias lab="cd /workspaces/$(basename $GITHUB_REPOSITORY)"
echo -e "\n${HIGH}You can now issue the command ${VERB}lab${RSET} ${HIGH}to quickly get back to the working directory.${RSET}"
# By default, do not install Ruby documentation as it is not needed.
# Note: The '.gemrc' file must go in the user's home directory.
echo "gem: --no-document" > "${HOME}/.gemrc"
# Accept the Chef license so the students are not prompted when first
# starting Inspec.
export CHEF_LICENSE="accept-silent"
echo -e "${LINE_ASCII_CONSOLE}\n"
echo -e "${VERB}Installing Code extensions.${RSET}\n"
code --install-extension shopify.ruby-lsp
code --install-extension ms-azuretools.vscode-docker
code --install-extension esbenp.prettier-vscode
# This can help students see indention errors, especially in the YAML files.
code --install-extension oderwat.indent-rainbow
echo -e "${LINE_ASCII_CONSOLE}\n"
if ! command -v tree &> /dev/null
then
echo -e "${VERB}Installing the \"tree\" utility.${RSET}"
sudo apt-get install -y tree
else
echo -e "${HIGH}The \"tree\" utility is already installed.${RSET}"
fi
echo -e "${LINE_ASCII_CONSOLE}\n"
if ! command -v inspec &> /dev/null
then
echo -e "${VERB}Installing InSpec into the Environment.${RSET}"
curl https://omnitruck.chef.io/install.sh | sudo bash -s -- -c stable -P inspec -v 5
else
echo -e "${HIGH}InSpec is already installed.${RSET}"
fi
echo -e "${LINE_ASCII_CONSOLE}\n"
if ! gem list --installed rubocop &> /dev/null
then
echo -e "${VERB}Installing the \"rubocop\" Ruby gem.${RSET}"
gem install rubocop
else
echo -e "${HIGH}The \"rubocop\" Ruby gem is already installed.${RSET}"
fi
echo -e "${LINE_ASCII_CONSOLE}\n"
# Heimdall Lite & SAF CLI use Node v18
nvm install 18 &> /dev/null
nvm use 18 &> /dev/null
if ! command -v saf &> /dev/null
then
echo -e "${VERB}Installing MITRE SAF CLI into the Environment.${RSET}"
npm install -g npm
npm install -g @mitre/saf
else
echo -e "${HIGH}MITRE SAF CLI is already installed.${RSET}"
fi
echo -e "${LINE_ASCII_CONSOLE}\n"
# First check for Heimdall Lite repo
if ! ls -A ./dev_repos/heimdall2 &> /dev/null
then
echo -e "${VERB}Pulling down MITRE Heimdall Lite repository into the Environment.${RSET}"
git clone https://github.com/mitre/heimdall2 dev_repos/heimdall2
else
echo -e "${HIGH}MITRE Heimdall Lite repository is already present.${RSET}"
fi
echo -e "${LINE_ASCII_CONSOLE}\n"
# Then check for Node packages
if ! ls -A ./dev_repos/heimdall2/node_modules &> /dev/null
then
echo -e "${VERB}Installing required Node packages for MITRE Heimdall Lite repository.${RSET}"
cd dev_repos/heimdall2
yarn install --frozen-lockfile
cd ../..
else
echo -e "${HIGH}MITRE Heimdall Lite Node packages are already present.${RSET}"
fi
echo -e "${LINE_ASCII_CONSOLE}\n"
# First check for SAF CLI repo
if ! ls -A ./dev_repos/saf &> /dev/null
then
echo -e "${VERB}Pulling down MITRE SAF CLI repository into the Environment.${RSET}"
git clone https://github.com/mitre/saf dev_repos/saf
else
echo -e "${HIGH}MITRE SAF CLI repository is already present.${RSET}"
fi
echo -e "${LINE_ASCII_CONSOLE}\n"
# Then check for Node packages
if ! ls -A ./dev_repos/saf/node_modules &> /dev/null
then
echo -e "${VERB}Installing required Node packages for MITRE SAF CLI repository.${RSET}"
cd dev_repos/saf
npm ci
cd ../..
else
echo -e "${HIGH}MITRE SAF CLI Node packages are already present.${RSET}"
fi
echo -e "${LINE_ASCII_CONSOLE}\n"
echo -e "${VERB}Setting up the required Docker containers.${RSET}"
docker-compose -f docker-compose.yml up -d
echo -e "${LINE_ASCII_CONSOLE}\n"
echo -e "${HIGH}Setup complete.${RSET}\n"