dsql-admin/dsql-app/setup.sh

78 lines
2.3 KiB
Bash
Raw Permalink Normal View History

2024-11-05 11:12:42 +00:00
#!/bin/bash
CA_CERT_FILE="/ssl/ca-cert.pem"
CA_KEY_FILE="/ssl/ca-key.pem"
SERVER_CERT_FILE="/ssl/server-cert.pem"
SERVER_CERT_FILE="/ssl/server-key.pem"
2024-11-05 18:42:02 +00:00
if [ ! -d "/app/ssl" ]; then
mkdir -p "/app/ssl"
fi
if [ ! -d "/app/public/documents/ssl/" ]; then
mkdir -p "/app/public/documents/ssl/"
fi
2024-11-05 11:12:42 +00:00
2024-12-05 07:03:33 +00:00
if [ -f "$CA_CERT_FILE" ] && [ -f "$CA_KEY_FILE" ] && [ -f "$SERVER_CERT_FILE" ] && [ -f "$SERVER_KEY_FILE" ]; then
2024-11-05 11:12:42 +00:00
echo "SSL Files Present. Moving Forward >>>"
else
echo "Generating SSL Files ..."
rm -Rf /ssl/*
cd /ssl
openssl genrsa 2048 >ca-key.pem
openssl req -new -x509 -nodes -days 365000 -key ca-key.pem -out ca-cert.pem -subj "/C=/ST=/L=/O=/CN=MariaDB admin"
openssl req -newkey rsa:2048 -days 365000 -nodes -keyout server-key.pem -out server-req.pem -subj "/C=/ST=/L=/O=/CN=MariaDB server"
openssl rsa -in server-key.pem -out server-key.pem
openssl x509 -req -in server-req.pem -days 365000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem
openssl req -newkey rsa:2048 -days 365000 -nodes -keyout client-key.pem -out client-req.pem -subj "/C=/ST=/L=/O=/CN=MariaDB user"
openssl rsa -in client-key.pem -out client-key.pem
openssl x509 -req -in client-req.pem -days 365000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem
fi
chmod 755 /ssl
chmod 644 /ssl/*.pem
rm -f /app/ssl/ca-cert.pem
rm -Rf /app/ssl/*
rm -Rf /app/public/documents/ssl/*
cp /ssl/ca-cert.pem /app/ssl/
cp /ssl/ca-cert.pem /app/public/documents/ssl/
2024-11-26 09:31:39 +00:00
LOCAL_CONFIG_DIR="/app/jsonData/dbSchemas/users"
if [ ! -d "$LOCAL_CONFIG_DIR" ]; then
echo "Creating Local Config Directory ..."
mkdir -p "$LOCAL_CONFIG_DIR"
fi
2024-12-05 07:03:33 +00:00
##------------------
# Create SSH keys
##------------------
echo "Generating SSH keys ..."
KEY_NAME="dsql"
OUTPUT_DIR="/ssh"
PASSPHRASE=""
mkdir -p "$OUTPUT_DIR"
KEY_PATH="$OUTPUT_DIR/$KEY_NAME"
if [ ! -f "$KEY_PATH" ]; then
echo "Generating SSH keypair..."
ssh-keygen -t rsa -b 4096 -f "$KEY_PATH" -N "$PASSPHRASE" -q
if [ $? -eq 0 ]; then
echo "SSH keypair generated successfully!"
echo "Private key: $KEY_PATH"
echo "Public key: $KEY_PATH.pub"
else
echo "Error: Failed to generate SSH keypair."
exit 1
fi
else
echo "SSH keypair already exists. Skipping key generation."
fi
2024-11-05 11:12:42 +00:00
exit 0