This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
install.sh
executable file
·110 lines (100 loc) · 3.19 KB
/
install.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
#!/bin/bash
function Gen-SSHKey
{
echo "Generating sandbox RSA ssh keys."
ssh-keygen -t rsa -b 4096 -f secrets_storage/sandbox_key -C "sandbox@web" -q -N ''
cp secrets_storage/sandbox_key.pub sandbox_storage/sandbox_key.pub
if [ $? -ne 0 ]
then
echo -e "\nCould not generate SSH key.\nAre you sure ssh-keygen is installed correctly?\n"
exit
fi
}
function Check-DockerCompose
{
docker-compose version >&2 2>/dev/null
if [ $? -ne 0 ]
then
echo -e "\nCould not execute docker-compose!\nAre you sure it is installed correctly?\n"
exit
fi
}
function Gen-Password
{
openssl rand -hex 12
}
function Gen-Credentials
{
django_user='admin'
django_pass=$(Gen-Password)
rabbit_user='queue_admin'
rabbit_pass=$(Gen-Password)
mysql_user='pulsar_db_user'
mysql_pass=$(Gen-Password)
echo -e "\nGenerated default service credentials."
echo -e "Store them somewhere safe.\n"
echo -e "\nDjango Admin user:\t\t${django_user}"
echo -e "Django Admin password:\t\t${django_pass}"
echo -e "\nRabbitMQ queue user:\t\t${rabbit_user}"
echo -e "RabbitMQ queue password:\t${rabbit_pass}"
echo -e "\nMySQL database user:\t\t${mysql_user}"
echo -e "MySQL database password:\t${mysql_pass}"
echo -e "\n"
echo -e "MYSQL_RANDOM_ROOT_PASSWORD=yes\nMYSQL_DATABASE=pulsar\nMYSQL_USER=${mysql_user}\nMYSQL_PASSWORD=${mysql_pass}" > db.env
echo -e "RABBITMQ_DEFAULT_VHOST=/\nRABBITMQ_DEFAULT_USER=${rabbit_user}\nRABBITMQ_DEFAULT_PASS=${rabbit_pass}" > queue.env
echo -e "DJANGO_ADMIN_USER=${django_user}\nDJANGO_ADMIN_PASS=${django_pass}" > web.env
echo "Credentials written to web.env, db.env and queue.env files."
}
function Build-Containers {
echo "Configuration complete."
read -n 2 -p 'Do you want to build containers? (y/n) ' Continue
if [ "$Continue" == "y" ]
then
echo -e "\nDownloading images and dependencies.\n"
echo -e "This will take a while...\n"
docker-compose build --no-cache # 2>&1 >/dev/null
if [ $? -ne 0 ]
then
echo -e "\nFailed to build docker containers."
exit 1
else
echo -e "\nBuild finished!"
fi
else
echo -e "\nBye. "
exit
fi
}
function Start-Pulsar
{
read -n 2 -p 'Do you want to start Pulsar now? (y/n) ' Continue
if [ "$Continue" == "y" ]
then
echo "Starting Pulsar containers."
echo "Web service will be available on port 8443."
docker-compose up --force-recreate
if [[ $? -ne 0 ]]
then
echo -e "\nFailed to start docker containers."
exit
fi
else
echo -e '\nRun "docker-compose up --force-recreate" to start it manually.'
exit
fi
}
echo -e "\nPulsar Installation Script\n\n"
echo -e "Before proceeding make sure you have Docker, Docker Compose and ssh-keygen tool"
echo -e "installed on your system.\n"
read -n 2 -p 'Do you want to countinue? (y/n) ' Continue
if [ "$Continue" == "y" ]
then
Check-DockerCompose
Gen-SSHKey
Gen-Credentials
Build-Containers
Start-Pulsar
else
echo -e "\nBye. "
exit
fi