chore: generate default admin credentials on install

This commit is contained in:
2026-05-26 01:16:10 +07:00
parent 96f5c9a4b5
commit 4e0615a7c5
3 changed files with 25 additions and 9 deletions
+14 -2
View File
@@ -8,6 +8,8 @@ REPO_URL="https://git.h0melab.ru/fabritsky/corp-address-book.git"
HOST_PORT="8180"
CONTAINER_PORT="3000"
IMAGE_NAME="corp-address-book:latest"
ENV_CREATED="false"
GENERATED_ADMIN_PASSWORD=""
log() {
printf '\n[%s] %s\n' "$(date +'%H:%M:%S')" "$*"
@@ -39,7 +41,8 @@ install_base_packages() {
ca-certificates \
curl \
git \
gnupg
gnupg \
openssl
}
install_docker_if_needed() {
@@ -96,6 +99,8 @@ prepare_env_and_data() {
if [ ! -f "${INSTALL_DIR}/.env" ]; then
jwt_secret="$(openssl rand -hex 32 2>/dev/null || date +%s%N)"
admin_password="$(openssl rand -base64 24 2>/dev/null | tr -d '\n' || date +%s%N)"
GENERATED_ADMIN_PASSWORD="$admin_password"
ENV_CREATED="true"
as_root tee "${INSTALL_DIR}/.env" >/dev/null <<EOF_ENV
# Created by install.sh. Keep this file private and do not commit it.
# Change ADMIN_PASSWORD after first login.
@@ -174,8 +179,15 @@ print_result() {
fi
log "Installation completed"
printf 'URL: http://%s:%s/\n' "$server_ip" "$HOST_PORT"
printf 'Local check: http://127.0.0.1:%s/\n' "$HOST_PORT"
printf 'Open: http://%s:%s/\n' "$server_ip" "$HOST_PORT"
printf 'Admin login: admin\n'
if [ "$ENV_CREATED" = "true" ]; then
printf 'Admin password: %s\n' "$GENERATED_ADMIN_PASSWORD"
printf 'The password was saved in %s/.env. JWT_SECRET was not printed.\n' "$INSTALL_DIR"
else
printf 'Admin password: unchanged; read it from %s/.env on the server.\n' "$INSTALL_DIR"
fi
}
main() {