-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
133 lines (115 loc) · 4.18 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
#! /bin/bash
cyan='\033[0;36m'
green='\033[0;32m'
red='\033[0;31m'
nocol='\033[0m'
distro=$(awk '/^ID=/' /etc/*-release | awk -F'=' '{ print tolower($2) }')
if ! [ $distro == ubuntu ]
then
echo -e "${red}Script isn't compatible with current Linux distribution!...exit${nocol}"
exit 1
fi
echo -e "${cyan}Installing docker... ${nocol}"
sleep 3
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
sleep 1
echo -e "${cyan}Installing docker-compose... ${nocol}"
sleep 3
apt install docker-compose -y
sleep 1
echo -e "${cyan}Installing apache2-utils... ${nocol}"
sleep 3
apt install apache2-utils -y
sleep 1
echo -e "${cyan}Installing ruby... ${nocol}"
sleep 3
apt install ruby -y
sleep 1
echo -e "${cyan}Enter admin user password...${nocol}"
read -p ": " admin_pass
echo -e "${cyan}Enter elasticsearch user password...${nocol}"
read -p ": " elasticsearch_pass
echo -e "${cyan}Generating bcrypt hash for admin user...${nocol}"
sleep 2
admin_hash=$(htpasswd -bnBC 10 "" $admin_pass | tr -d ':\n')
echo $admin_hash
echo -e "${cyan}Generating bcrypt hash for elasticsearch user...${nocol}"
sleep 2
elasticsearch_hash=$(htpasswd -bnBC 10 "" $elasticsearch_pass | tr -d ':\n')
echo $elasticsearch_hash
echo -e "${cyan}Generating password for kibanaserver user...${nocol}"
sleep 2
kibanaserver_pass=$(openssl rand -base64 10)
echo $kibanaserver_pass
echo -e "${cyan}Generating bcrypt hash for kibanaserver user...${nocol}"
sleep 2
kibanaserver_hash=$(htpasswd -bnBC 10 "" $kibanaserver_pass | tr -d ':\n')
echo $kibanaserver_hash
echo -e "${cyan}Applying configuration...${nocol}"
sleep 2
ruby ./config.rb "$admin_hash" "$kibanaserver_hash" "$elasticsearch_hash" "$kibanaserver_pass"
echo -e "${cyan}internal_users.yml${nocol}"
cat internal_users.yml
sleep 2
echo -e "${cyan}kibana.yml${nocol}"
cat kibana.yml
sleep 2
echo -e "${cyan}Running elasticsearch and kibana containers...${nocol}"
sleep 2
docker-compose up -d
echo -e "${cyan}Waiting 90sec...${nocol}"
sleep 90
echo -e "${cyan}Checking elasticsearch and kibana containers status...${nocol}"
sleep 2
if [ $(docker inspect -f '{{.State.Running}}' odfe-node1) == true ] && [ $(docker inspect -f '{{.State.Running}}' odfe-kibana) == true ]
then
echo -e "${cyan}Elasticsearch and kibana containers up...${nocol}"
docker ps
sleep 2
else
echo -e "${red}Docker containers are't running!...exit${nocol}"
exit 1
fi
echo -e "${cyan}Checking kibana ready status...${nocol}"
sleep 2
for ((n=0;n<20;n++))
do
response=$(curl -s -XGET http://localhost:5601/status -I -u admin:$admin_pass|grep "HTTP/1.1")
code=($response)
if ! [ ${code[1]} == '200' ]
then
echo "$response"
sleep 10
else
#elif [ ${code[1]} == '200' ]
#then
echo "$response"
echo -e "${cyan}Kibana is ready...${nocol}"
sleep 2
echo -e "${cyan}Importing saved data for winlogbeats...${nocol}"
sleep 2
curl -X POST "localhost:5601/api/saved_objects/_import" -H "kbn-xsrf: true" --form file=@import-logs.ndjson -u admin:${admin_pass} -w "\n"
echo -e "${cyan}Importing saved data for metricbeats...${nocol}"
sleep 2
curl -X POST "localhost:5601/api/saved_objects/_import" -H "kbn-xsrf: true" --form file=@import-metrics.ndjson -u admin:${admin_pass} -w "\n"
echo -e "${cyan}Importing Advanced Settings [7.3.2]...${nocol}"
sleep 2
curl -X POST "localhost:5601/api/saved_objects/_resolve_import_errors" -H "kbn-xsrf: true" --form file=@import-settings.ndjson --form retries='[{"type":"config","id":"7.3.2","overwrite":true}]' -u admin:${admin_pass} -w "\n"
break
fi
done
if [ $n == 20 ]
then
echo -e "${red}Tries exceeded...exit${nocol}"
docker logs odfe-node1 --tail 5
exit 1
fi
valhost=$(hostname)
ip=$(hostname -I | cut -d' ' -f1)
echo -e "${green}Kibana is running http://$valhost:5601${nocol}"
echo -e "${green}Elasticsearch is running http://$valhost:9200${nocol}"
echo -e "${cyan}admin user password: $admin_pass${nocol}"
echo -e "${cyan}kibanaserver user password: $kibanaserver_pass${nocol}"
echo -e "${cyan}elasticsearch user password: $elasticsearch_pass${nocol}"
echo -e "${cyan}Server IP address: $ip.${nocol}"