diff --git a/docker-compose-tunnels.yml b/docker-compose-tunnels.yml new file mode 100644 index 0000000..bd55fbf --- /dev/null +++ b/docker-compose-tunnels.yml @@ -0,0 +1,40 @@ +version: "3.7" +services: + nginx: + container_name: nginx + restart: unless-stopped + hostname: ${DOMAIN_NAME:?err} + volumes: + - './repo:/var/lib/nginx/html/repo/chaotic-aur:ro' + - './data/acme-webroot:/var/lib/nginx/html/acme:ro' + - './data/letsencrypt/etc:/etc/letsencrypt:ro' + - './preset/nginx.conf:/etc/nginx/nginx.conf:ro' + - './preset/conf.d-tunnels:/etc/nginx/conf.d:ro' + image: nginx + + syncthing: + image: linuxserver/syncthing + container_name: syncthing + hostname: ${DOMAIN_NAME:?err} + environment: + - PUID=1000 + - PGID=1000 + - TZ=Europe/London + volumes: + - './data/syncthing:/config' + - './repo:/repo' + ports: + - 8384:8384 + - 22000:22000/tcp + - 22000:22000/udp + - 21027:21027/udp + restart: unless-stopped + + cloudflared: + image: cloudflare/cloudflared:2022.2.2 + container_name: cloudflared + command: tunnel run --url http://nginx ${DOMAIN_NAME:?err} + user: root + volumes: + - './data/cloudflared/etc:/etc/cloudflared' + - './data/cloudflared/home:/root' diff --git a/preset/conf.d-tunnels/chaotic.conf b/preset/conf.d-tunnels/chaotic.conf new file mode 100644 index 0000000..986be85 --- /dev/null +++ b/preset/conf.d-tunnels/chaotic.conf @@ -0,0 +1,22 @@ +server { + listen 80; + autoindex on; + autoindex_exact_size off; + autoindex_format xml; + + root /var/lib/nginx/html/repo; + location ~* /chaotic-aur/x86_64/(?!.*chaotic-aur\.(db|files)).+\.tar.* { + add_header Cache-Control "max-age=150, stale-while-revalidate=150, stale-if-error=86400"; + } + location / { + xslt_string_param path $uri; + xslt_string_param hostname $hostname; + xslt_stylesheet /etc/nginx/conf.d/style.xslt; + add_header Cache-Control 'no-cache'; + } + location ~ /.well-known/acme-challenge { + allow all; + autoindex off; + root /var/lib/nginx/html/acme; + } +} diff --git a/preset/conf.d-tunnels/status.conf b/preset/conf.d-tunnels/status.conf new file mode 100644 index 0000000..bc12071 --- /dev/null +++ b/preset/conf.d-tunnels/status.conf @@ -0,0 +1,11 @@ +server { + listen 81; + access_log off; + + location /nginx_status { + # freely available with open source NGINX + stub_status; + # ensures the version information can be retrieved + server_tokens on; + } +} diff --git a/preset/conf.d-tunnels/style.xslt b/preset/conf.d-tunnels/style.xslt new file mode 100644 index 0000000..e8ec42a --- /dev/null +++ b/preset/conf.d-tunnels/style.xslt @@ -0,0 +1,337 @@ + + + + + ]> + + + + + + + + + - + + + B + + + K + + + M + + + G + + + + + + + + + + + + + + + + + + + + + + + + - + Directory + + + + + + + + + + + + + + + + + + + + + File + + + + + + + + + + + Index of + + <xsl:value-of select="$path"/> + + + + +
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameLast ModifiedSizeType
     
+ +
+
+
+
+ Directories, Files, Total +
+
powered by Nginx
+ +
+ + +
+
diff --git a/run b/run index 11c78b3..1a52b21 100755 --- a/run +++ b/run @@ -2,17 +2,37 @@ set -e +if [[ $EUID -ne 0 ]]; then + echo Run as root! + exit 1 +fi + if [ ! -e ./.env ]; then read -p 'Domain that will serve the mirror: ' domain - read -p 'Your email address: ' email echo "DOMAIN_NAME=$domain" > ./.env - echo "EMAIL=$email" >> ./.env + read -p "Use cloudflare tunnels y/N " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]] + then + USE_TUNNELS=true + echo "USE_TUNNELS=true" >> ./.env + echo "SSL_FILE=/dev/null" >> ./.env + else + read -p 'Your email address: ' email + echo "EMAIL=$email" >> ./.env + fi fi source .env -if [ ! -e ./data/letsencrypt/etc/renewal/chaotic.conf ]; then - docker run -p 80:80 -p 443:443 -it --rm -v "$PWD/data/letsencrypt/etc:/etc/letsencrypt" -v "$PWD/data/letsencrypt/var:/var/lib/letsencrypt" certbot/certbot certonly --standalone --agree-tos --cert-name chaotic -n -m "$EMAIL" -d "$DOMAIN_NAME" +if [ "$USE_TUNNELS" != "true" ]; then + if [ ! -e ./data/letsencrypt/etc/renewal/chaotic.conf ]; then + docker run -p 80:80 -p 443:443 -it --rm -v "$PWD/data/letsencrypt/etc:/etc/letsencrypt" -v "$PWD/data/letsencrypt/var:/var/lib/letsencrypt" certbot/certbot certonly --standalone --agree-tos --cert-name chaotic -n -m "$EMAIL" -d "$DOMAIN_NAME" + fi +elif [ ! -e "./data/cloudflared/home/.cloudflared/cert.pem" ]; then + docker-compose -f docker-compose-tunnels.yml run --rm cloudflared login + docker-compose -f docker-compose-tunnels.yml run --rm cloudflared tunnel create $DOMAIN_NAME + docker-compose -f docker-compose-tunnels.yml run --rm cloudflared tunnel route dns $DOMAIN_NAME $DOMAIN_NAME fi if [ ! -e ./repo ]; then @@ -26,4 +46,8 @@ if [ ! -e ./data/syncthing/config.xml ]; then chown -R 1000:1000 ./data/syncthing fi -docker-compose -f docker-compose.yml up -d +if [ "$USE_TUNNELS" != "true" ]; then + docker-compose -f docker-compose.yml up -d +else + docker-compose -f docker-compose-tunnels.yml up -d +fi