websoft9/docker/proxy/init_nginx.sh

34 lines
1.0 KiB
Bash
Raw Normal View History

2024-07-25 08:39:06 +08:00
#!/bin/bash
2024-12-06 13:43:57 +08:00
# Define variables
2024-07-25 08:39:06 +08:00
credential_path="/data/credential"
2024-12-06 13:43:57 +08:00
# Migrating initproxy.conf file
2024-12-10 15:19:55 +08:00
if [ ! -d /data/nginx/default_host ]; then mkdir -p /data/nginx/default_host; fi
2024-12-06 13:43:57 +08:00
cp -f /etc/websoft9/initproxy.conf /data/nginx/default_host/initproxy.conf
[ -f /etc/websoft9/initproxy.conf ] && rm -f /data/nginx/proxy_host/initproxy.conf
# If credential file then create it and init credential for NPM
# Reload NPM docker image Environments
2024-07-25 08:39:06 +08:00
if [ ! -f "$credential_path" ]; then
2024-12-06 13:43:57 +08:00
# Set init credential
2024-07-25 08:39:06 +08:00
INITIAL_ADMIN_EMAIL="admin@mydomain.com"
INITIAL_ADMIN_PASSWORD=$(openssl rand -base64 16 | tr -d '/+' | cut -c1-16)
2024-12-06 13:43:57 +08:00
# Write credential to file
2024-07-25 08:39:06 +08:00
mkdir -p "$(dirname "$credential_path")"
2024-12-06 13:43:57 +08:00
echo "{\"username\":\"$INITIAL_ADMIN_EMAIL\",\"password\":\"$INITIAL_ADMIN_PASSWORD\"}" > "$credential_path"
2024-07-25 08:39:06 +08:00
2024-12-06 13:43:57 +08:00
else
read -r INITIAL_ADMIN_EMAIL INITIAL_ADMIN_PASSWORD < <(jq -r '.username + " " + .password' "$credential_path")
2024-07-25 08:39:06 +08:00
fi
2024-12-06 13:43:57 +08:00
# Reload NPM docker image Environments
export INITIAL_ADMIN_EMAIL
export INITIAL_ADMIN_PASSWORD
# Start NPM
2024-07-25 08:39:06 +08:00
exec /init