forked from geoserver/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle_geoserver_admin_credentials.sh
More file actions
48 lines (43 loc) · 2.1 KB
/
handle_geoserver_admin_credentials.sh
File metadata and controls
48 lines (43 loc) · 2.1 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
#!/bin/bash
# Configure GeoServer admin credentials
# Supports: GEOSERVER_ADMIN_USER/PASSWORD (env vars) or GEOSERVER_ADMIN_USER_FILE/PASSWORD_FILE (file paths)
# Priority: Direct env vars take precedence over files
ADMIN_USER=""
ADMIN_PASSWORD=""
# Resolve password from file or env var
if [ -n "$GEOSERVER_ADMIN_PASSWORD_FILE" ] && [ -f "$GEOSERVER_ADMIN_PASSWORD_FILE" ]; then
if [ -n "$GEOSERVER_ADMIN_PASSWORD" ]; then
echo "Warning: Both GEOSERVER_ADMIN_PASSWORD and GEOSERVER_ADMIN_PASSWORD_FILE are set. Using GEOSERVER_ADMIN_PASSWORD."
ADMIN_PASSWORD="$GEOSERVER_ADMIN_PASSWORD"
else
ADMIN_PASSWORD=$(cat "$GEOSERVER_ADMIN_PASSWORD_FILE")
echo "Loaded GeoServer admin password from file."
fi
elif [ -n "$GEOSERVER_ADMIN_PASSWORD_FILE" ]; then
echo "Error: GEOSERVER_ADMIN_PASSWORD_FILE is set to '$GEOSERVER_ADMIN_PASSWORD_FILE' but file does not exist or is not readable."
exit 1
elif [ -n "$GEOSERVER_ADMIN_PASSWORD" ]; then
echo "Using GeoServer admin password from environment variable."
ADMIN_PASSWORD="$GEOSERVER_ADMIN_PASSWORD"
fi
# Resolve username from file or env var
if [ -n "$GEOSERVER_ADMIN_USER_FILE" ] && [ -f "$GEOSERVER_ADMIN_USER_FILE" ]; then
if [ -n "$GEOSERVER_ADMIN_USER" ]; then
echo "Warning: Both GEOSERVER_ADMIN_USER and GEOSERVER_ADMIN_USER_FILE are set. Using GEOSERVER_ADMIN_USER."
ADMIN_USER="$GEOSERVER_ADMIN_USER"
else
ADMIN_USER=$(cat "$GEOSERVER_ADMIN_USER_FILE")
echo "Loaded GeoServer admin user from file."
fi
elif [ -n "$GEOSERVER_ADMIN_USER_FILE" ]; then
echo "Error: GEOSERVER_ADMIN_USER_FILE is set to '$GEOSERVER_ADMIN_USER_FILE' but file does not exist or is not readable."
exit 1
elif [ -n "$GEOSERVER_ADMIN_USER" ]; then
echo "Using GeoServer admin username from environment variable."
ADMIN_USER="$GEOSERVER_ADMIN_USER"
fi
# Update credentials if both username and password are available
if [ -n "$ADMIN_PASSWORD" ] && [ -n "$ADMIN_USER" ]; then
echo "Updating GeoServer admin credentials..."
/bin/sh /opt/update_credentials.sh "$ADMIN_USER" "$ADMIN_PASSWORD"
fi