forked from freddy36/StartSSL_API
-
Notifications
You must be signed in to change notification settings - Fork 2
/
crtcopy
executable file
·28 lines (20 loc) · 882 Bytes
/
crtcopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python
# Copies a certificate and corresponding private key to clipboard, to be
# stored with the crtpaste tool on a server
#
import re,sys,subprocess
if len(sys.argv) < 2:
sys.exit("Please specify certificate nickname")
nick = sys.argv[1]
if len(sys.argv) == 2:
filelist = subprocess.check_output("ls -t %s_*.pem" % (nick), shell=True).splitlines()
datestamp = re.match(".*_([0-9]+)\.pem", filelist[0]).group(1)
else:
datestamp = sys.argv[2]
#print nick,datestamp
clipboard_copy = ""
if sys.platform == "darwin":
clipboard_copy = " | pbcopy"
elif sys.platform == "linux" or sys.platform == "linux2":
clipboard_copy = " | xclip"
subprocess.call("(echo \"{2:s}\"; cat {0:s}_cert_{1:s}.pem {0:s}_privatekey_{1:s}.pem; echo \"\\nDATENENDE\") {3}".format(nick,datestamp,"crtpaste <<DATENENDE\\nCERTDATA "+nick+" "+datestamp,clipboard_copy), shell=True)