Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
letsencrypt.sh
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
letsencrypt.sh
Commits
067d7ee4
Commit
067d7ee4
authored
Dec 07, 2015
by
Lukas Schauer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added import script (allows import of existing certificates from the original letsencrypt client)
parent
329acb58
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
import.sh
import.sh
+82
-0
No files found.
import.sh
0 → 100755
View file @
067d7ee4
#!/bin/bash
set
-e
set
-u
set
-o
pipefail
SCRIPTDIR
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
BASEDIR
=
"
${
SCRIPTDIR
}
"
LETSENCRYPT
=
"/etc/letsencrypt"
.
"
${
SCRIPTDIR
}
/config.sh"
if
[[
-e
"
${
BASEDIR
}
/domains.txt"
]]
;
then
DOMAINS_TXT
=
"
${
BASEDIR
}
/domains.txt"
elif
[[
-e
"
${
SCRIPTDIR
}
/domains.txt"
]]
;
then
DOMAINS_TXT
=
"
${
SCRIPTDIR
}
/domains.txt"
else
echo
"You have to create a domains.txt file listing the domains you want certificates for. Have a look at domains.txt.example."
echo
"For the purpose of this import script the file can be empty, but it has to exist."
exit
1
fi
for
certdir
in
"
${
LETSENCRYPT
}
/live/"
*
;
do
domain
=
"
$(
basename
"
${
certdir
}
"
)
"
echo
"Processing
${
domain
}
"
# Check if we already have a certificate for the same (main) domain
if
[
-e
"
${
BASEDIR
}
/certs/
${
domain
}
"
]
;
then
echo
" + Skipping: Found existing certificate directory, don't want to delete anything."
continue
fi
# Check if private-key, certificate and fullchain exist
if
[[
!
-e
"
${
certdir
}
/privkey.pem"
]]
;
then
echo
" + Skipping: Private key is missing."
continue
fi
if
[[
!
-e
"
${
certdir
}
/cert.pem"
]]
;
then
echo
" + Skipping: Certificate is missing."
continue
fi
if
[[
!
-e
"
${
certdir
}
/fullchain.pem"
]]
;
then
echo
" + Skipping: Chain is missing."
continue
fi
# Check if certificate still valid
set
+e
;
openssl x509
-checkend
0
-noout
-in
"
${
certdir
}
/cert.pem"
>
/dev/null 2> /dev/null
;
expired
=
"
${
?
}
"
;
set
-e
if
[[
"
${
expired
}
"
=
"1"
]]
;
then
echo
" + Skipping: Certificate is expired."
continue
fi
# Import certificate
timestamp
=
"
$(
date
+%s
)
"
echo
" + Adding list of domains to
${
DOMAINS_TXT
}
"
SAN
=
"
$(
openssl x509
-in
"
${
certdir
}
/cert.pem"
-noout
-text
|
grep
-A1
"Subject Alternative Name"
|
grep
"DNS"
)
"
SAN
=
"
${
SAN
//DNS
:/
}
"
SAN
=
"
${
SAN
//, /
}
"
altnames
=
"
${
domain
}
"
for
altname
in
${
SAN
}
;
do
if
[[
!
"
${
altname
}
"
=
"
${
domain
}
"
]]
;
then
altnames
=
"
${
altnames
}
${
altname
}
"
fi
done
echo
"
${
altnames
}
"
>>
"
${
DOMAINS_TXT
}
"
mkdir
-p
"
${
BASEDIR
}
/certs/
${
domain
}
"
echo
" + Importing private key"
cat
"
${
certdir
}
/privkey.pem"
>
"
${
BASEDIR
}
/certs/
${
domain
}
/privkey-
${
timestamp
}
.pem"
ln
-s
"privkey-
${
timestamp
}
.pem"
"
${
BASEDIR
}
/certs/
${
domain
}
/privkey.pem"
echo
" + Importing certificate"
cat
"
${
certdir
}
/cert.pem"
>
"
${
BASEDIR
}
/certs/
${
domain
}
/cert-
${
timestamp
}
.pem"
ln
-s
"cert-
${
timestamp
}
.pem"
"
${
BASEDIR
}
/certs/
${
domain
}
/cert.pem"
echo
" + Importing chain"
cat
"
${
certdir
}
/fullchain.pem"
>
"
${
BASEDIR
}
/certs/
${
domain
}
/fullchain-
${
timestamp
}
.pem"
ln
-s
"fullchain-
${
timestamp
}
.pem"
"
${
BASEDIR
}
/certs/
${
domain
}
/fullchain.pem"
done
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment