aboutsummaryrefslogtreecommitdiff
path: root/.github/container/ejabberd-container-install.bat
blob: 5d3abaceacbb676a0f49a3912189ecdc54ae0874 (plain) (blame)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
@echo off

::
::   ejabberd Docker installer for Windows
::   -------------------------------------
::                                    v0.3
::
:: This batch script downloads an ejabberd docker image
:: and setups a docker container to run ejabberd.

::
:: 1. Download and install Docker:
::
::    If you use Windows 10, download Docker Desktop from:
::      https://www.docker.com/
::
::    If you use Windows 7 or 8, download Docker Toolbox from:
::      https://github.com/docker/toolbox/releases
::    After installation, run Docker Quickstart Installer
::

::
:: 2. Edit those options:

:: Directory where your ejabberd deployment files will be installed
:: (configuration, database, logs, ...)
::
:: In Windows 10 you can configure the path:

set INSTALL_DIR_WINDOWS10=C:\ejabberd

:: In older Windows, not configurable, it will be installed in:
:: C:\Users\%USERNAME%\ejabberd

:: Please enter the desired ejabberd domain name.
:: The domain is the visible attribute that is added to the username
:: to form the Jabber Identifier (for example: user@example.net).
:: This computer must be known on the network with this address name.
:: You can later add more in conf/ejabberd.yml

set HOST=localhost

:: Please enter the administrator username for the current
:: ejabberd installation. A Jabber account with this username
:: will be created and granted administrative privileges.
:: Don't use blankspaces in the username.

set USER=admin

:: Please provide a password for that new administrator account

set PASSWORD=

:: By default this downloads 'latest' ejabberd version,
:: but you can set a specific version, for example 21.01

set VERSION=latest

:: This tells docker what ports ejabberd will use.
:: You can later configure them in conf/ejabberd.yml

set PORTS=5180 5222 5269 5443

::
:: 3. Now save this script and run it.
::

::
:: 4. When installation is completed:
::
:: If using Windows 10, open Docker Desktop and you can:
::
:: - (>) START the ejabberd container
:: - Enter WebAdmin: click the ([->]) OPEN IN BROWSER button
:: - To try ejabberdctl, click the (>_) CLI button, then: bin/ejabberdctl
:: - ([]) STOP the ejabberd container
::
:: If using an old Windows, open Kitematic and you can:
::
:: - START the ejabberd container
:: - Open your configuration, logs, ... in Settings > Volumes
:: - Enter WebAdmin in Settings > Hostname/Ports > click on the 5180 port
:: - Try ejabberdctl in EXEC, then: bin/ejabberdctl
:: - STOP the ejabberd container
::
:: You can delete the container and create it again running this script,
:: the configuration and database are maintained.
::

::===============================================================
:: Check Windows version
::
::===============================================================

set INSTALL_DIR_DOCKER=c/Users/%USERNAME%/ejabberd

for /f "tokens=4-5 delims=. " %%i in ('ver') do set WVERSION=%%i.%%j
if "%wversion%" == "10.0" (
  echo === Preparing paths to install in Windows 10...
  set INSTALL_DIR=%INSTALL_DIR_WINDOWS10%
  set VC=-v %INSTALL_DIR_WINDOWS10%\conf:/opt/ejabberd/conf
  set VD=-v %INSTALL_DIR_WINDOWS10%\database:/opt/ejabberd/database
  set VL=-v %INSTALL_DIR_WINDOWS10%\logs:/opt/ejabberd/logs
  set VM=-v %INSTALL_DIR_WINDOWS10%\ejabberd-modules:/opt/ejabberd/.ejabberd-modules
  set DOCKERDOWNLOAD="First download and install Docker Desktop from https://www.docker.com/"
) else (
  echo === Preparing paths to install in Windows older than 10...
  set INSTALL_DIR=C:\Users\%USERNAME%\ejabberd
  set VC=-v "/%INSTALL_DIR_DOCKER%/conf:/opt/ejabberd/conf"
  set VD=-v "/%INSTALL_DIR_DOCKER%/database:/opt/ejabberd/database"
  set VL=-v "/%INSTALL_DIR_DOCKER%/logs:/opt/ejabberd/logs"
  set VM=-v "/%INSTALL_DIR_DOCKER%/ejabberd-modules:/opt/ejabberd/.ejabberd-modules"
  set DOCKERDOWNLOAD="First download and install Docker Toolbox from https://github.com/docker/toolbox/releases"
)
set VOLUMES=%VC% %VD% %VL% %VM%

::===============================================================
:: Check docker is installed
::
::===============================================================

docker version >NUL
if %ERRORLEVEL% NEQ 0 (
  echo.
  echo === ERROR: It seems docker is not installed!!!
  echo.
  echo %DOCKERDOWNLOAD%
  echo === Then try to run this script again.
  echo.
  pause
  exit 1
)

