You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1332 lines
33 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. #!/usr/bin/env bash
  2. VER=1.1.8
  3. PROJECT="https://github.com/Neilpang/le"
  4. DEFAULT_CA="https://acme-v01.api.letsencrypt.org"
  5. DEFAULT_AGREEMENT="https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf"
  6. STAGE_CA="https://acme-staging.api.letsencrypt.org"
  7. VTYPE_HTTP="http-01"
  8. VTYPE_DNS="dns-01"
  9. if [ -z "$AGREEMENT" ] ; then
  10. AGREEMENT="$DEFAULT_AGREEMENT"
  11. fi
  12. _debug() {
  13. if [ -z "$DEBUG" ] ; then
  14. return
  15. fi
  16. if [ -z "$2" ] ; then
  17. echo $1
  18. else
  19. echo "$1"="$2"
  20. fi
  21. }
  22. _info() {
  23. if [ -z "$2" ] ; then
  24. echo "$1"
  25. else
  26. echo "$1"="$2"
  27. fi
  28. }
  29. _err() {
  30. if [ -z "$2" ] ; then
  31. echo "$1" >&2
  32. else
  33. echo "$1"="$2" >&2
  34. fi
  35. return 1
  36. }
  37. _h2b() {
  38. hex=$(cat)
  39. i=1
  40. j=2
  41. while [ '1' ] ; do
  42. h=$(printf $hex | cut -c $i-$j)
  43. if [ -z "$h" ] ; then
  44. break;
  45. fi
  46. printf "\x$h"
  47. let "i+=2"
  48. let "j+=2"
  49. done
  50. }
  51. _base64() {
  52. openssl base64 -e | tr -d '\n'
  53. }
  54. #domain [2048]
  55. createAccountKey() {
  56. _info "Creating account key"
  57. if [ -z "$1" ] ; then
  58. echo Usage: createAccountKey account-domain [2048]
  59. return
  60. fi
  61. account=$1
  62. length=$2
  63. if [[ "$length" == "ec-"* ]] ; then
  64. length=2048
  65. fi
  66. if [ -z "$2" ] ; then
  67. _info "Use default length 2048"
  68. length=2048
  69. fi
  70. _initpath
  71. if [ -f "$ACCOUNT_KEY_PATH" ] ; then
  72. _info "Account key exists, skip"
  73. return
  74. else
  75. #generate account key
  76. openssl genrsa $length > "$ACCOUNT_KEY_PATH"
  77. fi
  78. }
  79. #domain length
  80. createDomainKey() {
  81. _info "Creating domain key"
  82. if [ -z "$1" ] ; then
  83. echo Usage: createDomainKey domain [2048]
  84. return
  85. fi
  86. domain=$1
  87. length=$2
  88. isec=""
  89. if [[ "$length" == "ec-"* ]] ; then
  90. isec="1"
  91. length=$(printf $length | cut -d '-' -f 2-100)
  92. eccname="$length"
  93. fi
  94. if [ -z "$length" ] ; then
  95. if [ "$isec" ] ; then
  96. length=256
  97. else
  98. length=2048
  99. fi
  100. fi
  101. _info "Use length $length"
  102. if [ "$isec" ] ; then
  103. if [ "$length" == "256" ] ; then
  104. eccname="prime256v1"
  105. fi
  106. if [ "$length" == "384" ] ; then
  107. eccname="secp384r1"
  108. fi
  109. if [ "$length" == "521" ] ; then
  110. eccname="secp521r1"
  111. fi
  112. _info "Using ec name: $eccname"
  113. fi
  114. _initpath $domain
  115. if [ ! -f "$CERT_KEY_PATH" ] || ( [ "$FORCE" ] && ! [ "$IS_RENEW" ] ); then
  116. #generate account key
  117. if [ "$isec" ] ; then
  118. openssl ecparam -name $eccname -genkey 2>/dev/null > "$CERT_KEY_PATH"
  119. else
  120. openssl genrsa $length 2>/dev/null > "$CERT_KEY_PATH"
  121. fi
  122. else
  123. if [ "$IS_RENEW" ] ; then
  124. _info "Domain key exists, skip"
  125. return 0
  126. else
  127. _err "Domain key exists, do you want to overwrite the key?"
  128. _err "Set FORCE=1, and try again."
  129. return 1
  130. fi
  131. fi
  132. }
  133. # domain domainlist
  134. createCSR() {
  135. _info "Creating csr"
  136. if [ -z "$1" ] ; then
  137. echo Usage: $0 domain [domainlist]
  138. return
  139. fi
  140. domain=$1
  141. _initpath $domain
  142. domainlist=$2
  143. if [ -f "$CSR_PATH" ] && [ "$IS_RENEW" ] && ! [ "$FORCE" ]; then
  144. _info "CSR exists, skip"
  145. return
  146. fi
  147. if [ -z "$domainlist" ] ; then
  148. #single domain
  149. _info "Single domain" $domain
  150. printf "[ req_distinguished_name ]\n[ req ]\ndistinguished_name = req_distinguished_name\n" > "$DOMAIN_SSL_CONF"
  151. openssl req -new -sha256 -key "$CERT_KEY_PATH" -subj "/CN=$domain" -config "$DOMAIN_SSL_CONF" -out "$CSR_PATH"
  152. else
  153. alt="DNS:$(echo $domainlist | sed "s/,/,DNS:/g")"
  154. #multi
  155. _info "Multi domain" "$alt"
  156. printf "[ req_distinguished_name ]\n[ req ]\ndistinguished_name = req_distinguished_name\n[SAN]\nsubjectAltName=$alt" > "$DOMAIN_SSL_CONF"
  157. openssl req -new -sha256 -key "$CERT_KEY_PATH" -subj "/CN=$domain" -reqexts SAN -config "$DOMAIN_SSL_CONF" -out "$CSR_PATH"
  158. fi
  159. }
  160. _b64() {
  161. __n=$(cat)
  162. echo $__n | tr '/+' '_-' | tr -d '= '
  163. }
  164. _time2str() {
  165. #BSD
  166. if date -u -d@$1 2>/dev/null ; then
  167. return
  168. fi
  169. #Linux
  170. if date -u -r $1 2>/dev/null ; then
  171. return
  172. fi
  173. }
  174. _stat() {
  175. #Linux
  176. if stat -c '%U:%G' "$1" 2>/dev/null ; then
  177. return
  178. fi
  179. #BSD
  180. if stat -f '%Su:%Sg' "$1" 2>/dev/null ; then
  181. return
  182. fi
  183. }
  184. _send_signed_request() {
  185. url=$1
  186. payload=$2
  187. needbase64=$3
  188. _debug url $url
  189. _debug payload "$payload"
  190. CURL_HEADER="$LE_WORKING_DIR/curl.header"
  191. dp="$LE_WORKING_DIR/curl.dump"
  192. CURL="curl --silent --dump-header $CURL_HEADER "
  193. if [ "$DEBUG" ] ; then
  194. CURL="$CURL --trace-ascii $dp "
  195. fi
  196. payload64=$(echo -n $payload | _base64 | _b64)
  197. _debug payload64 $payload64
  198. nonceurl="$API/directory"
  199. nonce="$($CURL -I $nonceurl | grep -o "^Replay-Nonce:.*$" | tr -d "\r\n" | cut -d ' ' -f 2)"
  200. _debug nonce "$nonce"
  201. protected="$(printf "$HEADERPLACE" | sed "s/NONCE/$nonce/" )"
  202. _debug protected "$protected"
  203. protected64="$(printf "$protected" | _base64 | _b64)"
  204. _debug protected64 "$protected64"
  205. sig=$(echo -n "$protected64.$payload64" | openssl dgst -sha256 -sign $ACCOUNT_KEY_PATH | _base64 | _b64)
  206. _debug sig "$sig"
  207. body="{\"header\": $HEADER, \"protected\": \"$protected64\", \"payload\": \"$payload64\", \"signature\": \"$sig\"}"
  208. _debug body "$body"
  209. if [ "$needbase64" ] ; then
  210. response="$($CURL -X POST --data "$body" $url | _base64)"
  211. else
  212. response="$($CURL -X POST --data "$body" $url)"
  213. fi
  214. responseHeaders="$(< $CURL_HEADER)"
  215. _debug responseHeaders "$responseHeaders"
  216. _debug response "$response"
  217. code="$(grep ^HTTP $CURL_HEADER | tail -1 | cut -d " " -f 2 | tr -d "\r\n" )"
  218. _debug code $code
  219. }
  220. _get() {
  221. url="$1"
  222. _debug url $url
  223. response="$(curl --silent $url)"
  224. ret=$?
  225. _debug response "$response"
  226. code="$(echo $response | grep -o '"status":[0-9]\+' | cut -d : -f 2)"
  227. _debug code $code
  228. return $ret
  229. }
  230. #setopt "file" "opt" "=" "value" [";"]
  231. _setopt() {
  232. __conf="$1"
  233. __opt="$2"
  234. __sep="$3"
  235. __val="$4"
  236. __end="$5"
  237. if [ -z "$__opt" ] ; then
  238. echo usage: _setopt '"file" "opt" "=" "value" [";"]'
  239. return
  240. fi
  241. if [ ! -f "$__conf" ] ; then
  242. touch "$__conf"
  243. fi
  244. if grep -H -n "^$__opt$__sep" "$__conf" > /dev/null ; then
  245. _debug OK
  246. if [[ "$__val" == *"&"* ]] ; then
  247. __val="$(echo $__val | sed 's/&/\\&/g')"
  248. fi
  249. text="$(< $__conf)"
  250. echo "$text" | sed "s|^$__opt$__sep.*$|$__opt$__sep$__val$__end|" > "$__conf"
  251. elif grep -H -n "^#$__opt$__sep" "$__conf" > /dev/null ; then
  252. if [[ "$__val" == *"&"* ]] ; then
  253. __val="$(echo $__val | sed 's/&/\\&/g')"
  254. fi
  255. text="$(< $__conf)"
  256. echo "$text" | sed "s|^#$__opt$__sep.*$|$__opt$__sep$__val$__end|" > "$__conf"
  257. else
  258. _debug APP
  259. echo "$__opt$__sep$__val$__end" >> "$__conf"
  260. fi
  261. _debug "$(grep -H -n "^$__opt$__sep" $__conf)"
  262. }
  263. #_savedomainconf key value
  264. #save to domain.conf
  265. _savedomainconf() {
  266. key="$1"
  267. value="$2"
  268. if [ "$DOMAIN_CONF" ] ; then
  269. _setopt $DOMAIN_CONF "$key" "=" "$value"
  270. else
  271. _err "DOMAIN_CONF is empty, can not save $key=$value"
  272. fi
  273. }
  274. #_saveaccountconf key value
  275. _saveaccountconf() {
  276. key="$1"
  277. value="$2"
  278. if [ "$ACCOUNT_CONF_PATH" ] ; then
  279. _setopt $ACCOUNT_CONF_PATH "$key" "=" "$value"
  280. else
  281. _err "ACCOUNT_CONF_PATH is empty, can not save $key=$value"
  282. fi
  283. }
  284. _startserver() {
  285. content="$1"
  286. _NC="nc -q 1"
  287. if nc -h 2>&1 | grep "nmap.org/ncat" >/dev/null ; then
  288. _NC="nc"
  289. fi
  290. # while true ; do
  291. if [ "$DEBUG" ] ; then
  292. echo -e -n "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC -l -p $Le_HTTPPort -vv
  293. else
  294. echo -e -n "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC -l -p $Le_HTTPPort > /dev/null
  295. fi
  296. # done
  297. }
  298. _stopserver() {
  299. pid="$1"
  300. }
  301. _initpath() {
  302. if [ -z "$LE_WORKING_DIR" ]; then
  303. LE_WORKING_DIR=$HOME/.le
  304. fi
  305. if [ -z "$ACCOUNT_CONF_PATH" ] ; then
  306. ACCOUNT_CONF_PATH="$LE_WORKING_DIR/account.conf"
  307. fi
  308. if [ -f "$ACCOUNT_CONF_PATH" ] ; then
  309. source "$ACCOUNT_CONF_PATH"
  310. fi
  311. if [ -z "$API" ] ; then
  312. if [ -z "$STAGE" ] ; then
  313. API="$DEFAULT_CA"
  314. else
  315. API="$STAGE_CA"
  316. _info "Using stage api:$API"
  317. fi
  318. fi
  319. if [ -z "$ACME_DIR" ] ; then
  320. ACME_DIR="/home/.acme"
  321. fi
  322. if [ -z "$APACHE_CONF_BACKUP_DIR" ] ; then
  323. APACHE_CONF_BACKUP_DIR="$LE_WORKING_DIR/"
  324. fi
  325. domain="$1"
  326. if ! mkdir -p "$LE_WORKING_DIR" ; then
  327. _err "Can not craete working dir: $LE_WORKING_DIR"
  328. return 1
  329. fi
  330. if [ -z "$ACCOUNT_KEY_PATH" ] ; then
  331. ACCOUNT_KEY_PATH="$LE_WORKING_DIR/account.key"
  332. fi
  333. if [ -z "$domain" ] ; then
  334. return 0
  335. fi
  336. domainhome="$LE_WORKING_DIR/$domain"
  337. mkdir -p "$domainhome"
  338. if [ -z "$DOMAIN_PATH" ] ; then
  339. DOMAIN_PATH="$domainhome"
  340. fi
  341. if [ -z "$DOMAIN_CONF" ] ; then
  342. DOMAIN_CONF="$domainhome/$domain.conf"
  343. fi
  344. if [ -z "$DOMAIN_SSL_CONF" ] ; then
  345. DOMAIN_SSL_CONF="$domainhome/$domain.ssl.conf"
  346. fi
  347. if [ -z "$CSR_PATH" ] ; then
  348. CSR_PATH="$domainhome/$domain.csr"
  349. fi
  350. if [ -z "$CERT_KEY_PATH" ] ; then
  351. CERT_KEY_PATH="$domainhome/$domain.key"
  352. fi
  353. if [ -z "$CERT_PATH" ] ; then
  354. CERT_PATH="$domainhome/$domain.cer"
  355. fi
  356. if [ -z "$CA_CERT_PATH" ] ; then
  357. CA_CERT_PATH="$domainhome/ca.cer"
  358. fi
  359. }
  360. _apachePath() {
  361. httpdroot="$(apachectl -V | grep HTTPD_ROOT= | cut -d = -f 2 | tr -d '"' )"
  362. httpdconfname="$(apachectl -V | grep SERVER_CONFIG_FILE= | cut -d = -f 2 | tr -d '"' )"
  363. httpdconf="$httpdroot/$httpdconfname"
  364. if [ ! -f $httpdconf ] ; then
  365. _err "Apache Config file not found" $httpdconf
  366. return 1
  367. fi
  368. return 0
  369. }
  370. _restoreApache() {
  371. if [ -z "$usingApache" ] ; then
  372. return 0
  373. fi
  374. _initpath
  375. if ! _apachePath ; then
  376. return 1
  377. fi
  378. if [ ! -f "$APACHE_CONF_BACKUP_DIR/$httpdconfname" ] ; then
  379. _debug "No config file to restore."
  380. return 0
  381. fi
  382. cp -p "$APACHE_CONF_BACKUP_DIR/$httpdconfname" "$httpdconf"
  383. if ! apachectl -t ; then
  384. _err "Sorry, restore apache config error, please contact me."
  385. return 1;
  386. fi
  387. rm -f "$APACHE_CONF_BACKUP_DIR/$httpdconfname"
  388. return 0
  389. }
  390. _setApache() {
  391. _initpath
  392. if ! _apachePath ; then
  393. return 1
  394. fi
  395. #backup the conf
  396. _debug "Backup apache config file" $httpdconf
  397. cp -p $httpdconf $APACHE_CONF_BACKUP_DIR/
  398. _info "JFYI, Config file $httpdconf is backuped to $APACHE_CONF_BACKUP_DIR/$httpdconfname"
  399. _info "In case there is an error that can not be restored automatically, you may try restore it yourself."
  400. _info "The backup file will be deleted on sucess, just forget it."
  401. #add alias
  402. echo "
  403. Alias /.well-known/acme-challenge $ACME_DIR
  404. <Directory $ACME_DIR >
  405. Require all granted
  406. </Directory>
  407. " >> $httpdconf
  408. if ! apachectl -t ; then
  409. _err "Sorry, apache config error, please contact me."
  410. _restoreApache
  411. return 1;
  412. fi
  413. if [ ! -d "$ACME_DIR" ] ; then
  414. mkdir -p "$ACME_DIR"
  415. chmod 755 "$ACME_DIR"
  416. fi
  417. if ! apachectl graceful ; then
  418. _err "Sorry, apachectl graceful error, please contact me."
  419. _restoreApache
  420. return 1;
  421. fi
  422. usingApache="1"
  423. return 0
  424. }
  425. _clearup () {
  426. _stopserver $serverproc
  427. serverproc=""
  428. _restoreApache
  429. }
  430. # webroot removelevel tokenfile
  431. _clearupwebbroot() {
  432. __webroot="$1"
  433. if [ -z "$__webroot" ] ; then
  434. _debug "no webroot specified, skip"
  435. return 0
  436. fi
  437. if [ "$2" == '1' ] ; then
  438. _debug "remove $__webroot/.well-known"
  439. rm -rf "$__webroot/.well-known"
  440. elif [ "$2" == '2' ] ; then
  441. _debug "remove $__webroot/.well-known/acme-challenge"
  442. rm -rf "$__webroot/.well-known/acme-challenge"
  443. elif [ "$2" == '3' ] ; then
  444. _debug "remove $__webroot/.well-known/acme-challenge/$3"
  445. rm -rf "$__webroot/.well-known/acme-challenge/$3"
  446. else
  447. _info "Skip for removelevel:$2"
  448. fi
  449. return 0
  450. }
  451. issue() {
  452. if [ -z "$2" ] ; then
  453. _err "Usage: le issue webroot|no|apache|dns a.com [www.a.com,b.com,c.com]|no [key-length]|no"
  454. return 1
  455. fi
  456. Le_Webroot="$1"
  457. Le_Domain="$2"
  458. Le_Alt="$3"
  459. Le_Keylength="$4"
  460. Le_RealCertPath="$5"
  461. Le_RealKeyPath="$6"
  462. Le_RealCACertPath="$7"
  463. Le_ReloadCmd="$8"
  464. _initpath $Le_Domain
  465. if [ -f "$DOMAIN_CONF" ] ; then
  466. Le_NextRenewTime=$(grep "^Le_NextRenewTime=" "$DOMAIN_CONF" | cut -d '=' -f 2)
  467. if [ -z "$FORCE" ] && [ "$Le_NextRenewTime" ] && [ "$(date -u "+%s" )" -lt "$Le_NextRenewTime" ] ; then
  468. _info "Skip, Next renewal time is: $(grep "^Le_NextRenewTimeStr" "$DOMAIN_CONF" | cut -d '=' -f 2)"
  469. return 2
  470. fi
  471. fi
  472. if [ "$Le_Alt" == "no" ] ; then
  473. Le_Alt=""
  474. fi
  475. if [ "$Le_Keylength" == "no" ] ; then
  476. Le_Keylength=""
  477. fi
  478. if [ "$Le_RealCertPath" == "no" ] ; then
  479. Le_RealCertPath=""
  480. fi
  481. if [ "$Le_RealKeyPath" == "no" ] ; then
  482. Le_RealKeyPath=""
  483. fi
  484. if [ "$Le_RealCACertPath" == "no" ] ; then
  485. Le_RealCACertPath=""
  486. fi
  487. if [ "$Le_ReloadCmd" == "no" ] ; then
  488. Le_ReloadCmd=""
  489. fi
  490. _setopt "$DOMAIN_CONF" "Le_Domain" "=" "$Le_Domain"
  491. _setopt "$DOMAIN_CONF" "Le_Alt" "=" "$Le_Alt"
  492. _setopt "$DOMAIN_CONF" "Le_Webroot" "=" "$Le_Webroot"
  493. _setopt "$DOMAIN_CONF" "Le_Keylength" "=" "$Le_Keylength"
  494. _setopt "$DOMAIN_CONF" "Le_RealCertPath" "=" "\"$Le_RealCertPath\""
  495. _setopt "$DOMAIN_CONF" "Le_RealCACertPath" "=" "\"$Le_RealCACertPath\""
  496. _setopt "$DOMAIN_CONF" "Le_RealKeyPath" "=" "\"$Le_RealKeyPath\""
  497. _setopt "$DOMAIN_CONF" "Le_ReloadCmd" "=" "\"$Le_ReloadCmd\""
  498. if [ "$Le_Webroot" == "no" ] ; then
  499. _info "Standalone mode."
  500. if ! command -v "nc" > /dev/null ; then
  501. _err "Please install netcat(nc) tools first."
  502. return 1
  503. fi
  504. if [ -z "$Le_HTTPPort" ] ; then
  505. Le_HTTPPort=80
  506. fi
  507. _setopt "$DOMAIN_CONF" "Le_HTTPPort" "=" "$Le_HTTPPort"
  508. netprc="$(ss -ntpl | grep :$Le_HTTPPort" ")"
  509. if [ "$netprc" ] ; then
  510. _err "$netprc"
  511. _err "tcp port $Le_HTTPPort is already used by $(echo "$netprc" | cut -d : -f 4)"
  512. _err "Please stop it first"
  513. return 1
  514. fi
  515. fi
  516. if [ "$Le_Webroot" == "apache" ] ; then
  517. if ! _setApache ; then
  518. _err "set up apache error. Report error to me."
  519. return 1
  520. fi
  521. wellknown_path="$ACME_DIR"
  522. else
  523. usingApache=""
  524. fi
  525. createAccountKey $Le_Domain $Le_Keylength
  526. if ! createDomainKey $Le_Domain $Le_Keylength ; then
  527. _err "Create domain key error."
  528. return 1
  529. fi
  530. if ! createCSR $Le_Domain $Le_Alt ; then
  531. _err "Create CSR error."
  532. return 1
  533. fi
  534. pub_exp=$(openssl rsa -in $ACCOUNT_KEY_PATH -noout -text | grep "^publicExponent:"| cut -d '(' -f 2 | cut -d 'x' -f 2 | cut -d ')' -f 1)
  535. if [ "${#pub_exp}" == "5" ] ; then
  536. pub_exp=0$pub_exp
  537. fi
  538. _debug pub_exp "$pub_exp"
  539. e=$(echo $pub_exp | _h2b | _base64)
  540. _debug e "$e"
  541. modulus=$(openssl rsa -in $ACCOUNT_KEY_PATH -modulus -noout | cut -d '=' -f 2 )
  542. n=$(echo $modulus| _h2b | _base64 | _b64 )
  543. jwk='{"e": "'$e'", "kty": "RSA", "n": "'$n'"}'
  544. HEADER='{"alg": "RS256", "jwk": '$jwk'}'
  545. HEADERPLACE='{"nonce": "NONCE", "alg": "RS256", "jwk": '$jwk'}'
  546. _debug HEADER "$HEADER"
  547. accountkey_json=$(echo -n "$jwk" | tr -d ' ' )
  548. thumbprint=$(echo -n "$accountkey_json" | openssl dgst -sha256 -binary | _base64 | _b64)
  549. _info "Registering account"
  550. regjson='{"resource": "new-reg", "agreement": "'$AGREEMENT'"}'
  551. if [ "$ACCOUNT_EMAIL" ] ; then
  552. regjson='{"resource": "new-reg", "contact": ["mailto: '$ACCOUNT_EMAIL'"], "agreement": "'$AGREEMENT'"}'
  553. fi
  554. _send_signed_request "$API/acme/new-reg" "$regjson"
  555. if [ "$code" == "" ] || [ "$code" == '201' ] ; then
  556. _info "Registered"
  557. echo $response > $LE_WORKING_DIR/account.json
  558. elif [ "$code" == '409' ] ; then
  559. _info "Already registered"
  560. else
  561. _err "Register account Error."
  562. _clearup
  563. return 1
  564. fi
  565. vtype="$VTYPE_HTTP"
  566. if [[ "$Le_Webroot" == "dns"* ]] ; then
  567. vtype="$VTYPE_DNS"
  568. fi
  569. vlist="$Le_Vlist"
  570. # verify each domain
  571. _info "Verify each domain"
  572. sep='#'
  573. if [ -z "$vlist" ] ; then
  574. alldomains=$(echo "$Le_Domain,$Le_Alt" | tr ',' ' ' )
  575. for d in $alldomains
  576. do
  577. _info "Getting token for domain" $d
  578. _send_signed_request "$API/acme/new-authz" "{\"resource\": \"new-authz\", \"identifier\": {\"type\": \"dns\", \"value\": \"$d\"}}"
  579. if [ ! -z "$code" ] && [ ! "$code" == '201' ] ; then
  580. _err "new-authz error: $response"
  581. _clearup
  582. return 1
  583. fi
  584. entry="$(printf $response | egrep -o '{[^{]*"type":"'$vtype'"[^}]*')"
  585. _debug entry "$entry"
  586. token="$(printf "$entry" | egrep -o '"token":"[^"]*' | cut -d : -f 2 | tr -d '"')"
  587. _debug token $token
  588. uri="$(printf "$entry" | egrep -o '"uri":"[^"]*'| cut -d : -f 2,3 | tr -d '"' )"
  589. _debug uri $uri
  590. keyauthorization="$token.$thumbprint"
  591. _debug keyauthorization "$keyauthorization"
  592. dvlist="$d$sep$keyauthorization$sep$uri"
  593. _debug dvlist "$dvlist"
  594. vlist="$vlist$dvlist,"
  595. done
  596. #add entry
  597. dnsadded=""
  598. ventries=$(echo "$vlist" | tr ',' ' ' )
  599. for ventry in $ventries
  600. do
  601. d=$(echo $ventry | cut -d $sep -f 1)
  602. keyauthorization=$(echo $ventry | cut -d $sep -f 2)
  603. if [ "$vtype" == "$VTYPE_DNS" ] ; then
  604. dnsadded='0'
  605. txtdomain="_acme-challenge.$d"
  606. _debug txtdomain "$txtdomain"
  607. txt="$(echo -e -n $keyauthorization | openssl dgst -sha256 -binary | _base64 | _b64)"
  608. _debug txt "$txt"
  609. #dns
  610. #1. check use api
  611. d_api=""
  612. if [ -f "$LE_WORKING_DIR/$d/$Le_Webroot" ] ; then
  613. d_api="$LE_WORKING_DIR/$d/$Le_Webroot"
  614. elif [ -f "$LE_WORKING_DIR/$d/$Le_Webroot.sh" ] ; then
  615. d_api="$LE_WORKING_DIR/$d/$Le_Webroot.sh"
  616. elif [ -f "$LE_WORKING_DIR/$Le_Webroot" ] ; then
  617. d_api="$LE_WORKING_DIR/$Le_Webroot"
  618. elif [ -f "$LE_WORKING_DIR/$Le_Webroot.sh" ] ; then
  619. d_api="$LE_WORKING_DIR/$Le_Webroot.sh"
  620. elif [ -f "$LE_WORKING_DIR/dnsapi/$Le_Webroot" ] ; then
  621. d_api="$LE_WORKING_DIR/dnsapi/$Le_Webroot"
  622. elif [ -f "$LE_WORKING_DIR/dnsapi/$Le_Webroot.sh" ] ; then
  623. d_api="$LE_WORKING_DIR/dnsapi/$Le_Webroot.sh"
  624. fi
  625. _debug d_api "$d_api"
  626. if [ "$d_api" ]; then
  627. _info "Found domain api file: $d_api"
  628. else
  629. _err "Add the following TXT record:"
  630. _err "Domain: $txtdomain"
  631. _err "TXT value: $txt"
  632. _err "Please be aware that you prepend _acme-challenge. before your domain"
  633. _err "so the resulting subdomain will be: $txtdomain"
  634. continue
  635. fi
  636. if ! source $d_api ; then
  637. _err "Load file $d_api error. Please check your api file and try again."
  638. return 1
  639. fi
  640. addcommand="$Le_Webroot-add"
  641. if ! command -v $addcommand ; then
  642. _err "It seems that your api file is not correct, it must have a function named: $Le_Webroot"
  643. return 1
  644. fi
  645. if ! $addcommand $txtdomain $txt ; then
  646. _err "Error add txt for domain:$txtdomain"
  647. return 1
  648. fi
  649. dnsadded='1'
  650. fi
  651. done
  652. if [ "$dnsadded" == '0' ] ; then
  653. _setopt "$DOMAIN_CONF" "Le_Vlist" "=" "\"$vlist\""
  654. _debug "Dns record not added yet, so, save to $DOMAIN_CONF and exit."
  655. _err "Please add the TXT records to the domains, and retry again."
  656. return 1
  657. fi
  658. fi
  659. if [ "$dnsadded" == '1' ] ; then
  660. _info "Sleep 60 seconds for the txt records to take effect"
  661. sleep 60
  662. fi
  663. _debug "ok, let's start to verify"
  664. ventries=$(echo "$vlist" | tr ',' ' ' )
  665. for ventry in $ventries
  666. do
  667. d=$(echo $ventry | cut -d $sep -f 1)
  668. keyauthorization=$(echo $ventry | cut -d $sep -f 2)
  669. uri=$(echo $ventry | cut -d $sep -f 3)
  670. _info "Verifying:$d"
  671. _debug "d" "$d"
  672. _debug "keyauthorization" "$keyauthorization"
  673. _debug "uri" "$uri"
  674. removelevel=""
  675. token=""
  676. if [ "$vtype" == "$VTYPE_HTTP" ] ; then
  677. if [ "$Le_Webroot" == "no" ] ; then
  678. _info "Standalone mode server"
  679. _startserver "$keyauthorization" &
  680. serverproc="$!"
  681. sleep 2
  682. _debug serverproc $serverproc
  683. else
  684. if [ -z "$wellknown_path" ] ; then
  685. wellknown_path="$Le_Webroot/.well-known/acme-challenge"
  686. fi
  687. _debug wellknown_path "$wellknown_path"
  688. if [ ! -d "$Le_Webroot/.well-known" ] ; then
  689. removelevel='1'
  690. elif [ ! -d "$Le_Webroot/.well-known/acme-challenge" ] ; then
  691. removelevel='2'
  692. else
  693. removelevel='3'
  694. fi
  695. token="$(echo -e -n "$keyauthorization" | cut -d '.' -f 1)"
  696. _debug "writing token:$token to $wellknown_path/$token"
  697. mkdir -p "$wellknown_path"
  698. echo -n "$keyauthorization" > "$wellknown_path/$token"
  699. webroot_owner=$(_stat $Le_Webroot)
  700. _debug "Changing owner/group of .well-known to $webroot_owner"
  701. chown -R $webroot_owner "$Le_Webroot/.well-known"
  702. fi
  703. fi
  704. _send_signed_request $uri "{\"resource\": \"challenge\", \"keyAuthorization\": \"$keyauthorization\"}"
  705. if [ ! -z "$code" ] && [ ! "$code" == '202' ] ; then
  706. _err "$d:Challenge error: $resource"
  707. _clearupwebbroot "$Le_Webroot" "$removelevel" "$token"
  708. _clearup
  709. return 1
  710. fi
  711. while [ "1" ] ; do
  712. _debug "sleep 5 secs to verify"
  713. sleep 5
  714. _debug "checking"
  715. if ! _get $uri ; then
  716. _err "$d:Verify error:$resource"
  717. _clearupwebbroot "$Le_Webroot" "$removelevel" "$token"
  718. _clearup
  719. return 1
  720. fi
  721. status=$(echo $response | egrep -o '"status":"[^"]+"' | cut -d : -f 2 | tr -d '"')
  722. if [ "$status" == "valid" ] ; then
  723. _info "Success"
  724. _stopserver $serverproc
  725. serverproc=""
  726. _clearupwebbroot "$Le_Webroot" "$removelevel" "$token"
  727. break;
  728. fi
  729. if [ "$status" == "invalid" ] ; then
  730. error=$(echo $response | egrep -o '"error":{[^}]*}' | grep -o '"detail":"[^"]*"' | cut -d '"' -f 4)
  731. _err "$d:Verify error:$error"
  732. _clearupwebbroot "$Le_Webroot" "$removelevel" "$token"
  733. _clearup
  734. return 1;
  735. fi
  736. if [ "$status" == "pending" ] ; then
  737. _info "Pending"
  738. else
  739. _err "$d:Verify error:$response"
  740. _clearupwebbroot "$Le_Webroot" "$removelevel" "$token"
  741. _clearup
  742. return 1
  743. fi
  744. done
  745. done
  746. _clearup
  747. _info "Verify finished, start to sign."
  748. der="$(openssl req -in $CSR_PATH -outform DER | _base64 | _b64)"
  749. _send_signed_request "$API/acme/new-cert" "{\"resource\": \"new-cert\", \"csr\": \"$der\"}" "needbase64"
  750. Le_LinkCert="$(grep -i -o '^Location.*$' $CURL_HEADER | tr -d "\r\n" | cut -d " " -f 2)"
  751. _setopt "$DOMAIN_CONF" "Le_LinkCert" "=" "$Le_LinkCert"
  752. if [ "$Le_LinkCert" ] ; then
  753. echo -----BEGIN CERTIFICATE----- > "$CERT_PATH"
  754. curl --silent "$Le_LinkCert" | openssl base64 -e >> "$CERT_PATH"
  755. echo -----END CERTIFICATE----- >> "$CERT_PATH"
  756. _info "Cert success."
  757. cat "$CERT_PATH"
  758. _info "Your cert is in $CERT_PATH"
  759. fi
  760. if [ -z "$Le_LinkCert" ] ; then
  761. response="$(echo $response | openssl base64 -d -A)"
  762. _err "Sign failed: $(echo "$response" | grep -o '"detail":"[^"]*"')"
  763. return 1
  764. fi
  765. _setopt "$DOMAIN_CONF" 'Le_Vlist' '=' "\"\""
  766. Le_LinkIssuer=$(grep -i '^Link' $CURL_HEADER | cut -d " " -f 2| cut -d ';' -f 1 | tr -d '<>' )
  767. _setopt "$DOMAIN_CONF" "Le_LinkIssuer" "=" "$Le_LinkIssuer"
  768. if [ "$Le_LinkIssuer" ] ; then
  769. echo -----BEGIN CERTIFICATE----- > "$CA_CERT_PATH"
  770. curl --silent "$Le_LinkIssuer" | openssl base64 -e >> "$CA_CERT_PATH"
  771. echo -----END CERTIFICATE----- >> "$CA_CERT_PATH"
  772. _info "The intermediate CA cert is in $CA_CERT_PATH"
  773. fi
  774. Le_CertCreateTime=$(date -u "+%s")
  775. _setopt "$DOMAIN_CONF" "Le_CertCreateTime" "=" "$Le_CertCreateTime"
  776. Le_CertCreateTimeStr=$(date -u )
  777. _setopt "$DOMAIN_CONF" "Le_CertCreateTimeStr" "=" "\"$Le_CertCreateTimeStr\""
  778. if [ ! "$Le_RenewalDays" ] ; then
  779. Le_RenewalDays=80
  780. fi
  781. _setopt "$DOMAIN_CONF" "Le_RenewalDays" "=" "$Le_RenewalDays"
  782. let "Le_NextRenewTime=Le_CertCreateTime+Le_RenewalDays*24*60*60"
  783. _setopt "$DOMAIN_CONF" "Le_NextRenewTime" "=" "$Le_NextRenewTime"
  784. Le_NextRenewTimeStr=$( _time2str $Le_NextRenewTime )
  785. _setopt "$DOMAIN_CONF" "Le_NextRenewTimeStr" "=" "\"$Le_NextRenewTimeStr\""
  786. installcert $Le_Domain "$Le_RealCertPath" "$Le_RealKeyPath" "$Le_RealCACertPath" "$Le_ReloadCmd"
  787. }
  788. renew() {
  789. Le_Domain="$1"
  790. if [ -z "$Le_Domain" ] ; then
  791. _err "Usage: $0 domain.com"
  792. return 1
  793. fi
  794. _initpath $Le_Domain
  795. if [ ! -f "$DOMAIN_CONF" ] ; then
  796. _info "$Le_Domain is not a issued domain, skip."
  797. return 0;
  798. fi
  799. source "$DOMAIN_CONF"
  800. if [ -z "$FORCE" ] && [ "$Le_NextRenewTime" ] && [ "$(date -u "+%s" )" -lt "$Le_NextRenewTime" ] ; then
  801. _info "Skip, Next renewal time is: $Le_NextRenewTimeStr"
  802. return 2
  803. fi
  804. IS_RENEW="1"
  805. issue "$Le_Webroot" "$Le_Domain" "$Le_Alt" "$Le_Keylength" "$Le_RealCertPath" "$Le_RealKeyPath" "$Le_RealCACertPath" "$Le_ReloadCmd"
  806. local res=$?
  807. IS_RENEW=""
  808. return $res
  809. }
  810. renewAll() {
  811. _initpath
  812. _info "renewAll"
  813. for d in $(ls -F $LE_WORKING_DIR | grep [^.].*[.].*/$ ) ; do
  814. d=$(echo $d | cut -d '/' -f 1)
  815. _info "renew $d"
  816. Le_LinkCert=""
  817. Le_Domain=""
  818. Le_Alt=""
  819. Le_Webroot=""
  820. Le_Keylength=""
  821. Le_LinkIssuer=""
  822. Le_CertCreateTime=""
  823. Le_CertCreateTimeStr=""
  824. Le_RenewalDays=""
  825. Le_NextRenewTime=""
  826. Le_NextRenewTimeStr=""
  827. Le_RealCertPath=""
  828. Le_RealKeyPath=""
  829. Le_RealCACertPath=""
  830. Le_ReloadCmd=""
  831. DOMAIN_PATH=""
  832. DOMAIN_CONF=""
  833. DOMAIN_SSL_CONF=""
  834. CSR_PATH=""
  835. CERT_KEY_PATH=""
  836. CERT_PATH=""
  837. CA_CERT_PATH=""
  838. ACCOUNT_KEY_PATH=""
  839. wellknown_path=""
  840. renew "$d"
  841. done
  842. }
  843. installcert() {
  844. Le_Domain="$1"
  845. if [ -z "$Le_Domain" ] ; then
  846. _err "Usage: $0 domain.com [cert-file-path]|no [key-file-path]|no [ca-cert-file-path]|no [reloadCmd]|no"
  847. return 1
  848. fi
  849. Le_RealCertPath="$2"
  850. Le_RealKeyPath="$3"
  851. Le_RealCACertPath="$4"
  852. Le_ReloadCmd="$5"
  853. _initpath $Le_Domain
  854. _setopt "$DOMAIN_CONF" "Le_RealCertPath" "=" "\"$Le_RealCertPath\""
  855. _setopt "$DOMAIN_CONF" "Le_RealCACertPath" "=" "\"$Le_RealCACertPath\""
  856. _setopt "$DOMAIN_CONF" "Le_RealKeyPath" "=" "\"$Le_RealKeyPath\""
  857. _setopt "$DOMAIN_CONF" "Le_ReloadCmd" "=" "\"$Le_ReloadCmd\""
  858. if [ "$Le_RealCertPath" ] ; then
  859. if [ -f "$Le_RealCertPath" ] ; then
  860. cp -p "$Le_RealCertPath" "$Le_RealCertPath".bak
  861. fi
  862. cat "$CERT_PATH" > "$Le_RealCertPath"
  863. fi
  864. if [ "$Le_RealCACertPath" ] ; then
  865. if [ -f "$Le_RealCACertPath" ] ; then
  866. cp -p "$Le_RealCACertPath" "$Le_RealCACertPath".bak
  867. fi
  868. if [ "$Le_RealCACertPath" == "$Le_RealCertPath" ] ; then
  869. echo "" >> "$Le_RealCACertPath"
  870. cat "$CA_CERT_PATH" >> "$Le_RealCACertPath"
  871. else
  872. cat "$CA_CERT_PATH" > "$Le_RealCACertPath"
  873. fi
  874. fi
  875. if [ "$Le_RealKeyPath" ] ; then
  876. if [ -f "$Le_RealKeyPath" ] ; then
  877. cp -p "$Le_RealKeyPath" "$Le_RealKeyPath".bak
  878. fi
  879. cat "$CERT_KEY_PATH" > "$Le_RealKeyPath"
  880. fi
  881. if [ "$Le_ReloadCmd" ] ; then
  882. _info "Run Le_ReloadCmd: $Le_ReloadCmd"
  883. (cd "$DOMAIN_PATH" && eval "$Le_ReloadCmd")
  884. fi
  885. }
  886. installcronjob() {
  887. _initpath
  888. _info "Installing cron job"
  889. if ! crontab -l | grep 'le.sh cron' ; then
  890. if [ -f "$LE_WORKING_DIR/le.sh" ] ; then
  891. lesh="\"$LE_WORKING_DIR\"/le.sh"
  892. else
  893. _err "Can not install cronjob, le.sh not found."
  894. return 1
  895. fi
  896. crontab -l | { cat; echo "0 0 * * * LE_WORKING_DIR=\"$LE_WORKING_DIR\" $lesh cron > /dev/null"; } | crontab -
  897. fi
  898. if [ "$?" != "0" ] ; then
  899. _err "Install cron job failed. You need to manually renew your certs."
  900. _err "Or you can add cronjob by yourself:"
  901. _err "LE_WORKING_DIR=\"$LE_WORKING_DIR\" $lesh cron > /dev/null"
  902. return 1
  903. fi
  904. }
  905. uninstallcronjob() {
  906. _info "Removing cron job"
  907. cr="$(crontab -l | grep 'le.sh cron')"
  908. if [ "$cr" ] ; then
  909. crontab -l | sed "/le.sh cron/d" | crontab -
  910. LE_WORKING_DIR="$(echo "$cr" | cut -d ' ' -f 6 | cut -d '=' -f 2 | tr -d '"')"
  911. _info LE_WORKING_DIR "$LE_WORKING_DIR"
  912. fi
  913. _initpath
  914. }
  915. # Detect profile file if not specified as environment variable
  916. _detect_profile() {
  917. if [ -n "$PROFILE" -a -f "$PROFILE" ]; then
  918. echo "$PROFILE"
  919. return
  920. fi
  921. local DETECTED_PROFILE
  922. DETECTED_PROFILE=''
  923. local SHELLTYPE
  924. SHELLTYPE="$(basename "/$SHELL")"
  925. if [ "$SHELLTYPE" = "bash" ]; then
  926. if [ -f "$HOME/.bashrc" ]; then
  927. DETECTED_PROFILE="$HOME/.bashrc"
  928. elif [ -f "$HOME/.bash_profile" ]; then
  929. DETECTED_PROFILE="$HOME/.bash_profile"
  930. fi
  931. elif [ "$SHELLTYPE" = "zsh" ]; then
  932. DETECTED_PROFILE="$HOME/.zshrc"
  933. fi
  934. if [ -z "$DETECTED_PROFILE" ]; then
  935. if [ -f "$HOME/.profile" ]; then
  936. DETECTED_PROFILE="$HOME/.profile"
  937. elif [ -f "$HOME/.bashrc" ]; then
  938. DETECTED_PROFILE="$HOME/.bashrc"
  939. elif [ -f "$HOME/.bash_profile" ]; then
  940. DETECTED_PROFILE="$HOME/.bash_profile"
  941. elif [ -f "$HOME/.zshrc" ]; then
  942. DETECTED_PROFILE="$HOME/.zshrc"
  943. fi
  944. fi
  945. if [ ! -z "$DETECTED_PROFILE" ]; then
  946. echo "$DETECTED_PROFILE"
  947. fi
  948. }
  949. _initconf() {
  950. _initpath
  951. if [ ! -f "$ACCOUNT_CONF_PATH" ] ; then
  952. echo "#Account configurations:
  953. #Here are the supported macros, uncomment them to make them take effect.
  954. #ACCOUNT_EMAIL=aaa@aaa.com # the account email used to register account.
  955. #ACCOUNT_KEY_PATH=\"/path/to/account.key\"
  956. #STAGE=1 # Use the staging api
  957. #FORCE=1 # Force to issue cert
  958. #DEBUG=1 # Debug mode
  959. #dns api
  960. #######################
  961. #Cloudflare:
  962. #api key
  963. #CF_Key=\"sdfsdfsdfljlbjkljlkjsdfoiwje\"
  964. #account email
  965. #CF_Email=\"xxxx@sss.com\"
  966. #######################
  967. #Dnspod.cn:
  968. #api key id
  969. #DP_Id=\"1234\"
  970. #api key
  971. #DP_Key=\"sADDsdasdgdsf\"
  972. #######################
  973. #Cloudxns.com:
  974. #CX_Key=\"1234\"
  975. #
  976. #CX_Secret=\"sADDsdasdgdsf\"
  977. " > $ACCOUNT_CONF_PATH
  978. fi
  979. }
  980. install() {
  981. if ! _initpath ; then
  982. _err "Install failed."
  983. return 1
  984. fi
  985. #check if there is sudo installed, AND if the current user is a sudoer.
  986. if command -v sudo > /dev/null ; then
  987. if [ "$(sudo -n uptime 2>&1|grep "load"|wc -l)" != "0" ] ; then
  988. SUDO=sudo
  989. fi
  990. fi
  991. if command -v yum > /dev/null ; then
  992. YUM="1"
  993. INSTALL="$SUDO yum install -y "
  994. elif command -v apt-get > /dev/null ; then
  995. INSTALL="$SUDO apt-get install -y "
  996. fi
  997. if ! command -v "curl" > /dev/null ; then
  998. _err "Please install curl first."
  999. _err "$INSTALL curl"
  1000. return 1
  1001. fi
  1002. if ! command -v "crontab" > /dev/null ; then
  1003. _err "Please install crontab first."
  1004. if [ "$YUM" ] ; then
  1005. _err "$INSTALL crontabs"
  1006. else
  1007. _err "$INSTALL crontab"
  1008. fi
  1009. return 1
  1010. fi
  1011. if ! command -v "openssl" > /dev/null ; then
  1012. _err "Please install openssl first."
  1013. _err "$INSTALL openssl"
  1014. return 1
  1015. fi
  1016. _info "Installing to $LE_WORKING_DIR"
  1017. cp le.sh "$LE_WORKING_DIR/" && chmod +x "$LE_WORKING_DIR/le.sh"
  1018. if [ "$?" != "0" ] ; then
  1019. _err "Install failed, can not copy le.sh"
  1020. return 1
  1021. fi
  1022. _info "Installed to $LE_WORKING_DIR/le.sh"
  1023. _profile="$(_detect_profile)"
  1024. if [ "$_profile" ] ; then
  1025. _debug "Found profile: $_profile"
  1026. echo "LE_WORKING_DIR=$LE_WORKING_DIR
  1027. alias le=\"$LE_WORKING_DIR/le.sh\"
  1028. alias le.sh=\"$LE_WORKING_DIR/le.sh\"
  1029. " > "$LE_WORKING_DIR/le.env"
  1030. echo "" >> "$_profile"
  1031. _setopt "$_profile" "source \"$LE_WORKING_DIR/le.env\""
  1032. _info "OK, Close and reopen your terminal to start using le"
  1033. else
  1034. _info "No profile is found, you will need to go into $LE_WORKING_DIR to use le.sh"
  1035. fi
  1036. mkdir -p $LE_WORKING_DIR/dnsapi
  1037. cp dnsapi/* $LE_WORKING_DIR/dnsapi/
  1038. #to keep compatible mv the .acc file to .key file
  1039. if [ -f "$LE_WORKING_DIR/account.acc" ] ; then
  1040. mv "$LE_WORKING_DIR/account.acc" "$LE_WORKING_DIR/account.key"
  1041. fi
  1042. installcronjob
  1043. if [ ! -f "$ACCOUNT_CONF_PATH" ] ; then
  1044. _initconf
  1045. fi
  1046. _info OK
  1047. }
  1048. uninstall() {
  1049. uninstallcronjob
  1050. _initpath
  1051. _profile="$(_detect_profile)"
  1052. if [ "$_profile" ] ; then
  1053. text="$(< $_profile)"
  1054. echo "$text" | sed "s|^source.*le.env.*$||" > "$_profile"
  1055. fi
  1056. rm -f $LE_WORKING_DIR/le.sh
  1057. _info "The keys and certs are in $LE_WORKING_DIR, you can remove them by yourself."
  1058. }
  1059. cron() {
  1060. renewAll
  1061. }
  1062. version() {
  1063. _info "$PROJECT"
  1064. _info "v$VER"
  1065. }
  1066. showhelp() {
  1067. version
  1068. echo "Usage: le.sh [command] ...[args]....
  1069. Avalible commands:
  1070. install:
  1071. Install le.sh to your system.
  1072. issue:
  1073. Issue a cert.
  1074. installcert:
  1075. Install the issued cert to apache/nginx or any other server.
  1076. renew:
  1077. Renew a cert.
  1078. renewAll:
  1079. Renew all the certs.
  1080. uninstall:
  1081. Uninstall le.sh, and uninstall the cron job.
  1082. version:
  1083. Show version info.
  1084. installcronjob:
  1085. Install the cron job to renew certs, you don't need to call this. The 'install' command can automatically install the cron job.
  1086. uninstallcronjob:
  1087. Uninstall the cron job. The 'uninstall' command can do this automatically.
  1088. createAccountKey:
  1089. Create an account private key, professional use.
  1090. createDomainKey:
  1091. Create an domain private key, professional use.
  1092. createCSR:
  1093. Create CSR , professional use.
  1094. "
  1095. }
  1096. if [ -z "$1" ] ; then
  1097. showhelp
  1098. else
  1099. "$@"
  1100. fi