-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepare_prosody.sh
executable file
·101 lines (75 loc) · 1.87 KB
/
prepare_prosody.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
#!/bin/bash
cd `dirname $0`
. ./common.sh
usage="
Prepares the prosody XMPP IM server
Usage:
$(basename $0) <server_name> [--add-user <user>:<password>]
[--help] [--debug] [--log <output file>]
where
<server_name> - Name of the server. All clients should identify the server by its name otherwise the certificate wouldn't work
--add-user <user>:<password> - Adds user with on each run
--debug - Flag that sets debugging mode.
--log - Path to the log file that will log all meaningful commands
Example2:
$(basename $0) --debug
"
if [ -z "$1" ]; then
echo "$usage" >&2
exit 0
fi
export server_name="$1"
shift
set -x
while [[ $# > 0 ]]
do
key="$1"
shift
case $key in
--debug)
debug=1
;;
--log)
log=$1
shift
;;
--help)
echo "$usage"
exit 0
;;
--add-user)
add_user_txt=$1
shift
;;
-*)
echo "Error: Unknown option: $1" >&2
echo "$usage" >&2
exit 1
;;
esac
done
add_apt_source_manual prosody "deb https://packages.prosody.im/debian xenial main" "https://prosody.im/files/prosody-debian-packages.key" "prosody_Release.key"
install_apt_packages prosody
prosody_config=$(cat files/prosody.config.lua | envsubst)
textfile /etc/prosody/prosody.cfg.lua "$prosody_config" root
luac -p /etc/prosody/prosody.cfg.lua
if sudo [ ! -f /var/lib/prosody/${server_name}.crt ]; then
echo "
PL
${server_name}
" | sudo prosodyctl cert generate "${server_name}"
fi
if [ -n "$add_user_txt" ]; then
pattern='^([^:]+):(.*)$'
if [[ "$add_user_txt" =~ $pattern ]]; then
add_user=${BASH_REMATCH[1]}
add_password=${BASH_REMATCH[2]}
else
errcho "Wrong format of --add_user argument. Please use \"user:pa\$\$word\"."
exit 1
fi
echo "$add_password
$add_password" | sudo prosodyctl adduser "${add_user}@${server_name}"
# sudo prosodyctl passwd "${add_user}@${server_name}"
fi
sudo systemctl restart prosody