-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script for generating ssl certificates
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
echo "This is the WendzelNNTPd script for generating SSL certificates" | ||
echo | ||
|
||
mkdir -p /usr/local/etc/ssl | ||
|
||
if [ "$USER" != "root" ]; then | ||
echo "Run this script with root privileges!" | ||
exit | ||
fi | ||
|
||
while [ $# -gt 0 ]; do | ||
if [[ $1 == "--"* ]]; then | ||
v="${1/--/}" | ||
declare "$v"="$2" | ||
shift | ||
fi | ||
shift | ||
done | ||
|
||
if [[ -z $environment || "$environment" = "local" ]]; then | ||
echo "Environment is set to local. Certificates for local use are generated now..." | ||
echo | ||
|
||
openssl req \ | ||
-x509 \ | ||
-new \ | ||
-newkey rsa:2048 \ | ||
-days 3650 \ | ||
-nodes \ | ||
-extensions v3_ca \ | ||
-subj "/C=DE/ST=Hagen/O=Test-Cert Inc." \ | ||
-keyout "/usr/local/etc/ssl/ca-key.pem" \ | ||
-out "/usr/local/etc/ssl/ca.crt" | ||
|
||
openssl genrsa -out "/usr/local/etc/ssl/server.key" 2048 | ||
openssl req \ | ||
-new -key "/usr/local/etc/ssl/server.key" \ | ||
-out "/usr/local/etc/ssl/server.csr" \ | ||
-config "./docker/openssl/openssl.cnf" | ||
|
||
openssl x509 \ | ||
-req \ | ||
-days 365 \ | ||
-in "/usr/local/etc/ssl/server.csr" \ | ||
-CA "/usr/local/etc/ssl/ca.crt" \ | ||
-CAkey "/usr/local/etc/ssl/ca-key.pem" \ | ||
-CAcreateserial \ | ||
-extensions v3_req \ | ||
-extfile "./docker/openssl/openssl.cnf" \ | ||
-out "/usr/local/etc/ssl/server.crt" | ||
|
||
echo "Finished ..." | ||
echo "You can find certificate at: /usr/local/etc/ssl/server.crt, key: /usr/local/etc/ssl/server.crt, CA certificate: /usr/local/etc/ssl/ca.crt" | ||
echo | ||
elif [ "$environment" = "letsencrypt" ]; then | ||
echo "Environment is set to local. Certificates are generated now via LetsEncrypt certbot..." | ||
echo "Check if certbot is installed..." | ||
certbot --version || exit | ||
|
||
if [ -z $email ]; then | ||
echo "You have to add an email with --email parameter" | ||
exit | ||
fi | ||
|
||
if [ -z $domain ]; then | ||
echo "You have to add the domain where running this script with --domain parameter" | ||
exit | ||
fi | ||
|
||
echo "Generating certificates..." | ||
certbot certonly --standalone -n --agree-tos --email $email --domains $domain | ||
|
||
else | ||
echo "Unknown environment for script generation provided..." | ||
echo "Stopping script." | ||
echo | ||
fi |