AnPDockerServer/Nginx/scripts/create_certificate.sh

25 lines
886 B
Bash
Executable File

#!/bin/bash
name=$1
days=$2
if [[ "$name" == "" ]];then
echo -e "[ERRO] I need a name for the new certificate. Use the next example for your command where days is optional and it is 365 (1 year) by default:\n./create_certificate.sh NAME [DAYS]"
else
echo "[INFO] Creating the new certificate '$name'..."
if [[ "$(command -v openssl)" == "" ]];then
echo "[INFO] Installing the 'openssl' command application for create the new certificate."
apt install -y openssl
fi
if [[ "$days" == "" ]];then
days=365
fi
openssl req -newkey rsa:4096 -x509 -sha256 -days $days -nodes -out $name.crt -keyout $name.key &&
echo "[ OK ] The new certificate '$name' was created for $days days. Look for the '$name.crt' and '$name.key' files in this folder." ||
echo "[ERRO] There was any error creating the new certificate '$name'."
fi