From: Mark Wooding Date: Mon, 21 Dec 2015 02:45:28 +0000 (+0000) Subject: Early commit for testing elsewhere. X-Git-Url: https://git.distorted.org.uk/~mdw/distorted-letsencrypt/commitdiff_plain/55799f78d34a59c5ce7f7613b1351b130b5c5ad1 Early commit for testing elsewhere. --- 55799f78d34a59c5ce7f7613b1351b130b5c5ad1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2978b42 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +.cache +.ccache +.config +.lesshst +.local +cert/ +etc/ +log/ +req/ +tmp/ +webroot/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e087ce7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "letsencrypt"] + path = letsencrypt + url = https://github.com/letsencrypt/letsencrypt/ diff --git a/bin/le b/bin/le new file mode 100755 index 0000000..11963b5 --- /dev/null +++ b/bin/le @@ -0,0 +1,10 @@ +#! /bin/sh +set -e +. "${0%/*}/../config.sh" +. $home/lib/lib.sh + +run_as_user "$@" +prepare_tmp le-user +make_le_conf + +exec $home/letsencrypt/letsencrypt-auto -c "$tmp/le.conf" "$@" diff --git a/bin/make-cert b/bin/make-cert new file mode 100755 index 0000000..8c5605b --- /dev/null +++ b/bin/make-cert @@ -0,0 +1,30 @@ +#! /bin/sh +set -e +. "${0%/*}/../config.sh" +. "$home/lib/lib.sh" + +run_as_user "$@" + +## Pick out the certificate tag. +case $# in 0) fail_usage ;; esac +tag=$1; shift +case $# in 0) ;; *) fail_usage ;; esac + +prepare_tmp $tag + +## Get started. +cd $home/cert/$tag +openssl req -in req -out $tmp/req.der -outform der +sans=$(openssl req -in req -text -noout | + sed -n ' + x + /^ *X509v3 Subject Alternative Name: $/ { + x + s/ *DNS://g + s/,/ /g + p + x + }') +make_le_conf $sans + +cat "$tmp/le.conf" diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..13c9bb3 --- /dev/null +++ b/bin/setup @@ -0,0 +1,24 @@ +#! /bin/sh +set -ex + +user=letsencrypt +home=$(getent passwd $user | cut -d: -f6) +cd $home + +while read d m u g; do + mkdir -p $d + chmod $m $d + chown $u:$g $d +done <&2 "$prog: $*"; exit 1; } +fail_usage () { usage >&2; exit 1; } + +run_as_user () { + case $(id -un) in + $user) ;; + *) exec sudo -u$user "$0" "$@" ;; + esac + HOME=$home; export HOME + PATH=$home/bin:/usr/local/bin:/bin:/usr/bin; export PATH +} + +prepare_tmp () { + tag=$1 + + tmp=$home/tmp/$tag.$$ + rm -rf $tmp + mkdir $tmp + trap 'cd $home; rm -rf $tmp' EXIT INT TERM +} + +make_le_conf () { + { cat $home/le.conf.skel + echo "work-dir = $tmp" + echo + case $# in + 0) ;; + *) + map="webroot-map = {" sep=" " + for san in "$@"; do + map="$map$sep\"$san\": \"$home/webroot\"" sep=", " + done + map="$map }" + echo "$map" + ;; + esac + } >$tmp/le.conf +} \ No newline at end of file