Created
February 25, 2018 01:21
Star
You must be signed in to star a gist
upgrade_ssl.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
set domain [lindex $argv 0] | |
set www_root [lindex $argv 1] | |
spawn /root/certbot/letsencrypt-auto certonly --manual -d $domain | |
expect { | |
"Cert not yet due for renewal" { | |
close | |
exit 0 | |
} | |
"Cert is due for renewal, auto-renewing..." | |
} | |
expect "(Y)es/(N)o: " | |
send "Y\n" | |
# send_user "test expect 2\n" | |
expect "Create a file containing just this data:" | |
# send_user "done expect 2\n" | |
# send_user "test expect 3\n" | |
expect -r "\r" | |
# send_user "done expect 3\n" | |
# send_user "test expect 4\n" | |
expect -r "\r" | |
# send_user "done expect 4\n" | |
# send_user "test expect 5\n" | |
expect -indices -re "(\[A-Za-z0-9._-]{80,100})" { | |
set challenge_data $expect_out(1,string) | |
} | |
# send_user "done expect 5\n" | |
send_user "The challenge data is: $challenge_data\n" | |
# send_user "test expect 6\n" | |
expect -indices -re "http://.*((/\.well-known/acme-challenge/)\[A-Za-z0-9_-]*)" { | |
set challenge_dir [list {*}$www_root$expect_out(2,string)] | |
set challenge_path [list {*}$www_root$expect_out(1,string)] | |
} | |
# send_user "done expect 6\n" | |
send_user "The challenge dir is: $challenge_dir\n" | |
send_user "The challenge path is: $challenge_path\n" | |
exec mkdir -p $challenge_dir | |
set fileId [open $challenge_path "w"] | |
puts -nonewline $fileId $challenge_data | |
close $fileId | |
expect "Press Enter to Continue" | |
send "\n" | |
expect eof | |
exec /etc/init.d/nginx reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment