forked from mitre/saf-training-lab-environment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-lab.sh
executable file
·94 lines (62 loc) · 2.47 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
#!/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"
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"
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"