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.

1343 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
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 2>/dev/null > "$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="$(cat $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="$(cat $__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="$(cat $__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 -l"
  287. nchelp="$(nc -h 2>&1)"
  288. #centos
  289. if echo "$nchelp" | grep "nmap.org/ncat" >/dev/null ; then
  290. _NC="nc -l"
  291. fi
  292. #debian
  293. ncver="$(nc --version 2>&1)"
  294. if echo "$ncver" | grep "http://www.deepspace6.net" > /dev/null ; then
  295. _NC="$_NC -p"
  296. fi
  297. _debug nc "$_NC"
  298. # while true ; do
  299. if [ "$DEBUG" ] ; then
  300. echo -e -n "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC $Le_HTTPPort -vv
  301. else
  302. echo -e -n "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC $Le_HTTPPort > /dev/null
  303. fi
  304. # done
  305. }
  306. _stopserver() {
  307. pid="$1"
  308. }
  309. _initpath() {
  310. if [ -z "$LE_WORKING_DIR" ]; then
  311. LE_WORKING_DIR=$HOME/.le
  312. fi
  313. if [ -z "$ACCOUNT_CONF_PATH" ] ; then
  314. ACCOUNT_CONF_PATH="$LE_WORKING_DIR/account.conf"
  315. fi
  316. if [ -f "$ACCOUNT_CONF_PATH" ] ; then
  317. source "$ACCOUNT_CONF_PATH"
  318. fi
  319. if [ -z "$API" ] ; then
  320. if [ -z "$STAGE" ] ; then
  321. API="$DEFAULT_CA"
  322. else
  323. API="$STAGE_CA"
  324. _info "Using stage api:$API"
  325. fi
  326. fi
  327. if [ -z "$ACME_DIR" ] ; then
  328. ACME_DIR="/home/.acme"
  329. fi
  330. if [ -z "$APACHE_CONF_BACKUP_DIR" ] ; then
  331. APACHE_CONF_BACKUP_DIR="$LE_WORKING_DIR/"
  332. fi
  333. domain="$1"
  334. if ! mkdir -p "$LE_WORKING_DIR" ; then
  335. _err "Can not craete working dir: $LE_WORKING_DIR"
  336. return 1
  337. fi
  338. if [ -z "$ACCOUNT_KEY_PATH" ] ; then
  339. ACCOUNT_KEY_PATH="$LE_WORKING_DIR/account.key"
  340. fi
  341. if [ -z "$domain" ] ; then
  342. return 0
  343. fi
  344. domainhome="$LE_WORKING_DIR/$domain"
  345. mkdir -p "$domainhome"
  346. if [ -z "$DOMAIN_PATH" ] ; then
  347. DOMAIN_PATH="$domainhome"
  348. fi
  349. if [ -z "$DOMAIN_CONF" ] ; then
  350. DOMAIN_CONF="$domainhome/$domain.conf"
  351. fi
  352. if [ -z "$DOMAIN_SSL_CONF" ] ; then
  353. DOMAIN_SSL_CONF="$domainhome/$domain.ssl.conf"
  354. fi
  355. if [ -z "$CSR_PATH" ] ; then
  356. CSR_PATH="$domainhome/$domain.csr"
  357. fi
  358. if [ -z "$CERT_KEY_PATH" ] ; then
  359. CERT_KEY_PATH="$domainhome/$domain.key"
  360. fi
  361. if [ -z "$CERT_PATH" ] ; then
  362. CERT_PATH="$domainhome/$domain.cer"
  363. fi
  364. if [ -z "$CA_CERT_PATH" ] ; then
  365. CA_CERT_PATH="$domainhome/ca.cer"
  366. fi
  367. }
  368. _apachePath() {
  369. httpdroot="$(apachectl -V | grep HTTPD_ROOT= | cut -d = -f 2 | tr -d '"' )"
  370. httpdconfname="$(apachectl -V | grep SERVER_CONFIG_FILE= | cut -d = -f 2 | tr -d '"' )"
  371. httpdconf="$httpdroot/$httpdconfname"
  372. if [ ! -f $httpdconf ] ; then
  373. _err "Apache Config file not found" $httpdconf
  374. return 1
  375. fi
  376. return 0
  377. }
  378. _restoreApache() {
  379. if [ -z "$usingApache" ] ; then
  380. return 0
  381. fi
  382. _initpath
  383. if ! _apachePath ; then
  384. return 1
  385. fi
  386. if [ ! -f "$APACHE_CONF_BACKUP_DIR/$httpdconfname" ] ; then
  387. _debug "No config file to restore."
  388. return 0
  389. fi
  390. cp -p "$APACHE_CONF_BACKUP_DIR/$httpdconfname" "$httpdconf"
  391. if ! apachectl -t ; then
  392. _err "Sorry, restore apache config error, please contact me."
  393. return 1;
  394. fi
  395. rm -f "$APACHE_CONF_BACKUP_DIR/$httpdconfname"
  396. return 0
  397. }
  398. _setApache() {
  399. _initpath
  400. if ! _apachePath ; then
  401. return 1
  402. fi
  403. #backup the conf
  404. _debug "Backup apache config file" $httpdconf
  405. cp -p $httpdconf $APACHE_CONF_BACKUP_DIR/
  406. _info "JFYI, Config file $httpdconf is backuped to $APACHE_CONF_BACKUP_DIR/$httpdconfname"
  407. _info "In case there is an error that can not be restored automatically, you may try restore it yourself."
  408. _info "The backup file will be deleted on sucess, just forget it."
  409. #add alias
  410. echo "
  411. Alias /.well-known/acme-challenge $ACME_DIR
  412. <Directory $ACME_DIR >
  413. Require all granted
  414. </Directory>
  415. " >> $httpdconf
  416. if ! apachectl -t ; then
  417. _err "Sorry, apache config error, please contact me."
  418. _restoreApache
  419. return 1;
  420. fi
  421. if [ ! -d "$ACME_DIR" ] ; then
  422. mkdir -p "$ACME_DIR"
  423. chmod 755 "$ACME_DIR"
  424. fi
  425. if ! apachectl graceful ; then
  426. _err "Sorry, apachectl graceful error, please contact me."
  427. _restoreApache
  428. return 1;
  429. fi
  430. usingApache="1"
  431. return 0
  432. }
  433. _clearup () {
  434. _stopserver $serverproc
  435. serverproc=""
  436. _restoreApache
  437. }
  438. # webroot removelevel tokenfile
  439. _clearupwebbroot() {
  440. __webroot="$1"
  441. if [ -z "$__webroot" ] ; then
  442. _debug "no webroot specified, skip"
  443. return 0
  444. fi
  445. if [ "$2" == '1' ] ; then
  446. _debug "remove $__webroot/.well-known"
  447. rm -rf "$__webroot/.well-known"
  448. elif [ "$2" == '2' ] ; then
  449. _debug "remove $__webroot/.well-known/acme-challenge"
  450. rm -rf "$__webroot/.well-known/acme-challenge"
  451. elif [ "$2" == '3' ] ; then
  452. _debug "remove $__webroot/.well-known/acme-challenge/$3"
  453. rm -rf "$__webroot/.well-known/acme-challenge/$3"
  454. else
  455. _info "Skip for removelevel:$2"
  456. fi
  457. return 0
  458. }
  459. issue() {
  460. if [ -z "$2" ] ; then
  461. _err "Usage: le issue webroot|no|apache|dns a.com [www.a.com,b.com,c.com]|no [key-length]|no"
  462. return 1
  463. fi
  464. Le_Webroot="$1"
  465. Le_Domain="$2"
  466. Le_Alt="$3"
  467. Le_Keylength="$4"
  468. Le_RealCertPath="$5"
  469. Le_RealKeyPath="$6"
  470. Le_RealCACertPath="$7"
  471. Le_ReloadCmd="$8"
  472. _initpath $Le_Domain
  473. if [ -f "$DOMAIN_CONF" ] ; then
  474. Le_NextRenewTime=$(grep "^Le_NextRenewTime=" "$DOMAIN_CONF" | cut -d '=' -f 2)
  475. if [ -z "$FORCE" ] && [ "$Le_NextRenewTime" ] && [ "$(date -u "+%s" )" -lt "$Le_NextRenewTime" ] ; then
  476. _info "Skip, Next renewal time is: $(grep "^Le_NextRenewTimeStr" "$DOMAIN_CONF" | cut -d '=' -f 2)"
  477. return 2
  478. fi
  479. fi
  480. if [ "$Le_Alt" == "no" ] ; then
  481. Le_Alt=""
  482. fi
  483. if [ "$Le_Keylength" == "no" ] ; then
  484. Le_Keylength=""
  485. fi
  486. if [ "$Le_RealCertPath" == "no" ] ; then
  487. Le_RealCertPath=""
  488. fi
  489. if [ "$Le_RealKeyPath" == "no" ] ; then
  490. Le_RealKeyPath=""
  491. fi
  492. if [ "$Le_RealCACertPath" == "no" ] ; then
  493. Le_RealCACertPath=""
  494. fi
  495. if [ "$Le_ReloadCmd" == "no" ] ; then
  496. Le_ReloadCmd=""
  497. fi
  498. _setopt "$DOMAIN_CONF" "Le_Domain" "=" "$Le_Domain"
  499. _setopt "$DOMAIN_CONF" "Le_Alt" "=" "$Le_Alt"
  500. _setopt "$DOMAIN_CONF" "Le_Webroot" "=" "$Le_Webroot"
  501. _setopt "$DOMAIN_CONF" "Le_Keylength" "=" "$Le_Keylength"
  502. _setopt "$DOMAIN_CONF" "Le_RealCertPath" "=" "\"$Le_RealCertPath\""
  503. _setopt "$DOMAIN_CONF" "Le_RealCACertPath" "=" "\"$Le_RealCACertPath\""
  504. _setopt "$DOMAIN_CONF" "Le_RealKeyPath" "=" "\"$Le_RealKeyPath\""
  505. _setopt "$DOMAIN_CONF" "Le_ReloadCmd" "=" "\"$Le_ReloadCmd\""
  506. if [ "$Le_Webroot" == "no" ] ; then
  507. _info "Standalone mode."
  508. if ! command -v "nc" > /dev/null ; then
  509. _err "Please install netcat(nc) tools first."
  510. return 1
  511. fi
  512. if [ -z "$Le_HTTPPort" ] ; then
  513. Le_HTTPPort=80
  514. fi
  515. _setopt "$DOMAIN_CONF" "Le_HTTPPort" "=" "$Le_HTTPPort"
  516. netprc="$(ss -ntpl | grep :$Le_HTTPPort" ")"
  517. if [ "$netprc" ] ; then
  518. _err "$netprc"
  519. _err "tcp port $Le_HTTPPort is already used by $(echo "$netprc" | cut -d : -f 4)"
  520. _err "Please stop it first"
  521. return 1
  522. fi
  523. fi
  524. if [ "$Le_Webroot" == "apache" ] ; then
  525. if ! _setApache ; then
  526. _err "set up apache error. Report error to me."
  527. return 1
  528. fi
  529. wellknown_path="$ACME_DIR"
  530. else
  531. usingApache=""
  532. fi
  533. createAccountKey $Le_Domain $Le_Keylength
  534. if ! createDomainKey $Le_Domain $Le_Keylength ; then
  535. _err "Create domain key error."
  536. return 1
  537. fi
  538. if ! createCSR $Le_Domain $Le_Alt ; then
  539. _err "Create CSR error."
  540. return 1
  541. fi
  542. 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)
  543. if [ "${#pub_exp}" == "5" ] ; then
  544. pub_exp=0$pub_exp
  545. fi
  546. _debug pub_exp "$pub_exp"
  547. e=$(echo $pub_exp | _h2b | _base64)
  548. _debug e "$e"
  549. modulus=$(openssl rsa -in $ACCOUNT_KEY_PATH -modulus -noout | cut -d '=' -f 2 )
  550. n=$(echo $modulus| _h2b | _base64 | _b64 )
  551. jwk='{"e": "'$e'", "kty": "RSA", "n": "'$n'"}'
  552. HEADER='{"alg": "RS256", "jwk": '$jwk'}'
  553. HEADERPLACE='{"nonce": "NONCE", "alg": "RS256", "jwk": '$jwk'}'
  554. _debug HEADER "$HEADER"
  555. accountkey_json=$(echo -n "$jwk" | tr -d ' ' )
  556. thumbprint=$(echo -n "$accountkey_json" | openssl dgst -sha256 -binary | _base64 | _b64)
  557. _info "Registering account"
  558. regjson='{"resource": "new-reg", "agreement": "'$AGREEMENT'"}'
  559. if [ "$ACCOUNT_EMAIL" ] ; then
  560. regjson='{"resource": "new-reg", "contact": ["mailto: '$ACCOUNT_EMAIL'"], "agreement": "'$AGREEMENT'"}'
  561. fi
  562. _send_signed_request "$API/acme/new-reg" "$regjson"
  563. if [ "$code" == "" ] || [ "$code" == '201' ] ; then
  564. _info "Registered"
  565. echo $response > $LE_WORKING_DIR/account.json
  566. elif [ "$code" == '409' ] ; then
  567. _info "Already registered"
  568. else
  569. _err "Register account Error."
  570. _clearup
  571. return 1
  572. fi
  573. vtype="$VTYPE_HTTP"
  574. if [[ "$Le_Webroot" == "dns"* ]] ; then
  575. vtype="$VTYPE_DNS"
  576. fi
  577. vlist="$Le_Vlist"
  578. # verify each domain
  579. _info "Verify each domain"
  580. sep='#'
  581. if [ -z "$vlist" ] ; then
  582. alldomains=$(echo "$Le_Domain,$Le_Alt" | tr ',' ' ' )
  583. for d in $alldomains
  584. do
  585. _info "Getting token for domain" $d
  586. _send_signed_request "$API/acme/new-authz" "{\"resource\": \"new-authz\", \"identifier\": {\"type\": \"dns\", \"value\": \"$d\"}}"
  587. if [ ! -z "$code" ] && [ ! "$code" == '201' ] ; then
  588. _err "new-authz error: $response"
  589. _clearup
  590. return 1
  591. fi
  592. entry="$(printf $response | egrep -o '\{[^{]*"type":"'$vtype'"[^}]*')"
  593. _debug entry "$entry"
  594. token="$(printf "$entry" | egrep -o '"token":"[^"]*' | cut -d : -f 2 | tr -d '"')"
  595. _debug token $token
  596. uri="$(printf "$entry" | egrep -o '"uri":"[^"]*'| cut -d : -f 2,3 | tr -d '"' )"
  597. _debug uri $uri
  598. keyauthorization="$token.$thumbprint"
  599. _debug keyauthorization "$keyauthorization"
  600. dvlist="$d$sep$keyauthorization$sep$uri"
  601. _debug dvlist "$dvlist"
  602. vlist="$vlist$dvlist,"
  603. done
  604. #add entry
  605. dnsadded=""
  606. ventries=$(echo "$vlist" | tr ',' ' ' )
  607. for ventry in $ventries
  608. do
  609. d=$(echo $ventry | cut -d $sep -f 1)
  610. keyauthorization=$(echo $ventry | cut -d $sep -f 2)
  611. if [ "$vtype" == "$VTYPE_DNS" ] ; then
  612. dnsadded='0'
  613. txtdomain="_acme-challenge.$d"
  614. _debug txtdomain "$txtdomain"
  615. txt="$(echo -e -n $keyauthorization | openssl dgst -sha256 -binary | _base64 | _b64)"
  616. _debug txt "$txt"
  617. #dns
  618. #1. check use api
  619. d_api=""
  620. if [ -f "$LE_WORKING_DIR/$d/$Le_Webroot" ] ; then
  621. d_api="$LE_WORKING_DIR/$d/$Le_Webroot"
  622. elif [ -f "$LE_WORKING_DIR/$d/$Le_Webroot.sh" ] ; then
  623. d_api="$LE_WORKING_DIR/$d/$Le_Webroot.sh"
  624. elif [ -f "$LE_WORKING_DIR/$Le_Webroot" ] ; then
  625. d_api="$LE_WORKING_DIR/$Le_Webroot"
  626. elif [ -f "$LE_WORKING_DIR/$Le_Webroot.sh" ] ; then
  627. d_api="$LE_WORKING_DIR/$Le_Webroot.sh"
  628. elif [ -f "$LE_WORKING_DIR/dnsapi/$Le_Webroot" ] ; then
  629. d_api="$LE_WORKING_DIR/dnsapi/$Le_Webroot"
  630. elif [ -f "$LE_WORKING_DIR/dnsapi/$Le_Webroot.sh" ] ; then
  631. d_api="$LE_WORKING_DIR/dnsapi/$Le_Webroot.sh"
  632. fi
  633. _debug d_api "$d_api"
  634. if [ "$d_api" ]; then
  635. _info "Found domain api file: $d_api"
  636. else
  637. _err "Add the following TXT record:"
  638. _err "Domain: $txtdomain"
  639. _err "TXT value: $txt"
  640. _err "Please be aware that you prepend _acme-challenge. before your domain"
  641. _err "so the resulting subdomain will be: $txtdomain"
  642. continue
  643. fi
  644. if ! source $d_api ; then
  645. _err "Load file $d_api error. Please check your api file and try again."
  646. return 1
  647. fi
  648. addcommand="$Le_Webroot-add"
  649. if ! command -v $addcommand ; then
  650. _err "It seems that your api file is not correct, it must have a function named: $addcommand"
  651. return 1
  652. fi
  653. if ! $addcommand $txtdomain $txt ; then
  654. _err "Error add txt for domain:$txtdomain"
  655. return 1
  656. fi
  657. dnsadded='1'
  658. fi
  659. done
  660. if [ "$dnsadded" == '0' ] ; then
  661. _setopt "$DOMAIN_CONF" "Le_Vlist" "=" "\"$vlist\""
  662. _debug "Dns record not added yet, so, save to $DOMAIN_CONF and exit."
  663. _err "Please add the TXT records to the domains, and retry again."
  664. return 1
  665. fi
  666. fi
  667. if [ "$dnsadded" == '1' ] ; then
  668. _info "Sleep 60 seconds for the txt records to take effect"
  669. sleep 60
  670. fi
  671. _debug "ok, let's start to verify"
  672. ventries=$(echo "$vlist" | tr ',' ' ' )
  673. for ventry in $ventries
  674. do
  675. d=$(echo $ventry | cut -d $sep -f 1)
  676. keyauthorization=$(echo $ventry | cut -d $sep -f 2)
  677. uri=$(echo $ventry | cut -d $sep -f 3)
  678. _info "Verifying:$d"
  679. _debug "d" "$d"
  680. _debug "keyauthorization" "$keyauthorization"
  681. _debug "uri" "$uri"
  682. removelevel=""
  683. token=""
  684. if [ "$vtype" == "$VTYPE_HTTP" ] ; then
  685. if [ "$Le_Webroot" == "no" ] ; then
  686. _info "Standalone mode server"
  687. _startserver "$keyauthorization" &
  688. serverproc="$!"
  689. sleep 2
  690. _debug serverproc $serverproc
  691. else
  692. if [ -z "$wellknown_path" ] ; then
  693. wellknown_path="$Le_Webroot/.well-known/acme-challenge"
  694. fi
  695. _debug wellknown_path "$wellknown_path"
  696. if [ ! -d "$Le_Webroot/.well-known" ] ; then
  697. removelevel='1'
  698. elif [ ! -d "$Le_Webroot/.well-known/acme-challenge" ] ; then
  699. removelevel='2'
  700. else
  701. removelevel='3'
  702. fi
  703. token="$(echo -e -n "$keyauthorization" | cut -d '.' -f 1)"
  704. _debug "writing token:$token to $wellknown_path/$token"
  705. mkdir -p "$wellknown_path"
  706. echo -n "$keyauthorization" > "$wellknown_path/$token"
  707. webroot_owner=$(_stat $Le_Webroot)
  708. _debug "Changing owner/group of .well-known to $webroot_owner"
  709. chown -R $webroot_owner "$Le_Webroot/.well-known"
  710. fi
  711. fi
  712. _send_signed_request $uri "{\"resource\": \"challenge\", \"keyAuthorization\": \"$keyauthorization\"}"
  713. if [ ! -z "$code" ] && [ ! "$code" == '202' ] ; then
  714. _err "$d:Challenge error: $resource"
  715. _clearupwebbroot "$Le_Webroot" "$removelevel" "$token"
  716. _clearup
  717. return 1
  718. fi
  719. while [ "1" ] ; do
  720. _debug "sleep 5 secs to verify"
  721. sleep 5
  722. _debug "checking"
  723. if ! _get $uri ; then
  724. _err "$d:Verify error:$resource"
  725. _clearupwebbroot "$Le_Webroot" "$removelevel" "$token"
  726. _clearup
  727. return 1
  728. fi
  729. status=$(echo $response | egrep -o '"status":"[^"]+"' | cut -d : -f 2 | tr -d '"')
  730. if [ "$status" == "valid" ] ; then
  731. _info "Success"
  732. _stopserver $serverproc
  733. serverproc=""
  734. _clearupwebbroot "$Le_Webroot" "$removelevel" "$token"
  735. break;
  736. fi
  737. if [ "$status" == "invalid" ] ; then
  738. error=$(echo $response | egrep -o '"error":{[^}]*}' | grep -o '"detail":"[^"]*"' | cut -d '"' -f 4)
  739. _err "$d:Verify error:$error"
  740. _clearupwebbroot "$Le_Webroot" "$removelevel" "$token"
  741. _clearup
  742. return 1;
  743. fi
  744. if [ "$status" == "pending" ] ; then
  745. _info "Pending"
  746. else
  747. _err "$d:Verify error:$response"
  748. _clearupwebbroot "$Le_Webroot" "$removelevel" "$token"
  749. _clearup
  750. return 1
  751. fi
  752. done
  753. done
  754. _clearup
  755. _info "Verify finished, start to sign."
  756. der="$(openssl req -in $CSR_PATH -outform DER | _base64 | _b64)"
  757. _send_signed_request "$API/acme/new-cert" "{\"resource\": \"new-cert\", \"csr\": \"$der\"}" "needbase64"
  758. Le_LinkCert="$(grep -i -o '^Location.*$' $CURL_HEADER | tr -d "\r\n" | cut -d " " -f 2)"
  759. _setopt "$DOMAIN_CONF" "Le_LinkCert" "=" "$Le_LinkCert"
  760. if [ "$Le_LinkCert" ] ; then
  761. echo -----BEGIN CERTIFICATE----- > "$CERT_PATH"
  762. curl --silent "$Le_LinkCert" | openssl base64 -e >> "$CERT_PATH"
  763. echo -----END CERTIFICATE----- >> "$CERT_PATH"
  764. _info "Cert success."
  765. cat "$CERT_PATH"
  766. _info "Your cert is in $CERT_PATH"
  767. fi
  768. if [ -z "$Le_LinkCert" ] ; then
  769. response="$(echo $response | openssl base64 -d -A)"
  770. _err "Sign failed: $(echo "$response" | grep -o '"detail":"[^"]*"')"
  771. return 1
  772. fi
  773. _setopt "$DOMAIN_CONF" 'Le_Vlist' '=' "\"\""
  774. Le_LinkIssuer=$(grep -i '^Link' $CURL_HEADER | cut -d " " -f 2| cut -d ';' -f 1 | tr -d '<>' )
  775. _setopt "$DOMAIN_CONF" "Le_LinkIssuer" "=" "$Le_LinkIssuer"
  776. if [ "$Le_LinkIssuer" ] ; then
  777. echo -----BEGIN CERTIFICATE----- > "$CA_CERT_PATH"
  778. curl --silent "$Le_LinkIssuer" | openssl base64 -e >> "$CA_CERT_PATH"
  779. echo -----END CERTIFICATE----- >> "$CA_CERT_PATH"
  780. _info "The intermediate CA cert is in $CA_CERT_PATH"
  781. fi
  782. Le_CertCreateTime=$(date -u "+%s")
  783. _setopt "$DOMAIN_CONF" "Le_CertCreateTime" "=" "$Le_CertCreateTime"
  784. Le_CertCreateTimeStr=$(date -u )
  785. _setopt "$DOMAIN_CONF" "Le_CertCreateTimeStr" "=" "\"$Le_CertCreateTimeStr\""
  786. if [ ! "$Le_RenewalDays" ] ; then
  787. Le_RenewalDays=80
  788. fi
  789. _setopt "$DOMAIN_CONF" "Le_RenewalDays" "=" "$Le_RenewalDays"
  790. let "Le_NextRenewTime=Le_CertCreateTime+Le_RenewalDays*24*60*60"
  791. _setopt "$DOMAIN_CONF" "Le_NextRenewTime" "=" "$Le_NextRenewTime"
  792. Le_NextRenewTimeStr=$( _time2str $Le_NextRenewTime )
  793. _setopt "$DOMAIN_CONF" "Le_NextRenewTimeStr" "=" "\"$Le_NextRenewTimeStr\""
  794. installcert $Le_Domain "$Le_RealCertPath" "$Le_RealKeyPath" "$Le_RealCACertPath" "$Le_ReloadCmd"
  795. }
  796. renew() {
  797. Le_Domain="$1"
  798. if [ -z "$Le_Domain" ] ; then
  799. _err "Usage: $0 domain.com"
  800. return 1
  801. fi
  802. _initpath $Le_Domain
  803. if [ ! -f "$DOMAIN_CONF" ] ; then
  804. _info "$Le_Domain is not a issued domain, skip."
  805. return 0;
  806. fi
  807. source "$DOMAIN_CONF"
  808. if [ -z "$FORCE" ] && [ "$Le_NextRenewTime" ] && [ "$(date -u "+%s" )" -lt "$Le_NextRenewTime" ] ; then
  809. _info "Skip, Next renewal time is: $Le_NextRenewTimeStr"
  810. return 2
  811. fi
  812. IS_RENEW="1"
  813. issue "$Le_Webroot" "$Le_Domain" "$Le_Alt" "$Le_Keylength" "$Le_RealCertPath" "$Le_RealKeyPath" "$Le_RealCACertPath" "$Le_ReloadCmd"
  814. local res=$?
  815. IS_RENEW=""
  816. return $res
  817. }
  818. renewAll() {
  819. _initpath
  820. _info "renewAll"
  821. for d in $(ls -F $LE_WORKING_DIR | grep [^.].*[.].*/$ ) ; do
  822. d=$(echo $d | cut -d '/' -f 1)
  823. _info "renew $d"
  824. Le_LinkCert=""
  825. Le_Domain=""
  826. Le_Alt=""
  827. Le_Webroot=""
  828. Le_Keylength=""
  829. Le_LinkIssuer=""
  830. Le_CertCreateTime=""
  831. Le_CertCreateTimeStr=""
  832. Le_RenewalDays=""
  833. Le_NextRenewTime=""
  834. Le_NextRenewTimeStr=""
  835. Le_RealCertPath=""
  836. Le_RealKeyPath=""
  837. Le_RealCACertPath=""
  838. Le_ReloadCmd=""
  839. DOMAIN_PATH=""
  840. DOMAIN_CONF=""
  841. DOMAIN_SSL_CONF=""
  842. CSR_PATH=""
  843. CERT_KEY_PATH=""
  844. CERT_PATH=""
  845. CA_CERT_PATH=""
  846. ACCOUNT_KEY_PATH=""
  847. wellknown_path=""
  848. renew "$d"
  849. done
  850. }
  851. installcert() {
  852. Le_Domain="$1"
  853. if [ -z "$Le_Domain" ] ; then
  854. _err "Usage: $0 domain.com [cert-file-path]|no [key-file-path]|no [ca-cert-file-path]|no [reloadCmd]|no"
  855. return 1
  856. fi
  857. Le_RealCertPath="$2"
  858. Le_RealKeyPath="$3"
  859. Le_RealCACertPath="$4"
  860. Le_ReloadCmd="$5"
  861. _initpath $Le_Domain
  862. _setopt "$DOMAIN_CONF" "Le_RealCertPath" "=" "\"$Le_RealCertPath\""
  863. _setopt "$DOMAIN_CONF" "Le_RealCACertPath" "=" "\"$Le_RealCACertPath\""
  864. _setopt "$DOMAIN_CONF" "Le_RealKeyPath" "=" "\"$Le_RealKeyPath\""
  865. _setopt "$DOMAIN_CONF" "Le_ReloadCmd" "=" "\"$Le_ReloadCmd\""
  866. if [ "$Le_RealCertPath" ] ; then
  867. if [ -f "$Le_RealCertPath" ] ; then
  868. cp -p "$Le_RealCertPath" "$Le_RealCertPath".bak
  869. fi
  870. cat "$CERT_PATH" > "$Le_RealCertPath"
  871. fi
  872. if [ "$Le_RealCACertPath" ] ; then
  873. if [ -f "$Le_RealCACertPath" ] ; then
  874. cp -p "$Le_RealCACertPath" "$Le_RealCACertPath".bak
  875. fi
  876. if [ "$Le_RealCACertPath" == "$Le_RealCertPath" ] ; then
  877. echo "" >> "$Le_RealCACertPath"
  878. cat "$CA_CERT_PATH" >> "$Le_RealCACertPath"
  879. else
  880. cat "$CA_CERT_PATH" > "$Le_RealCACertPath"
  881. fi
  882. fi
  883. if [ "$Le_RealKeyPath" ] ; then
  884. if [ -f "$Le_RealKeyPath" ] ; then
  885. cp -p "$Le_RealKeyPath" "$Le_RealKeyPath".bak
  886. fi
  887. cat "$CERT_KEY_PATH" > "$Le_RealKeyPath"
  888. fi
  889. if [ "$Le_ReloadCmd" ] ; then
  890. _info "Run Le_ReloadCmd: $Le_ReloadCmd"
  891. (cd "$DOMAIN_PATH" && eval "$Le_ReloadCmd")
  892. fi
  893. }
  894. installcronjob() {
  895. _initpath
  896. _info "Installing cron job"
  897. if ! crontab -l | grep 'le.sh cron' ; then
  898. if [ -f "$LE_WORKING_DIR/le.sh" ] ; then
  899. lesh="\"$LE_WORKING_DIR\"/le.sh"
  900. else
  901. _err "Can not install cronjob, le.sh not found."
  902. return 1
  903. fi
  904. crontab -l | { cat; echo "0 0 * * * LE_WORKING_DIR=\"$LE_WORKING_DIR\" $lesh cron > /dev/null"; } | crontab -
  905. fi
  906. if [ "$?" != "0" ] ; then
  907. _err "Install cron job failed. You need to manually renew your certs."
  908. _err "Or you can add cronjob by yourself:"
  909. _err "LE_WORKING_DIR=\"$LE_WORKING_DIR\" $lesh cron > /dev/null"
  910. return 1
  911. fi
  912. }
  913. uninstallcronjob() {
  914. _info "Removing cron job"
  915. cr="$(crontab -l | grep 'le.sh cron')"
  916. if [ "$cr" ] ; then
  917. crontab -l | sed "/le.sh cron/d" | crontab -
  918. LE_WORKING_DIR="$(echo "$cr" | cut -d ' ' -f 6 | cut -d '=' -f 2 | tr -d '"')"
  919. _info LE_WORKING_DIR "$LE_WORKING_DIR"
  920. fi
  921. _initpath
  922. }
  923. # Detect profile file if not specified as environment variable
  924. _detect_profile() {
  925. if [ -n "$PROFILE" -a -f "$PROFILE" ]; then
  926. echo "$PROFILE"
  927. return
  928. fi
  929. local DETECTED_PROFILE
  930. DETECTED_PROFILE=''
  931. local SHELLTYPE
  932. SHELLTYPE="$(basename "/$SHELL")"
  933. if [ "$SHELLTYPE" = "bash" ]; then
  934. if [ -f "$HOME/.bashrc" ]; then
  935. DETECTED_PROFILE="$HOME/.bashrc"
  936. elif [ -f "$HOME/.bash_profile" ]; then
  937. DETECTED_PROFILE="$HOME/.bash_profile"
  938. fi
  939. elif [ "$SHELLTYPE" = "zsh" ]; then
  940. DETECTED_PROFILE="$HOME/.zshrc"
  941. fi
  942. if [ -z "$DETECTED_PROFILE" ]; then
  943. if [ -f "$HOME/.profile" ]; then
  944. DETECTED_PROFILE="$HOME/.profile"
  945. elif [ -f "$HOME/.bashrc" ]; then
  946. DETECTED_PROFILE="$HOME/.bashrc"
  947. elif [ -f "$HOME/.bash_profile" ]; then
  948. DETECTED_PROFILE="$HOME/.bash_profile"
  949. elif [ -f "$HOME/.zshrc" ]; then
  950. DETECTED_PROFILE="$HOME/.zshrc"
  951. fi
  952. fi
  953. if [ ! -z "$DETECTED_PROFILE" ]; then
  954. echo "$DETECTED_PROFILE"
  955. fi
  956. }
  957. _initconf() {
  958. _initpath
  959. if [ ! -f "$ACCOUNT_CONF_PATH" ] ; then
  960. echo "#Account configurations:
  961. #Here are the supported macros, uncomment them to make them take effect.
  962. #ACCOUNT_EMAIL=aaa@aaa.com # the account email used to register account.
  963. #ACCOUNT_KEY_PATH=\"/path/to/account.key\"
  964. #STAGE=1 # Use the staging api
  965. #FORCE=1 # Force to issue cert
  966. #DEBUG=1 # Debug mode
  967. #dns api
  968. #######################
  969. #Cloudflare:
  970. #api key
  971. #CF_Key=\"sdfsdfsdfljlbjkljlkjsdfoiwje\"
  972. #account email
  973. #CF_Email=\"xxxx@sss.com\"
  974. #######################
  975. #Dnspod.cn:
  976. #api key id
  977. #DP_Id=\"1234\"
  978. #api key
  979. #DP_Key=\"sADDsdasdgdsf\"
  980. #######################
  981. #Cloudxns.com:
  982. #CX_Key=\"1234\"
  983. #
  984. #CX_Secret=\"sADDsdasdgdsf\"
  985. " > $ACCOUNT_CONF_PATH
  986. fi
  987. }
  988. install() {
  989. if ! _initpath ; then
  990. _err "Install failed."
  991. return 1
  992. fi
  993. #check if there is sudo installed, AND if the current user is a sudoer.
  994. if command -v sudo > /dev/null ; then
  995. if [ "$(sudo -n uptime 2>&1|grep "load"|wc -l)" != "0" ] ; then
  996. SUDO=sudo
  997. fi
  998. fi
  999. if command -v yum > /dev/null ; then
  1000. YUM="1"
  1001. INSTALL="$SUDO yum install -y "
  1002. elif command -v apt-get > /dev/null ; then
  1003. INSTALL="$SUDO apt-get install -y "
  1004. fi
  1005. if ! command -v "curl" > /dev/null ; then
  1006. _err "Please install curl first."
  1007. _err "$INSTALL curl"
  1008. return 1
  1009. fi
  1010. if ! command -v "crontab" > /dev/null ; then
  1011. _err "Please install crontab first."
  1012. if [ "$YUM" ] ; then
  1013. _err "$INSTALL crontabs"
  1014. else
  1015. _err "$INSTALL crontab"
  1016. fi
  1017. return 1
  1018. fi
  1019. if ! command -v "openssl" > /dev/null ; then
  1020. _err "Please install openssl first."
  1021. _err "$INSTALL openssl"
  1022. return 1
  1023. fi
  1024. _info "Installing to $LE_WORKING_DIR"
  1025. cp le.sh "$LE_WORKING_DIR/" && chmod +x "$LE_WORKING_DIR/le.sh"
  1026. if [ "$?" != "0" ] ; then
  1027. _err "Install failed, can not copy le.sh"
  1028. return 1
  1029. fi
  1030. _info "Installed to $LE_WORKING_DIR/le.sh"
  1031. _profile="$(_detect_profile)"
  1032. if [ "$_profile" ] ; then
  1033. _debug "Found profile: $_profile"
  1034. echo "LE_WORKING_DIR=$LE_WORKING_DIR
  1035. alias le=\"$LE_WORKING_DIR/le.sh\"
  1036. alias le.sh=\"$LE_WORKING_DIR/le.sh\"
  1037. " > "$LE_WORKING_DIR/le.env"
  1038. echo "" >> "$_profile"
  1039. _setopt "$_profile" "source \"$LE_WORKING_DIR/le.env\""
  1040. _info "OK, Close and reopen your terminal to start using le"
  1041. else
  1042. _info "No profile is found, you will need to go into $LE_WORKING_DIR to use le.sh"
  1043. fi
  1044. mkdir -p $LE_WORKING_DIR/dnsapi
  1045. cp dnsapi/* $LE_WORKING_DIR/dnsapi/
  1046. #to keep compatible mv the .acc file to .key file
  1047. if [ -f "$LE_WORKING_DIR/account.acc" ] ; then
  1048. mv "$LE_WORKING_DIR/account.acc" "$LE_WORKING_DIR/account.key"
  1049. fi
  1050. installcronjob
  1051. if [ ! -f "$ACCOUNT_CONF_PATH" ] ; then
  1052. _initconf
  1053. fi
  1054. _info OK
  1055. }
  1056. uninstall() {
  1057. uninstallcronjob
  1058. _initpath
  1059. _profile="$(_detect_profile)"
  1060. if [ "$_profile" ] ; then
  1061. text="$(cat $_profile)"
  1062. echo "$text" | sed "s|^source.*le.env.*$||" > "$_profile"
  1063. fi
  1064. rm -f $LE_WORKING_DIR/le.sh
  1065. _info "The keys and certs are in $LE_WORKING_DIR, you can remove them by yourself."
  1066. }
  1067. cron() {
  1068. renewAll
  1069. }
  1070. version() {
  1071. _info "$PROJECT"
  1072. _info "v$VER"
  1073. }
  1074. showhelp() {
  1075. version
  1076. echo "Usage: le.sh [command] ...[args]....
  1077. Avalible commands:
  1078. install:
  1079. Install le.sh to your system.
  1080. issue:
  1081. Issue a cert.
  1082. installcert:
  1083. Install the issued cert to apache/nginx or any other server.
  1084. renew:
  1085. Renew a cert.
  1086. renewAll:
  1087. Renew all the certs.
  1088. uninstall:
  1089. Uninstall le.sh, and uninstall the cron job.
  1090. version:
  1091. Show version info.
  1092. installcronjob:
  1093. Install the cron job to renew certs, you don't need to call this. The 'install' command can automatically install the cron job.
  1094. uninstallcronjob:
  1095. Uninstall the cron job. The 'uninstall' command can do this automatically.
  1096. createAccountKey:
  1097. Create an account private key, professional use.
  1098. createDomainKey:
  1099. Create an domain private key, professional use.
  1100. createCSR:
  1101. Create CSR , professional use.
  1102. "
  1103. }
  1104. if [ -z "$1" ] ; then
  1105. showhelp
  1106. else
  1107. "$@"
  1108. fi