Created
April 17, 2017 17:41
-
-
Save lukas2511/fdbf3ac4c34ce445a772234e1c996752 to your computer and use it in GitHub Desktop.
openwrt dehydrated stuff
This file contains hidden or 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
#!/bin/bash | |
hostname="$(uci get "system.@system[0].hostname")" | |
if [ -n "${1:-}" ]; then | |
if [ "${1}" = "serve" ]; then | |
printf "HTTP/1.1 200 OK\r\n" | |
printf "Server: Socken Katze\r\n" | |
printf "X-Powered-By: Pink Fluffy Unicorns Dancing On Rainbows\r\n" | |
printf "Connection: close\r\n" | |
printf "Date: $(date -R)\r\n" | |
printf "\r\n" | |
cat /tmp/challenge | |
elif [ "${1}" = "deploy_challenge" ]; then | |
echo "${4}" > /tmp/challenge | |
elif [ "${1}" = "deploy_cert" ]; then | |
uci set uhttpd.main.cert="/etc/dehydrated/certs/${hostname}/fullchain.pem" | |
uci set uhttpd.main.key="/etc/dehydrated/certs/${hostname}/privkey.pem" | |
uci commit uhttpd | |
/etc/init.d/uhttpd reload | |
fi | |
exit 0 | |
fi | |
socat TCP-LISTEN:8080,reuseaddr EXEC:"dehydrated-run.sh serve" & | |
server="${!}" | |
if [ ! -e /etc/dehydrated ]; then | |
mkdir /etc/dehydrated | |
mkdir /etc/dehydrated/challenges | |
echo 'WELLKNOWN=/etc/dehydrated/challenges' > /etc/dehydrated/config | |
echo 'HOOK=/sbin/dehydrated-run.sh' >> /etc/dehydrated/config | |
fi | |
if [ ! -e /etc/dehydrated/accounts/*/registration_info.json ]; then | |
rm -rf /etc/dehydrated/accounts | |
dehydrated --register --accept-terms | |
fi | |
dehydrated -c -d "${hostname}" | |
if [ "$(readlink /proc/${server}/exe)" = "/usr/bin/socat" ]; then | |
echo "Server still active.. killing." | |
kill $server | |
fi |
hostname="$(uci get "system.@System[0].hostname")"
Maybe it should be better to get the domain by
hostname
command?printf "Date: $(date -R)\r\n"
The header should be not necessary. Also you must return the date in GMT zone:
TZ=GMT date -R
socat
The socat must be compiled on BusyBox.
Hey. This was basically just a proof-of-concept and definitively not an ideal solution. I'll leave it as since these are just results of an experiment. I'm working on more documentation and might write a paragraph about setting up dehydrated on openwrt, but that will take some time, especially since I'll have to set up an openwrt device for testing etc.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe it should be better to get the domain by
hostname
command?The header should be not necessary. Also you must return the date in GMT zone:
TZ=GMT date -R
The socat must be compiled on BusyBox.