cert gen improvement

This commit is contained in:
2025-12-03 14:45:26 +02:00
parent baa81ec162
commit 590e9564a4
+40 -2
View File
@@ -8,11 +8,49 @@ CERTS_DIRS=(
printf "\nChecking local HTTPS certificates...\n"
install_mkcert_ca() {
set +e
local temp_err=$(mktemp)
mkcert -install 2>"$temp_err"
local exit_code=$?
grep -v "keytool" "$temp_err" | grep -v "Keystore file does not exist" | grep -v "ERROR: failed to execute" >&2
rm "$temp_err"
set -e
if [ $exit_code -ne 0 ]; then
echo "Note: Some certificate installation steps were skipped (Java keystore not found)."
echo "This is normal if Java is not installed and won't affect local HTTPS functionality."
fi
return 0
}
if ! mkcert -CAROOT >/dev/null 2>&1; then
echo "Installing mkcert root CA..."
mkcert -install >/dev/null 2>&1 || true
install_mkcert_ca
fi
generate_certificates() {
local cert_file="$1"
local key_file="$2"
set +e
local temp_err=$(mktemp)
mkcert -cert-file "$cert_file" -key-file "$key_file" localhost 127.0.0.1 ::1 2>"$temp_err"
local exit_code=$?
grep -v "keytool" "$temp_err" | grep -v "Keystore file does not exist" | grep -v "ERROR: failed to execute" >&2
rm "$temp_err"
set -e
return $exit_code
}
for dir in "${CERTS_DIRS[@]}"; do
mkdir -p "$dir"
@@ -21,7 +59,7 @@ for dir in "${CERTS_DIRS[@]}"; do
if [[ ! -f "$CERT_FILE" || ! -f "$KEY_FILE" ]]; then
echo "Generating new certificates in $dir..."
mkcert -install -cert-file "$CERT_FILE" -key-file "$KEY_FILE" localhost 127.0.0.1 ::1
generate_certificates "$CERT_FILE" "$KEY_FILE"
else
echo "Certificates already exist in $dir"
fi