From 6f3ecb076e0c58d03414403f910ecb5f4d634bd3 Mon Sep 17 00:00:00 2001 From: dongdigua Date: Tue, 27 Jun 2023 13:47:08 +0800 Subject: [PATCH] docker: working gmid --- .meta | 4 ---- gmi/docker/Dockerfile | 6 ++++-- gmi/docker/cgi/stat.cgi | 4 ++++ gmi/docker/genkey.sh | 12 ++++++++++++ gmi/docker/gmid.conf | 9 +++++++++ gmi/docker/run-wrapper.sh | 4 +++- gmi/docker/update-git.sh | 1 + 7 files changed, 33 insertions(+), 7 deletions(-) delete mode 100644 .meta create mode 100755 gmi/docker/cgi/stat.cgi create mode 100755 gmi/docker/genkey.sh create mode 100644 gmi/docker/gmid.conf diff --git a/.meta b/.meta deleted file mode 100644 index 2de8754..0000000 --- a/.meta +++ /dev/null @@ -1,4 +0,0 @@ -org/*.org: text/plain -misc/*: text/plain -pgp: text/plain - diff --git a/gmi/docker/Dockerfile b/gmi/docker/Dockerfile index 615a311..ebff9e8 100644 --- a/gmi/docker/Dockerfile +++ b/gmi/docker/Dockerfile @@ -2,16 +2,18 @@ FROM alpine:latest RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \ && sed -i 'a https://mirrors.tuna.tsinghua.edu.cn/alpine/edge/testing' /etc/apk/repositories \ - && apk add agate git python3 perl \ + && apk add gmid git python3 perl \ && touch /var/log/git.log \ && echo "0 * * * * run-parts /etc/periodic/hourly" > /var/spool/cron/crontabs/root RUN git clone https://github.com/dongdigua/dongdigua.github.io.git --depth 1 \ && cd dongdigua.github.io \ && git config filter.dater.smudge 'perl -pe "\$last_date = `git log --pretty=format:\\"%ad\\" -1`;s/\\\$Date\\\$/\\\$Date: \$last_date\\\$/"' \ - && git config filter.dater.clean 'perl -pe "s/\\\$Date[^\\\$]*\\\$/\\\$Date\\\$/"' \ + && git config filter.dater.clean 'perl -pe "s/\\\$Date[^\\\$]*\\\$/\\\$Date\\\$/"' COPY run-wrapper.sh . +COPY gmid.conf /dongdigua.github.io/gmi/docker/ +COPY cgi/* /dongdigua.github.io/gmi/docker/cgi/ COPY update-git.sh /etc/periodic/hourly/ # for testing purpose only diff --git a/gmi/docker/cgi/stat.cgi b/gmi/docker/cgi/stat.cgi new file mode 100755 index 0000000..337b116 --- /dev/null +++ b/gmi/docker/cgi/stat.cgi @@ -0,0 +1,4 @@ +#! /usr/bin/sh + +printf "20 text/gemini\r\n"; +printf "OS: $(uname -rv)\r\nuptime: $(uptime)\r\nserver: $SERVER_SOFTWARE\r\nauth: $AUTH\r\n"; diff --git a/gmi/docker/genkey.sh b/gmi/docker/genkey.sh new file mode 100755 index 0000000..2a58a70 --- /dev/null +++ b/gmi/docker/genkey.sh @@ -0,0 +1,12 @@ +#! /usr/bin/sh + +if test -f /etc/ssl/gmid.pem; then + echo "OK certificate exists" +else + echo "generating certificate..." + apk add libressl + libressl req -x509 -newkey rsa:4096 -nodes \ + -keyout /etc/ssl/private/gmid.key \ + -out /etc/ssl/gmid.pem \ + -days 365 -subj "/CN=$GEMINI_HOST" +fi diff --git a/gmi/docker/gmid.conf b/gmi/docker/gmid.conf new file mode 100644 index 0000000..8fe9fe3 --- /dev/null +++ b/gmi/docker/gmid.conf @@ -0,0 +1,9 @@ +server $gem_host { + cert "/etc/ssl/gmid.pem" + key "/etc/ssl/private/gmid.key" + root "/dongdigua.github.io" + + cgi "/cgi/*" + default type "text/plain" +} + diff --git a/gmi/docker/run-wrapper.sh b/gmi/docker/run-wrapper.sh index 169d59d..350a657 100755 --- a/gmi/docker/run-wrapper.sh +++ b/gmi/docker/run-wrapper.sh @@ -1,8 +1,10 @@ #! /bin/sh +sh genkey.sh + crond -f -d 8 & tail -f /var/log/git.log & -agate -C --content dongdigua.github.io --hostname $GEMINI_HOST +gmid -f -c /dongdigua.github.io/gmi/docker/gmid.conf -Dgem_host=$GEMINI_HOST wait -n echo $? diff --git a/gmi/docker/update-git.sh b/gmi/docker/update-git.sh index 11e9e2d..4cfccff 100755 --- a/gmi/docker/update-git.sh +++ b/gmi/docker/update-git.sh @@ -3,3 +3,4 @@ cd /dongdigua.github.io git pull --rebase >> /var/log/git.log 2>&1 python misc/mdlist2gmi.py > posts.gmi +pkill -HUP gmid