::===============================================================
:: Check install options are correctly set
::
::===============================================================

if [%PASSWORD%]==[] (
  echo.
  echo === ERROR: PASSWORD not set!!!
  echo.
  echo === Please edit this script and set the PASSWORD.
  echo === Then try to run this script again.
  echo.
  pause
  exit 1
)

::===============================================================
:: Download Docker image
::
::===============================================================

set IMAGE=ghcr.io/processone/ejabberd:%VERSION%

echo.
echo === Checking if the '%IMAGE%' docker image was already downloaded...
docker image history %IMAGE% >NUL
if %ERRORLEVEL% NEQ 0 (
  echo === The '%IMAGE%' docker image was not downloaded yet.
  echo.
  echo === Downloading the '%IMAGE%' docker image, please wait...
  docker pull %IMAGE%
) else (
  echo === The '%IMAGE%' docker image was already downloaded.
)

::===============================================================
:: Create preliminary container
::
::===============================================================

echo.
echo === Checking if the 'ejabberd' docker container already exists...
docker container logs ejabberd
if %ERRORLEVEL% EQU 0 (
  echo.
  echo === The 'ejabberd' docker container already exists.
  echo === Nothing to do, so installation finishes now.
  echo === You can go to Docker Desktop and start the 'ejabberd' container.
  echo.
  pause
  exit 1
) else (
  echo === The 'ejabberd' docker container doesn't yet exist,
  echo === so let's continue the installation process.
)

echo.
if exist %INSTALL_DIR% (
  echo === The INSTALL_DIR %INSTALL_DIR% already exists.
  echo === No need to create the preliminary 'ejabberd-pre' image.
) else (
  echo === The INSTALL_DIR %INSTALL_DIR% doesn't exist.
  echo === Let's create the preliminary 'ejabberd-pre' image.
  CALL :create-ejabberd-pre
)

::===============================================================
:: Create final container
::
::===============================================================

echo.
echo === Creating the final 'ejabberd' docker container using %IMAGE% image...

setlocal EnableDelayedExpansion
set PS=
for %%a in (%PORTS%) do (
  set PS=!PS! -p %%a:%%a
)

docker create --name ejabberd --hostname localhost %PS% %VOLUMES% %IMAGE%

echo.
echo === Installation completed.
echo.
pause

EXIT /B %ERRORLEVEL%

::===============================================================
:: Function to create preliminary container
::
::===============================================================

:create-ejabberd-pre

echo.
echo === Creating a preliminary 'ejabberd-pre' docker image using %IMAGE% image...
docker create --name ejabberd-pre --hostname localhost %IMAGE%

echo.
echo === Now 'ejabberd-pre' will be started.
docker container start ejabberd-pre

echo.
echo === Waiting ejabberd to be running...
set /A timeout = 10
set status=4
goto :while

:statusstart
docker exec -it ejabberd-pre ejabberdctl status
goto :statusend

:while
if %status% GTR 0 (
   echo.
   timeout /t 1 /nobreak >NUL
   set /A timeout = timeout - 1
   if %timeout% EQU 0 (
      set status=-1
   ) else (
      goto :statusstart
      :statusend
      set status=%ERRORLEVEL%
   )
   goto :while
)

echo.
echo === Setting a few options...
docker exec -it ejabberd-pre sed -i "s!- localhost!- %HOST%!g" conf/ejabberd.yml
docker exec -it ejabberd-pre sed -i "s!^acl:!acl:\n  admin:\n    user:\n      - \"%USER%@%HOST%\"!g" conf/ejabberd.yml
docker exec -it ejabberd-pre sed -i "s!5280!5180!g" conf/ejabberd.yml
docker exec -it ejabberd-pre sed -i "s!/admin!/!g" conf/ejabberd.yml
docker exec -it ejabberd-pre ejabberdctl reload_config

echo.
echo === Registering the administrator account...
docker exec -it ejabberd-pre ejabberdctl register %USER% %HOST% %PASSWORD%
docker exec -it ejabberd-pre ejabberdctl stop

echo.
echo === Copying conf, database, logs...
mkdir %INSTALL_DIR%
mkdir %INSTALL_DIR%\conf
mkdir %INSTALL_DIR%\database
mkdir %INSTALL_DIR%\logs
mkdir %INSTALL_DIR%\ejabberd-modules
docker cp ejabberd-pre:/opt/ejabberd/conf/ %INSTALL_DIR%
docker cp ejabberd-pre:/opt/ejabberd/database/ %INSTALL_DIR%
docker cp ejabberd-pre:/opt/ejabberd/logs/ %INSTALL_DIR%

echo.
echo === Deleting the preliminary 'ejabberd-pre' docker image...
docker stop ejabberd-pre
docker rm ejabberd-pre

EXIT /B 0