Skip to content

Commit d0aad16

Browse files
committed
fix: be compatible with mac os
1 parent 7d02406 commit d0aad16

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/.idea/
2-
/out/*
2+
/out/
33
/deploy-passport.sh
44
/cert.all.sh

gen.cert.sh

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,15 @@
33
if [ -z "$1" ]
44
then
55
echo
6-
echo 'Issue a wildcard SSL certification with Fishdrowned ROOT CA'
6+
echo 'Issue a wildcard SSL certificate with Fishdrowned ROOT CA'
77
echo
88
echo 'Usage: ./gen.cert.sh <domain> [<domain2>] [<domain3>] [<domain4>] ...'
99
echo ' <domain> The domain name of your site, like "example.dev",'
10-
echo ' you will get a certification for *.example.dev'
10+
echo ' you will get a certificate for *.example.dev'
1111
echo ' Multiple domains are acceptable'
1212
exit;
1313
fi
1414

15-
if [ ! -d "./out/newcerts" ]; then
16-
mkdir -p "./out/newcerts"
17-
fi
18-
19-
if [ ! -f "./out/index.txt" ]; then
20-
touch "./out/index.txt"
21-
fi
22-
23-
if [ ! -f "./out/serial" ]; then
24-
touch "./out/serial"
25-
echo 1000 > ./out/serial
26-
fi
2715
SAN=""
2816
for var in "$@"
2917
do
@@ -34,6 +22,11 @@ SAN=${SAN:0:${#SAN}-1}
3422
# Move to root directory
3523
cd "$(dirname "${BASH_SOURCE[0]}")"
3624

25+
# Generate root certificate if not exists
26+
if [ ! -f "out/root.crt" ]; then
27+
bash gen.root.sh
28+
fi
29+
3730
# Create domain directory
3831
BASE_DIR="out/$1"
3932
TIME=`date +%Y%m%d-%H%M`
@@ -48,21 +41,25 @@ openssl req -new -out "${DIR}/$1.csr.pem" \
4841
<(printf "[SAN]\nsubjectAltName=${SAN}")) \
4942
-subj "/C=CN/ST=Guangdong/L=Guangzhou/O=Fishdrowned/OU=$1/CN=*.$1"
5043

51-
# Issue certification
44+
# Issue certificate
5245
# openssl ca -batch -config ./ca.cnf -notext -in "${DIR}/$1.csr.pem" -out "${DIR}/$1.cert.pem"
5346
openssl ca -config ./ca.cnf -batch -notext \
5447
-in "${DIR}/$1.csr.pem" \
5548
-out "${DIR}/$1.crt" \
5649
-cert ./out/root.crt \
5750
-keyfile ./out/root.key.pem
5851

59-
# Chain certification with CA
52+
# Chain certificate with CA
6053
cat "${DIR}/$1.crt" ./out/root.crt > "${DIR}/$1.bundle.crt"
6154
ln -snf "./${TIME}/$1.bundle.crt" "${BASE_DIR}/$1.bundle.crt"
6255
ln -snf "./${TIME}/$1.crt" "${BASE_DIR}/$1.crt"
6356
ln -snf "../cert.key.pem" "${BASE_DIR}/$1.key.pem"
57+
ln -snf "../root.crt" "${BASE_DIR}/root.crt"
6458

65-
# Output certifications
59+
# Output certificates
6660
echo
67-
echo "Certifications are located in:"
68-
ls -la `pwd`/${BASE_DIR}/*.*
61+
echo "Certificates are located in:"
62+
63+
LS=$([[ `ls --help | grep '\-\-color'` ]] && echo "ls --color" || echo "ls -G")
64+
65+
${LS} -la `pwd`/${BASE_DIR}/*.*

gen.root.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/usr/bin/env bash
22
cd "$(dirname "${BASH_SOURCE[0]}")"
33

4-
folder="./out"
5-
if [ ! -d "$folder" ]; then
6-
mkdir "$folder"
4+
if [ -f "out/root.crt" ]; then
5+
echo Root certificate already exists.
6+
exit 1
7+
fi
8+
9+
if [ ! -d "out" ]; then
10+
bash flush.sh
711
fi
812

913
# Generate root cert along with root key

0 commit comments

Comments
 (0)