forked from guardian/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·147 lines (124 loc) · 2.78 KB
/
setup.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
#!/bin/bash
set -e
readonly SYSTEM=$(uname -s)
EXTRA_STEPS=()
BASEDIR=$(dirname $0)
linux() {
[[ $SYSTEM == 'Linux' ]]
}
mac() {
[[ $SYSTEM == 'Darwin' ]]
}
installed() {
hash "$1" 2>/dev/null
}
nvm_installed() {
if [ -d '/usr/local/opt/nvm' ] || [ -d "$HOME/.nvm" ]; then
true
else
false
fi
}
nvm_available() {
type -t nvm > /dev/null
}
source_nvm() {
if ! nvm_available; then
[ -e "/usr/local/opt/nvm/nvm.sh" ] && source /usr/local/opt/nvm/nvm.sh
fi
if ! nvm_available; then
[ -e "$HOME/.nvm/nvm.sh" ] && source $HOME/.nvm/nvm.sh
fi
}
check_encryption() {
if linux; then
EXTRA_STEPS+=("Sorry, can't check if your hard disk is encrypted - please ensure that it is! (applies to both portable and Desktop machines)")
elif mac; then
if [[ "$(fdesetup status)" != "FileVault is On." ]]; then
EXTRA_STEPS+=("your hard disk is not encrypted! Encryption must be enabled on all guardian machines. Follow these instructions: https://support.apple.com/en-gb/HT204837")
fi
fi
}
create_aws_config() {
local path="$HOME/.aws"
local filename="config"
if [[ ! -f "$path/$filename" ]]; then
if [[ ! -d "$path" ]]; then
mkdir "$path"
fi
echo "[profile frontend]
region = eu-west-1" > "$path/$filename"
fi
}
install_homebrew() {
if mac && ! installed brew; then
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
}
install_jdk() {
if ! installed javac; then
if linux; then
sudo apt-get install -y openjdk-7-jdk
elif mac; then
EXTRA_STEPS+=("Download the JDK from https://adoptopenjdk.net")
fi
fi
}
install_node() {
if ! nvm_installed; then
if linux; then
if ! installed curl; then
sudo apt-get install -y curl
fi
fi
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
nvm install
EXTRA_STEPS+=("Add https://git.io/vKTnK to your .bash_profile")
else
if ! nvm_available; then
source_nvm
fi
nvm install
fi
}
install_gcc() {
if ! installed g++; then
if linux; then
sudo apt-get install -y g++ make
elif mac; then
EXTRA_STEPS+=("Install Xcode from the App Store")
fi
fi
}
install_libpng() {
if ! installed libpng-config; then
if linux; then
sudo apt-get install -y libpng-dev
elif mac; then
brew install libpng
fi
fi
}
compile() {
make install compile
}
report() {
if [[ ${#EXTRA_STEPS[@]} -gt 0 ]]; then
node ./tools/messages.js install-steps
for i in "${!EXTRA_STEPS[@]}"; do
echo " $((i+1)). ${EXTRA_STEPS[$i]}"
done
fi
}
main() {
check_encryption
create_aws_config
install_homebrew
install_jdk
install_node
install_gcc
install_libpng
compile
report
}
main