-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·108 lines (87 loc) · 3.81 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·108 lines (87 loc) · 3.81 KB
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
#!/bin/bash
domain=${DOMAIN:-"localhost"}
fqdn=${FQDN:-"localhost"}
adminemail=${ADMIN_EMAIL:-"admin%40example.com"}
adminpassword=${ADMIN_PASSWORD:-"admin"}
dbtype=${DB_TYPE:-'embedded'}
datasourcemode='embedded'
case "$dbtype" in
postgres)
datasourcemode='standard'
dbpresets=${DB_PRESETS:-"3"}
dbdriver=${DB_DRIVER:-"org.postgresql.Driver"}
dbserverurlraw=${DB_SERVER_URL:-"jdbc:postgresql://localhost:5432/openfire"}
dbserverurl=$(echo -n "$dbserverurlraw" | od -An -tx1 | tr ' ' '\n' | awk 'NF {printf "%%%s", toupper($1)}')
dbusername=${DB_USERNAME:-"postgres"}
dbpassword=${DB_PASSWORD:-"mysecurepassword"}
dbminconnections=${DB_MIN_CONNECTIONS:-"5"}
dbmaxconnections=${DB_MAX_CONNECTIONS:-"25"}
dbconnectiontimeout=${DB_CONNECTION_TIMEOUT:-"1.0"}
;;
mysql|oracle|mssql)
#TODO: implement other DB types
datasourcemode='standard'
;;
*)
datasourcemode='embedded'
;;
esac
plugins () {
if [ ! -f /data/plugins/restAPI.jar ]; then
cp /tmp/plugins/restAPI.jar /data/plugins
fi
if [ ! -f /data/plugins/subscription.jar ]; then
cp /tmp/plugins/subscription.jar /data/plugins
fi
if [ ! -f /data/plugins/xmppweb.jar ]; then
cp /tmp/plugins/xmppweb.jar /data/plugins
fi
}
setupHeader () {
CSRF=''
header=$(curl -Is 'http://localhost:9090/setup/index.jsp')
JSESSIONID=$(echo "$header" | grep -iE '^Set-Cookie: JSESSIONID=' | sed 's/.*JSESSIONID=\([^;]*\).*/\1/')
}
runCurlGet () {
url=$1
header=$(curl -is "${url}" -H "Cookie: JSESSIONID=$JSESSIONID; csrf=$CSRF;")
CSRF=$(echo "$header" | grep -iE '^Set-Cookie: csrf=' | sed 's/.*csrf=\([^;]*\).*/\1/')
}
runCurlPost () {
url=$1
dataRaw=$2
header=$(curl -is "${url}" -H "Content-Type: application/x-www-form-urlencoded" -H "Cookie: JSESSIONID=$JSESSIONID; csrf=$CSRF;" --data-raw "${dataRaw}")
CSRF=$(echo "$header" | grep -iE '^Set-Cookie: csrf=' | sed 's/.*csrf=\([^;]*\).*/\1/')
}
runSetup () {
setupHeader
runCurlGet "http://localhost:9090/setup/index.jsp?csrf=$CSRF&localeCode=en&save=Continue"
runCurlGet "http://localhost:9090/setup/setup-host-settings.jsp"
runCurlPost "http://localhost:9090/setup/setup-host-settings.jsp" "csrf=$CSRF&domain=$domain&fqdn=$fqdn&embeddedPort=9090&securePort=9091&encryptionAlgorithm=Blowfish&encryptionKey=&encryptionKey1=&continue=Continue"
runCurlGet "http://localhost:9090/setup/setup-datasource-settings.jsp"
runCurlGet "http://localhost:9090/setup/setup-datasource-settings.jsp?csrf=$CSRF&next=true&mode=$datasourcemode&continue=Continue"
if [ "$datasourcemode" = 'standard' ]; then
runCurlGet "http://localhost:9090/setup/setup-datasource-standard.jsp"
runCurlPost "http://localhost:9090/setup/setup-datasource-standard.jsp" "csrf=${CSRF}&presets=${dbpresets}&driver=${dbdriver}&serverURL=${dbserverurl}&username=${dbusername}&password=${dbpassword}&minConnections=${dbminconnections}&maxConnections=${dbmaxconnections}&connectionTimeout=${dbconnectiontimeout}&continue=Continue"
fi
runCurlGet "http://localhost:9090/setup/setup-profile-settings.jsp"
runCurlPost "http://localhost:9090/setup/setup-profile-settings.jsp" "csrf=$CSRF&mode=default&continue=Continue"
runCurlGet "http://localhost:9090/setup/setup-admin-settings.jsp"
runCurlPost "http://localhost:9090/setup/setup-admin-settings.jsp" "csrf=$CSRF&password=admin&email=$adminemail&newPassword=$adminpassword&newPasswordConfirm=$adminpassword&continue=Continue"
runCurlGet "http://localhost:9090/setup/setup-finished.jsp"
plugins
}
echo "--- Waiting server..."
while true; do
HTTPCODE=$(curl -o /dev/null -I -s -w "%{http_code}\n" http://localhost:9090/setup/index.jsp)
if [ "$HTTPCODE" = "200" ]; then
echo "--- setup mode"
runSetup
echo "--- done setup"
break
elif [ "$HTTPCODE" = "302" ]; then
echo "--- running mode"
break
fi
sleep 1
done