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
/
Copy pathinstall.ps1
134 lines (123 loc) · 4.08 KB
/
install.ps1
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
Function Gen-SSHKey
{
Try {
Write-Host "Generating sandbox RSA ssh keys."
ssh-keygen -t rsa -b 4096 -f secrets_storage/sandbox_key -C "sandbox@web" -q -N '""'
copy secrets_storage\sandbox_key.pub sandbox_storage\sandbox_key.pub
}
Catch {
Try {
Write-Host "Generating sandbox RSA ssh keys. (git-bash)"
C:\"Program Files"\Git\bin\sh.exe -c "ssh-keygen -t rsa -N '' -b 4096 -f secrets_storage/sandbox_key -C 'sandbox@web' -q "
copy secrets_storage\sandbox_key.pub sandbox_storage\sandbox_key.pub
}
Catch {
Write-Error "Could not generate SSH key.`n`nAre you sure Git tools are installed correctly?`n"
exit 1
}
}
}
Function Check-DockerCompose
{
Try {
docker-compose -v | Out-Null
}
Catch {
Write-Error "Could not execute docker-compose!`n`nAre you sure it is installed correctly?`n"
exit 1
}
}
Function Gen-Password
{
$private:ofs=""
$Characters = '-+_.~1234567890ZXCVBNMASDFGHJKLQWERTYUIOPqwertyuiopasdfghjklzxcvbnm'
return [String]$Characters[(1..18 | ForEach-Object { Get-Random -Maximum 68 })]
}
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
Write-Host "`nGenerated default service credentials."
Write-Host "Store them somewhere safe.`n"
Write-Host "`nDjango Admin user:`t`t" $django_user
Write-Host "Django Admin password:`t`t" $django_pass
Write-Host "`nRabbitMQ queue user:`t`t" $rabbit_user
Write-Host "RabbitMQ queue password:`t" $rabbit_pass
Write-Host "`nMySQL database user:`t`t" $mysql_user
Write-Host "MySQL database password:`t" $mysql_pass
Write-Host "`n"
$mysql_config = "MYSQL_RANDOM_ROOT_PASSWORD=yes`nMYSQL_DATABASE=pulsar`nMYSQL_USER="+$mysql_user+"`n"
$mysql_config = $mysql_config+"MYSQL_PASSWORD="+$mysql_pass
$rabbit_config = "RABBITMQ_DEFAULT_VHOS=/`nRABBITMQ_DEFAULT_USER="+$rabbit_user+"`n"
$rabbit_config = $rabbit_config+"RABBITMQ_DEFAULT_PASS="+$rabbit_pass
$django_config = "DJANGO_ADMIN_USER="+$django_user+"`n"
$django_config = $django_config+"DJANGO_ADMIN_PASS="+$django_pass
$mysql_config | Out-File -encoding ASCII db.env
$rabbit_config | Out-File -encoding ASCII queue.env
$django_config | Out-File -encoding ASCII web.env
Write-Host "Credentials written to web.env, db.env and queue.env files."
}
Function Build-Containers {
Write-Host "Configuration complete."
$Continue = Read-Host -Prompt 'Do you want to build containers? (y/n)'
if( $Continue -eq "y" -OR $Continue -eq "Y" )
{
Try {
Write-Host "Downloading images and dependencies."
Write-Host "This will take a while..."
docker-compose build --no-cache
Write-Host "Build finished!"
}
Catch {
Write-Error "Failed to build docker containers."
exit 1
}
}
else
{
Write-Host "Bye. "
exit
}
}
Function Start-Pulsar
{
Try {
$Continue = Read-Host -Prompt 'Do you want to start Pulsar now? (y/n)'
if( $Continue -eq "y" -OR $Continue -eq "Y" )
{
Write-Host "Starting Pulsar containers."
Write-Host "Web service will be available on port 8443."
docker-compose up --force-recreate
}
else
{
Write-Host 'Run "docker-compose up --force-recreate" to start it manually.'
exit
}
}
Catch {
Write-Error "Failed to start docker containers."
exit
}
}
Write-Host "`nPulsar Installation Script`n`n"
Write-Host "Before proceeding make sure you have Docker, Docker Compose and Git tools"
Write-Host "installed on your system.`n"
$Continue = Read-Host -Prompt 'Do you want to countinue? (y/n)'
if( $Continue -eq "y" -OR $Continue -eq "Y" )
{
Check-DockerCompose
Gen-SSHKey
Gen-Credentials
Build-Containers
Start-Pulsar
}
else
{
Write-Host "Bye. "
exit
}