-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-metabase.sh
More file actions
131 lines (118 loc) · 4.64 KB
/
init-metabase.sh
File metadata and controls
131 lines (118 loc) · 4.64 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/sh -e
ADMIN_FIRST_NAME=${MB_ADMIN_FIRST_NAME:-Administrator}
ADMIN_LAST_NAME=${MB_ADMIN_LAST_NAME:-Administrator}
ADMIN_EMAIL=${MB_ADMIN_EMAIL:-admin@metabase.local}
ADMIN_PASSWORD=${MB_ADMIN_PASSWORD:-SuperSecurePassword123456!}
METABASE_HOST=${MB_HOSTNAME:-metabase}
METABASE_PORT=${MB_PORT:-3000}
SITE_NAME=${MB_SITE_NAME:-"MetabaseDemo"}
if [ -f ./.init-done ]; then
echo "Metabase init script has already run. Remove the file ./.init-done to run this script again.";
exit 0;
fi;
echo "Waiting for Metabase to be ready...";
while (! curl -s -m 5 http://${METABASE_HOST}:${METABASE_PORT}/api/session/properties -o /dev/null); do sleep 5; done
printf "Obtaining setup token...";
SETUP_TOKEN=$(curl -s -m 5 -X GET \
http://${METABASE_HOST}:${METABASE_PORT}/api/session/properties \
-H "Content-Type: application/json" \
| jq -r '.["setup-token"]') && printf ' [OK]\n' || printf ' [FAIL]\n';
printf "Creating admin user...";
MB_TOKEN=$(curl -s -X POST \
http://${METABASE_HOST}:${METABASE_PORT}/api/setup \
-H "Content-type: application/json" \
-d '{
"token": "'${SETUP_TOKEN}'",
"user": {
"email": "'${ADMIN_EMAIL}'",
"first_name": "'${ADMIN_FIRST_NAME}'",
"last_name": "'${ADMIN_LAST_NAME}'",
"password": "'${ADMIN_PASSWORD}'"
},
"prefs": {
"allow_tracking": false,
"site_name": "'${SITE_NAME}'"
}
}' | jq -r '.id') && printf ' [OK]\n' || printf ' [FAIL]\n';
# echo -e "\n Creating some basic users: "
# curl -s "http://${METABASE_HOST}:${METABASE_PORT}/api/user" \
# -H 'Content-Type: application/json' \
# -H "X-Metabase-Session: ${MB_TOKEN}" \
# -d '{"first_name":"Basic","last_name":"User","email":"basic@somewhere.com","login_attributes":{"region_filter":"WA"},"password":"'${ADMIN_PASSWORD}'"}'
# curl -s "http://${METABASE_HOST}:${METABASE_PORT}/api/user" \
# -H 'Content-Type: application/json' \
# -H "X-Metabase-Session: ${MB_TOKEN}" \
# -d '{"first_name":"Basic 2","last_name":"User","email":"basic2@somewhere.com","login_attributes":{"region_filter":"CA"},"password":"'${ADMIN_PASSWORD}'"}'
# echo -e "\n Basic users created!"
printf "Configuring SMTP server...";
curl -s "http://${METABASE_HOST}:${METABASE_PORT}/api/email" \
-X PUT \
-H 'Content-Type: application/json' \
-H "X-Metabase-Session: ${MB_TOKEN}" \
--data-raw '{
"email-smtp-host": "metabase_mailpit",
"email-smtp-port": 1025,
"email-smtp-security": "tls",
"email-smtp-username": "mailpituser1",
"email-smtp-password": "mailpitpassword1"
}' && printf ' [OK]\n' || printf ' [FAIL]\n';
printf "Configuring Database 1...";
curl -s http://${METABASE_HOST}:${METABASE_PORT}/api/database \
-X POST \
-H 'Content-Type: application/json' \
-H "X-Metabase-Session: ${MB_TOKEN}" \
-d '{
"is_on_demand": false,
"is_full_sync": true,
"is_sample": false,
"cache_ttl": null,
"refingerprint": false,
"auto_run_queries": true,
"schedules": {},
"details": {
"host": "metabase_demo_database_1",
"port": 5432,
"dbname": "demo-database-1-db",
"user": "demo-database-1-user",
"password": "demo-database-1-password",
"schema-filters-type": "inclusion",
"schema-filters-patterns": "public",
"ssl": true,
"ssl-mode": "prefer",
"ssl-use-client-auth": false,
"tunnel-enabled": false,
"advanced-options": false
},
"name": "Metabase Demo Database 1",
"engine": "postgres"
}' && printf ' [OK]\n' || printf ' [FAIL]\n';
printf "Configuring Database 2...";
curl -s http://${METABASE_HOST}:${METABASE_PORT}/api/database \
-X POST \
-H 'Content-Type: application/json' \
-H "X-Metabase-Session: ${MB_TOKEN}" \
-d '{
"is_on_demand": false,
"is_full_sync": true,
"is_sample": false,
"cache_ttl": null,
"refingerprint": false,
"auto_run_queries": true,
"schedules": {},
"details": {
"host": "metabase_demo_database_2",
"port": 3306,
"dbname": "demo-database-2-db",
"user": "demo-database-2-user",
"password": "demo-database-2-password",
"ssl": false,
"tunnel-enabled": false,
"advanced-options": true,
"json-unfolding": true,
"additional-options": "allowPublicKeyRetrieval=true",
"let-user-control-scheduling": false
},
"name": "Metabase Demo Database 2",
"engine": "mysql"
}' && printf ' [OK]\n' || printf ' [FAIL]\n';
touch ./.init-done