-
Notifications
You must be signed in to change notification settings - Fork 129
/
bootstrap
executable file
·153 lines (145 loc) · 4.34 KB
/
bootstrap
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
151
152
#!/bin/sh
# (c) 2016, The MITRE Corporation. All rights reserved.
# Source code distributed pursuant to license agreement.
#
# Usage: bootstrap
# This script is designed to install all of the necessary dependencies for the
# services available.
#=====================Message Colors=========================
FAIL=$(tput setaf 1) #red
PASS=$(tput setaf 2) #green
HEAD=$(tput setaf 5) #magenta
INFO=$(tput setaf 6) #cyan
END=$(tput sgr0) #ends color
#============================================================
PIP='pip'
. ./funcs.sh
verify()
{
printf "${INFO}Testing Computer's Architecture${END}\n"
ARCH=$(uname -m | sed 's/x86_//;s/amd//;s/i[3-6]86/32/')
if [ "$ARCH" -ne '64' ];
then
printf "${FAIL}Non 64-bit system detected${END}\n"
exit
else
printf "${PASS}Architecure 64-bit Passed${END}\n"
fi
printf "${INFO}Testing the distro type${END}\n"
OS=''
VER=''
REL=''
# Using lsb-release because os-release not available on Ubuntu 10.04
if [ -f /etc/redhat-release ];
then
OS=$(cat /etc/redhat-release | sed 's/ [Enterprise|release|Linux release].*//')
VER=$(cat /etc/redhat-release | sed 's/.*release //;s/ .*$//')
#Redhat/CentOS release version
REL=$(echo $VER | sed 's/.[0-9].[0-9]*//;s/.[0-9]$//')
if [ $REL -lt 7 ];
then
#change for RHEL/CentOS < Release 7
PIP='pip2.7'
fi
elif command -v lsb_release >/dev/null 2>&1
then
OS=$(lsb_release -is)
VER=$(lsb_release -rs)
else
OS=$(uname -s)
VER=$(uname -r)
fi
OS="$(echo "$OS" | tr "[:upper:]" "[:lower:]")"
VER="$(echo "$VER" | tr "[:upper:]" "[:lower:]")"
# Let's export these, so we don't have to repeat this in every bootstrap
export OS REL VER PIP
}
# Creates Default folders
create_files()
{
#TODO fix the fixed paths
#Perhaps we'll do this later
if [ ! -e /data/crits_services ];
then
printf "${HEAD}Creating Services Folder${END}\n"
sudo mkdir -v -p /data/crits_services
fi
#It used to be /data/crits_services
#sudo chown -R $USER:$GROUP /data/crits_services
#This messes with git commits
#chmod -R -v 0755 /data/crits_services
}
traversing_install()
{
tpwd=$PWD
for serv in ${tpwd}/* ;do
if [ -d "$serv" ];
then
fbname=$(basename "${serv}" _service)
if [ -f ${serv}/bootstrap ];
then
printf "${INFO}Installing dependencies for ${fbname}${END}\n"
cd ${serv};
./bootstrap
if [ $? -ne 0 ];
then
printf "${FAIL}bootstrap failed for ${fbname}!${END}\n"
exit
else
printf "${PASS}bootstrap complete for ${fbname}${END}\n"
fi
cd ${tpwd}
else
if [ -f ${serv}/requirements.txt ];
then
printf "${INFO}Installing python dependencies for ${fbname}${END}\n"
cd ${serv};
depend_crits
if [ $? -ne 0 ];
then
printf "${FAIL}bootstrap failed for ${fbname}!${END}\n"
exit
else
printf "${PASS}bootstrap complete for ${fbname}${END}\n"
fi
cd ${tpwd}
fi
fi
fi
done
printf "${INFO}bootstrap finished!\nDependencies for the following \
services need some manual setup (at least until somebody fixes them):\
\n- chopshop_service\n- metacap_service (it needs chopshop)\n- pyew\n\
- taxii_service${END}\n"
}
# Error Message
exit_restart()
{
printf "\n${HEAD}Error: To restart at this step: sh $0 $1${END}\n"
exit
}
#===============================================================
# This is the Beginning of the Script
#===============================================================
# Sees if there is an argument
if [ -z $1 ];
then
STEP=1
else
STEP=$1
fi
while [ $STEP -lt 4 ]
do
case $STEP in
1)
verify ;;
2)
create_files ||exit_restart $STEP ;;
3)
traversing_install ||exit_restart $STEP ;;
*)
exit
;;
esac
STEP=$((STEP+1))
done