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.

686 lines
17 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
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. #!/bin/bash
  2. DEFAULT_CA="https://acme-v01.api.letsencrypt.org"
  3. DEFAULT_AGREEMENT="https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf"
  4. API="$DEFAULT_CA"
  5. AGREEMENT="$DEFAULT_AGREEMENT"
  6. _debug() {
  7. if [ -z "$DEBUG" ] ; then
  8. return
  9. fi
  10. if [ -z "$2" ] ; then
  11. echo $1
  12. else
  13. echo $1:$2
  14. fi
  15. }
  16. _info() {
  17. if [ -z "$2" ] ; then
  18. echo $1
  19. else
  20. echo $1:$2
  21. fi
  22. }
  23. _err() {
  24. if [ -z "$2" ] ; then
  25. echo "$1" >&2
  26. else
  27. echo "$1:$2" >&2
  28. fi
  29. }
  30. #domain [2048]
  31. createAccountKey() {
  32. if [ -z "$1" ] ; then
  33. echo Usage: $0 account-domain [2048]
  34. return
  35. fi
  36. account=$1
  37. length=$2
  38. if [ -z "$2" ] ; then
  39. _info "Use default length 2048"
  40. length=2048
  41. fi
  42. _initpath
  43. if [ -f "$ACCOUNT_KEY_PATH" ] ; then
  44. _info "Account key exists, skip"
  45. return
  46. else
  47. #generate account key
  48. openssl genrsa $length > "$ACCOUNT_KEY_PATH"
  49. fi
  50. }
  51. #domain length
  52. createDomainKey() {
  53. if [ -z "$1" ] ; then
  54. echo Usage: $0 domain [2048]
  55. return
  56. fi
  57. domain=$1
  58. length=$2
  59. if [ -z "$2" ] ; then
  60. _info "Use default length 2048"
  61. length=2048
  62. fi
  63. _initpath $domain
  64. if [ -f "$CERT_KEY_PATH" ] ; then
  65. _info "Domain key exists, skip"
  66. else
  67. #generate account key
  68. openssl genrsa $length > "$CERT_KEY_PATH"
  69. fi
  70. }
  71. # domain domainlist
  72. createCSR() {
  73. if [ -z "$1" ] ; then
  74. echo Usage: $0 domain [domainlist]
  75. return
  76. fi
  77. domain=$1
  78. _initpath $domain
  79. domainlist=$2
  80. if [ -f "$CSR_PATH" ] ; then
  81. _info "CSR exists, skip"
  82. return
  83. fi
  84. if [ -z "$domainlist" ] ; then
  85. #single domain
  86. _info "Single domain" $domain
  87. openssl req -new -sha256 -key "$CERT_KEY_PATH" -subj "/CN=$domain" > "$CSR_PATH"
  88. else
  89. alt="DNS:$(echo $domainlist | sed "s/,/,DNS:/g")"
  90. #multi
  91. _info "Multi domain" "$alt"
  92. openssl req -new -sha256 -key "$CERT_KEY_PATH" -subj "/CN=$domain" -reqexts SAN -config <(printf "[ req_distinguished_name ]\n[ req ]\ndistinguished_name = req_distinguished_name\n[SAN]\nsubjectAltName=$alt") -out "$CSR_PATH"
  93. fi
  94. }
  95. _b64() {
  96. __n=$(cat)
  97. echo $__n | tr '/+' '_-' | tr -d '= '
  98. }
  99. _send_signed_request() {
  100. url=$1
  101. payload=$2
  102. needbase64=$3
  103. _debug url $url
  104. _debug payload "$payload"
  105. CURL_HEADER="$WORKING_DIR/curl.header"
  106. dp="$WORKING_DIR/curl.dump"
  107. CURL="curl --silent --dump-header $CURL_HEADER "
  108. if [ "$DEBUG" ] ; then
  109. CURL="$CURL --trace-ascii $dp "
  110. fi
  111. payload64=$(echo -n $payload | base64 -w 0 | _b64)
  112. _debug payload64 $payload64
  113. nonceurl="$API/directory"
  114. nonce=$($CURL -I $nonceurl | grep "^Replay-Nonce:" | sed s/\\r//|sed s/\\n//| cut -d ' ' -f 2)
  115. _debug nonce $nonce
  116. protected=$(echo -n "$HEADERPLACE" | sed "s/NONCE/$nonce/" )
  117. _debug protected "$protected"
  118. protected64=$( echo -n $protected | base64 -w 0 | _b64)
  119. _debug protected64 "$protected64"
  120. sig=$(echo -n "$protected64.$payload64" | openssl dgst -sha256 -sign $ACCOUNT_KEY_PATH | base64 -w 0 | _b64)
  121. _debug sig "$sig"
  122. body="{\"header\": $HEADER, \"protected\": \"$protected64\", \"payload\": \"$payload64\", \"signature\": \"$sig\"}"
  123. _debug body "$body"
  124. if [ "$needbase64" ] ; then
  125. response="$($CURL -X POST --data "$body" $url | base64 -w 0)"
  126. else
  127. response="$($CURL -X POST --data "$body" $url)"
  128. fi
  129. responseHeaders="$(sed 's/\r//g' $CURL_HEADER)"
  130. _debug responseHeaders "$responseHeaders"
  131. _debug response "$response"
  132. code="$(grep ^HTTP $CURL_HEADER | tail -1 | cut -d " " -f 2)"
  133. _debug code $code
  134. }
  135. _get() {
  136. url="$1"
  137. _debug url $url
  138. response="$(curl --silent $url)"
  139. ret=$?
  140. _debug response "$response"
  141. code="$(echo $response | grep -o '"status":[0-9]\+' | cut -d : -f 2)"
  142. _debug code $code
  143. return $ret
  144. }
  145. #setopt "file" "opt" "=" "value" [";"]
  146. _setopt() {
  147. __conf="$1"
  148. __opt="$2"
  149. __sep="$3"
  150. __val="$4"
  151. __end="$5"
  152. if [ -z "$__opt" ] ; then
  153. echo usage: $0 '"file" "opt" "=" "value" [";"]'
  154. return
  155. fi
  156. if [ ! -f "$__conf" ] ; then
  157. touch "$__conf"
  158. fi
  159. if grep -H -n "^$__opt$__sep" "$__conf" > /dev/null ; then
  160. _debug OK
  161. if [[ "$__val" == *"&"* ]] ; then
  162. __val="$(echo $__val | sed 's/&/\\&/g')"
  163. fi
  164. sed -i "s|^$__opt$__sep.*$|$__opt$__sep$__val$__end|" "$__conf"
  165. else
  166. _debug APP
  167. echo "$__opt$__sep$__val$__end" >> "$__conf"
  168. fi
  169. _debug "$(grep -H -n "^$__opt$__sep" $__conf)"
  170. }
  171. _startserver() {
  172. content="$1"
  173. while true ; do
  174. if [ "$DEBUG" ] ; then
  175. echo -e -n "HTTP/1.1 200 OK\r\n\r\n$content" | nc -q 1 -l -p 80
  176. else
  177. echo -e -n "HTTP/1.1 200 OK\r\n\r\n$content" | nc -q 1 -l -p 80 > /dev/null
  178. fi
  179. done
  180. }
  181. _stopserver() {
  182. pid="$1"
  183. if [ "$pid" ] ; then
  184. if [ "$DEBUG" ] ; then
  185. kill -s 9 $pid
  186. killall -s 9 nc
  187. else
  188. kill -s 9 $pid > /dev/null
  189. wait $pid 2>/dev/null
  190. killall -s 9 nc > /dev/null
  191. fi
  192. fi
  193. }
  194. _initpath() {
  195. if [ -z "$WORKING_DIR" ]; then
  196. WORKING_DIR=~/.le
  197. fi
  198. domain="$1"
  199. mkdir -p "$WORKING_DIR"
  200. ACCOUNT_KEY_PATH="$WORKING_DIR/account.acc"
  201. if [ -z "$domain" ] ; then
  202. return 0
  203. fi
  204. mkdir -p "$WORKING_DIR/$domain"
  205. DOMAIN_CONF="$WORKING_DIR/$domain/$Le_Domain.conf"
  206. CSR_PATH="$WORKING_DIR/$domain/$domain.csr"
  207. CERT_KEY_PATH="$WORKING_DIR/$domain/$domain.key"
  208. CERT_PATH="$WORKING_DIR/$domain/$domain.cer"
  209. CA_CERT_PATH="$WORKING_DIR/$domain/ca.cer"
  210. }
  211. issue() {
  212. if [ -z "$1" ] ; then
  213. echo "Usage: le issue webroot|no a.com [www.a.com,b.com,c.com]|no [key-length]|no [cert-file-path]|no [key-file-path]|no [ca-cert-file-path]|no [reloadCmd]|no"
  214. return 1
  215. fi
  216. Le_Webroot="$1"
  217. Le_Domain="$2"
  218. Le_Alt="$3"
  219. Le_Keylength="$4"
  220. Le_RealCertPath="$5"
  221. Le_RealKeyPath="$6"
  222. Le_RealCACertPath="$7"
  223. Le_ReloadCmd="$8"
  224. if [ -z "$Le_Domain" ] ; then
  225. Le_Domain="$1"
  226. fi
  227. _initpath $Le_Domain
  228. if [ -f "$DOMAIN_CONF" ] ; then
  229. source "$DOMAIN_CONF"
  230. if [ -z "$FORCE" ] && [ "$Le_NextRenewTime" ] && [ "$(date -u "+%s" )" -lt "$Le_NextRenewTime" ] ; then
  231. _info "Skip, Next renwal time is: $Le_NextRenewTimeStr"
  232. return 2
  233. fi
  234. fi
  235. if [ "$Le_Alt" == "no" ] ; then
  236. Le_Alt=""
  237. fi
  238. if [ "$Le_Keylength" == "no" ] ; then
  239. Le_Keylength=""
  240. fi
  241. if [ "$Le_RealCertPath" == "no" ] ; then
  242. Le_RealCertPath=""
  243. fi
  244. if [ "$Le_RealKeyPath" == "no" ] ; then
  245. Le_RealKeyPath=""
  246. fi
  247. if [ "$Le_RealCACertPath" == "no" ] ; then
  248. Le_RealCACertPath=""
  249. fi
  250. if [ "$Le_ReloadCmd" == "no" ] ; then
  251. Le_ReloadCmd=""
  252. fi
  253. if [ "$Le_Webroot" == "no" ] ; then
  254. _info "Standalone mode."
  255. if ! command -v "nc" > /dev/null ; then
  256. _err "Please install netcat(nc) tools first."
  257. return 1
  258. fi
  259. if ! command -v "netstat" > /dev/null ; then
  260. _err "Please install netstat first."
  261. return 1
  262. fi
  263. netprc="$(netstat -ntpl | grep ':80 ')"
  264. if [ "$netprc" ] ; then
  265. _err "$netprc"
  266. _err "tcp port 80 is already used by $(echo "$netprc" | cut -d '/' -f 2)"
  267. _err "Please stop it first"
  268. return 1
  269. fi
  270. fi
  271. createAccountKey $Le_Domain $Le_Keylength
  272. createDomainKey $Le_Domain $Le_Keylength
  273. createCSR $Le_Domain $Le_Alt
  274. 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)
  275. if [ "${#pub_exp}" == "5" ] ; then
  276. pub_exp=0$pub_exp
  277. fi
  278. _debug pub_exp "$pub_exp"
  279. e=$(echo $pub_exp | xxd -r -p | base64)
  280. _debug e "$e"
  281. modulus=$(openssl rsa -in $ACCOUNT_KEY_PATH -modulus -noout | cut -d '=' -f 2 )
  282. n=$(echo $modulus| xxd -r -p | base64 -w 0 | _b64 )
  283. jwk='{"e": "'$e'", "kty": "RSA", "n": "'$n'"}'
  284. HEADER='{"alg": "RS256", "jwk": '$jwk'}'
  285. HEADERPLACE='{"nonce": "NONCE", "alg": "RS256", "jwk": '$jwk'}'
  286. _debug HEADER "$HEADER"
  287. accountkey_json=$(echo -n "$jwk" | sed "s/ //g")
  288. thumbprint=$(echo -n "$accountkey_json" | sha256sum | xxd -r -p | base64 -w 0 | _b64)
  289. _info "Registering account"
  290. regjson='{"resource": "new-reg", "agreement": "'$AGREEMENT'"}'
  291. if [ "$ACCOUNT_EMAIL" ] ; then
  292. regjson='{"resource": "new-reg", "contact": ["mailto: '$ACCOUNT_EMAIL'"], "agreement": "'$AGREEMENT'"}'
  293. fi
  294. _send_signed_request "$API/acme/new-reg" "$regjson"
  295. if [ "$code" == "" ] || [ "$code" == '201' ] ; then
  296. _info "Registered"
  297. echo $response > $WORKING_DIR/account.json
  298. elif [ "$code" == '409' ] ; then
  299. _info "Already registered"
  300. else
  301. _err "Register account Error."
  302. return 1
  303. fi
  304. # verify each domain
  305. _info "Verify each domain"
  306. alldomains=$(echo "$Le_Domain,$Le_Alt" | sed "s/,/ /g")
  307. for d in $alldomains
  308. do
  309. _info "Verifing domain" $d
  310. _send_signed_request "$API/acme/new-authz" "{\"resource\": \"new-authz\", \"identifier\": {\"type\": \"dns\", \"value\": \"$d\"}}"
  311. if [ ! -z "$code" ] && [ ! "$code" == '201' ] ; then
  312. _err "new-authz error: $response"
  313. return 1
  314. fi
  315. http01=$(echo $response | egrep -o '{[^{]*"type":"http-01"[^}]*')
  316. _debug http01 "$http01"
  317. token=$(echo "$http01" | sed 's/,/\n'/g| grep '"token":'| cut -d : -f 2|sed 's/"//g')
  318. _debug token $token
  319. uri=$(echo "$http01" | sed 's/,/\n'/g| grep '"uri":'| cut -d : -f 2,3|sed 's/"//g')
  320. _debug uri $uri
  321. keyauthorization="$token.$thumbprint"
  322. _debug keyauthorization "$keyauthorization"
  323. if [ "$Le_Webroot" == "no" ] ; then
  324. _info "Standalone mode server"
  325. _startserver "$keyauthorization" &
  326. serverproc="$!"
  327. sleep 2
  328. _debug serverproc $serverproc
  329. else
  330. wellknown_path="$Le_Webroot/.well-known/acme-challenge"
  331. _debug wellknown_path "$wellknown_path"
  332. mkdir -p "$wellknown_path"
  333. wellknown_path="$wellknown_path/$token"
  334. echo -n "$keyauthorization" > $wellknown_path
  335. fi
  336. wellknown_url="http://$d/.well-known/acme-challenge/$token"
  337. _debug wellknown_url "$wellknown_url"
  338. _debug challenge "$challenge"
  339. _send_signed_request $uri "{\"resource\": \"challenge\", \"keyAuthorization\": \"$keyauthorization\"}"
  340. if [ ! -z "$code" ] && [ ! "$code" == '202' ] ; then
  341. _err "$d:Challenge error: $resource"
  342. _stopserver $serverproc
  343. return 1
  344. fi
  345. while [ "1" ] ; do
  346. _debug "sleep 5 secs to verify"
  347. sleep 5
  348. _debug "checking"
  349. if ! _get $uri ; then
  350. _err "$d:Verify error:$resource"
  351. _stopserver $serverproc
  352. return 1
  353. fi
  354. status=$(echo $response | egrep -o '"status":"[^"]+"' | cut -d : -f 2 | sed 's/"//g')
  355. if [ "$status" == "valid" ] ; then
  356. _info "Success"
  357. break;
  358. fi
  359. if [ "$status" == "invalid" ] ; then
  360. error=$(echo $response | egrep -o '"error":{[^}]*}' | grep -o '"detail":"[^"]*"' | cut -d '"' -f 4)
  361. _err "$d:Verify error:$error"
  362. _stopserver $serverproc
  363. return 1;
  364. fi
  365. if [ "$status" == "pending" ] ; then
  366. _info "Pending"
  367. else
  368. _err "$d:Verify error:$response"
  369. _stopserver $serverproc
  370. return 1
  371. fi
  372. done
  373. _stopserver $serverproc
  374. done
  375. _info "Verify finished, start to sign."
  376. der="$(openssl req -in $CSR_PATH -outform DER | base64 -w 0 | _b64)"
  377. _send_signed_request "$API/acme/new-cert" "{\"resource\": \"new-cert\", \"csr\": \"$der\"}" "needbase64"
  378. Le_LinkCert="$(grep -i -o '^Location.*' $CURL_HEADER |sed 's/\r//g'| cut -d " " -f 2)"
  379. _setopt "$DOMAIN_CONF" "Le_LinkCert" "=" "$Le_LinkCert"
  380. if [ "$Le_LinkCert" ] ; then
  381. echo -----BEGIN CERTIFICATE----- > "$CERT_PATH"
  382. curl --silent "$Le_LinkCert" | base64 >> "$CERT_PATH"
  383. echo -----END CERTIFICATE----- >> "$CERT_PATH"
  384. _info "Cert success."
  385. cat "$CERT_PATH"
  386. _info "Your cert is in $CERT_PATH"
  387. fi
  388. _setopt "$DOMAIN_CONF" "Le_Domain" "=" "$Le_Domain"
  389. _setopt "$DOMAIN_CONF" "Le_Alt" "=" "$Le_Alt"
  390. _setopt "$DOMAIN_CONF" "Le_Webroot" "=" "$Le_Webroot"
  391. _setopt "$DOMAIN_CONF" "Le_Keylength" "=" "$Le_Keylength"
  392. _setopt "$DOMAIN_CONF" "Le_RealCertPath" "=" "\"$Le_RealCertPath\""
  393. _setopt "$DOMAIN_CONF" "Le_RealCACertPath" "=" "\"$Le_RealCACertPath\""
  394. _setopt "$DOMAIN_CONF" "Le_RealKeyPath" "=" "\"$Le_RealKeyPath\""
  395. _setopt "$DOMAIN_CONF" "Le_ReloadCmd" "=" "\"$Le_ReloadCmd\""
  396. if [ -z "$Le_LinkCert" ] ; then
  397. response="$(echo $response | base64 -d)"
  398. _err "Sign failed: $(echo "$response" | grep -o '"detail":"[^"]*"')"
  399. return 1
  400. fi
  401. Le_LinkIssuer=$(grep -i '^Link' $CURL_HEADER | cut -d " " -f 2| cut -d ';' -f 1 | sed 's/<//g' | sed 's/>//g')
  402. _setopt "$DOMAIN_CONF" "Le_LinkIssuer" "=" "$Le_LinkIssuer"
  403. if [ "$Le_LinkIssuer" ] ; then
  404. echo -----BEGIN CERTIFICATE----- > "$CA_CERT_PATH"
  405. curl --silent "$Le_LinkIssuer" | base64 >> "$CA_CERT_PATH"
  406. echo -----END CERTIFICATE----- >> "$CA_CERT_PATH"
  407. _info "The intermediate CA cert is in $CA_CERT_PATH"
  408. fi
  409. Le_CertCreateTime=$(date -u "+%s")
  410. _setopt "$DOMAIN_CONF" "Le_CertCreateTime" "=" "$Le_CertCreateTime"
  411. Le_CertCreateTimeStr=$(date -u "+%Y-%m-%d %H:%M:%S UTC")
  412. _setopt "$DOMAIN_CONF" "Le_CertCreateTimeStr" "=" "\"$Le_CertCreateTimeStr\""
  413. if [ ! "$Le_RenewalDays" ] ; then
  414. Le_RenewalDays=50
  415. fi
  416. _setopt "$DOMAIN_CONF" "Le_RenewalDays" "=" "$Le_RenewalDays"
  417. Le_NextRenewTime=$(date -u -d "+$Le_RenewalDays day" "+%s")
  418. _setopt "$DOMAIN_CONF" "Le_NextRenewTime" "=" "$Le_NextRenewTime"
  419. Le_NextRenewTimeStr=$(date -u -d "+$Le_RenewalDays day" "+%Y-%m-%d %H:%M:%S UTC")
  420. _setopt "$DOMAIN_CONF" "Le_NextRenewTimeStr" "=" "\"$Le_NextRenewTimeStr\""
  421. if [ "$Le_RealCertPath" ] ; then
  422. if [ -f "$Le_RealCertPath" ] ; then
  423. rm -f "$Le_RealCertPath"
  424. fi
  425. ln -s "$CERT_PATH" "$Le_RealCertPath"
  426. fi
  427. if [ "$Le_RealCACertPath" ] ; then
  428. if [ -f "$Le_RealCACertPath" ] ; then
  429. rm -f "$Le_RealCACertPath"
  430. fi
  431. ln -s "$CA_CERT_PATH" "$Le_RealCACertPath"
  432. fi
  433. if [ "$Le_RealKeyPath" ] ; then
  434. if [ -f "$Le_RealKeyPath" ] ; then
  435. rm -f "$Le_RealKeyPath"
  436. fi
  437. ln -s "$CERT_KEY_PATH" "$Le_RealKeyPath"
  438. fi
  439. if [ "$Le_ReloadCmd" ] ; then
  440. _info "Run Le_ReloadCmd: $Le_ReloadCmd"
  441. "$Le_ReloadCmd"
  442. fi
  443. }
  444. renew() {
  445. Le_Domain="$1"
  446. if [ -z "$Le_Domain" ] ; then
  447. echo Usage: $0 domain.com
  448. return 1
  449. fi
  450. issue $Le_Domain
  451. }
  452. renewAll() {
  453. _initpath
  454. _info "renewAll"
  455. for d in $(ls -F $WORKING_DIR | grep '/$') ; do
  456. d=$(echo $d | cut -d '/' -f 1)
  457. _info "renew $d"
  458. Le_LinkCert=""
  459. Le_Domain=""
  460. Le_Alt=""
  461. Le_Webroot=""
  462. Le_Keylength=""
  463. Le_LinkIssuer=""
  464. Le_CertCreateTime=""
  465. Le_CertCreateTimeStr=""
  466. Le_RenewalDays=""
  467. Le_NextRenewTime=""
  468. Le_NextRenewTimeStr=""
  469. Le_RealCertPath=""
  470. Le_RealKeyPath=""
  471. Le_RealCACertPath=""
  472. Le_ReloadCmd=""
  473. renew "$d"
  474. done
  475. }
  476. install() {
  477. _initpath
  478. if ! command -v "curl" > /dev/null ; then
  479. _err "Please install curl first."
  480. _err "Ubuntu: sudo apt-get install curl"
  481. _err "CentOS: yum install curl"
  482. return 1
  483. fi
  484. if ! command -v "crontab" > /dev/null ; then
  485. _err "Please install crontab first."
  486. _err "CentOs: yum -y install crontabs"
  487. return 1
  488. fi
  489. if ! command -v "openssl" > /dev/null ; then
  490. _err "Please install openssl first."
  491. _err "CentOs: yum -y install openssl"
  492. return 1
  493. fi
  494. if ! command -v "xxd" > /dev/null ; then
  495. _err "Please install xxd first."
  496. _err "CentOs: yum install vim-common"
  497. return 1
  498. fi
  499. _info "Installing to $WORKING_DIR"
  500. if [ ! -f /bin/le.sh ] ; then
  501. cp le.sh "/bin/"
  502. chmod +x "/bin/le.sh"
  503. ln -s "/bin/le.sh" /bin/le
  504. fi
  505. _info "Installing cron job"
  506. if command -v sudo > /dev/null ; then
  507. if [ "$(sudo -n uptime 2>&1|grep "load"|wc -l)" != "0" ] ; then
  508. SUDO=sudo
  509. fi
  510. fi
  511. if ! crontab -l | grep 'le renewAll' ; then
  512. crontab -l | { cat; echo "0 0 * * * $SUDO le renewAll > /dev/null"; } | crontab -
  513. if command -v crond > /dev/null ; then
  514. service crond reload >/dev/null
  515. else
  516. service cron reload >/dev/null
  517. fi
  518. fi
  519. _info OK
  520. }
  521. uninstall() {
  522. _initpath
  523. _info "Removing cron job"
  524. if crontab -l | grep 'le.*renewAll' ; then
  525. crontab -l | sed "/le.*renewAll/d" | crontab -
  526. if command -v crond > /dev/null ; then
  527. service crond reload >/dev/null
  528. else
  529. service cron reload >/dev/null
  530. fi
  531. fi
  532. _info "Removing /bin/le.sh"
  533. rm -f /bin/le
  534. rm -f /bin/le.sh
  535. _info "The keys and certs are in $WORKING_DIR, you can remove them by yourself."
  536. }
  537. showhelp() {
  538. echo "Usage: issue|renew|renewAll|createAccountKey|createDomainKey|createCSR|install|uninstall"
  539. }
  540. if [ -z "$1" ] ; then
  541. showhelp
  542. else
  543. "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
  544. fi