From fe641afd86d431263b5b6a569954607287e24e3b Mon Sep 17 00:00:00 2001 From: aptalca Date: Mon, 7 Feb 2022 12:41:35 -0500 Subject: [PATCH] make params required, disable service if not configured conrrectly --- README.md | 30 ++++++++-------------- root/etc/cont-init.d/98-cloudflared-config | 25 ++++-------------- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index a15b568..a93ea93 100644 --- a/README.md +++ b/README.md @@ -14,29 +14,19 @@ Here an example snippet to help you get started using this docker mod. ```yaml swag: - image: ghcr.io/linuxserver/swag - container_name: swag - cap_add: - - NET_ADMIN + image: lscr.io/linuxserver/nginx + container_name: nginx environment: PUID: 1000 PGID: 1000 TZ: Europe/London - URL: yourdomain.url - SUBDOMAINS: test, - VALIDATION: dns - DNSPLUGIN: cloudflare #optional - ONLY_SUBDOMAINS: true #optional - EMAIL: #optional - EXTRA_DOMAINS: #optional - STAGING: false #optional DOCKER_MODS: linuxserver/mods:universal-cloudflared - CF_ZONE_ID: #optional - CF_ACCOUNT_ID: #optional - CF_API_TOKEN: #optional - CF_TUNNEL_NAME: example #optional - CF_TUNNEL_PASSWORD: pleasedontusethisexamplepassword #optional - CF_TUNNEL_CONFIG: | #optional + CF_ZONE_ID: zone_id + CF_ACCOUNT_ID: acct_id + CF_API_TOKEN: token + CF_TUNNEL_NAME: example + CF_TUNNEL_PASSWORD: pleasedontusethisexamplepassword + CF_TUNNEL_CONFIG: | ingress: - hostname: test.yourdomain.url service: http://localhost:80 @@ -54,7 +44,7 @@ Container images/mods are configured using parameters passed at runtime (such as | :----: | --- | --- | | `DOCKER_MODS` | Enable this docker mod with `linuxserver/mods:universal-cloudflared` | If adding multiple mods, enter them in an array separated by `\|`, such as `DOCKER_MODS: linuxserver/mods:universal-cloudflared\|linuxserver/mods:universal-mod2` | -### Optional tunnel parameters +### Cloudflare tunnel parameters | Parameter | Function | Notes | | :----: | --- | --- | @@ -72,7 +62,7 @@ Container images/mods are configured using parameters passed at runtime (such as If you're using a method that doesn't allow you to enter a properly formatted yaml into an environment variable (e.g. `docker run`, or the compose yaml format we recommend in our samples, or a web gui manager) you can alternatively use a yaml file to set the `CF_TUNNEL_CONFIG` variable. -Create a properly formatted yaml file in the `/config` folder of your container (e.g. `/config/tunnelconfig.yaml`): +Create a properly formatted yaml file in the `/config` folder of your container (e.g. `/config/tunnelconfig.yml`): ```shell ingress: diff --git a/root/etc/cont-init.d/98-cloudflared-config b/root/etc/cont-init.d/98-cloudflared-config index 34d46a9..fafe919 100644 --- a/root/etc/cont-init.d/98-cloudflared-config +++ b/root/etc/cont-init.d/98-cloudflared-config @@ -70,10 +70,11 @@ else fi cloudflared -v -echo "**** Checking for optional cloudflare tunnel parameters... ****" -if [[ ${#CF_ACCOUNT_ID} -gt 0 ]] && [[ ${#CF_API_TOKEN} -gt 0 ]] && [[ ${#CF_TUNNEL_NAME} -gt 0 ]]; then +echo "**** Checking for cloudflare tunnel parameters... ****" +if [[ ${#CF_ZONE_ID} -gt 0 ]] && [[ ${#CF_ACCOUNT_ID} -gt 0 ]] && [[ ${#CF_API_TOKEN} -gt 0 ]] && [[ ${#CF_TUNNEL_NAME} -gt 0 ]] && [[ ${#CF_TUNNEL_CONFIG} -gt 0 ]]; then if [[ ${#CF_TUNNEL_PASSWORD} -le 32 ]]; then echo "**** Cloudflare tunnel password must be at least 32 characters long, exiting... ****" + rm -rf /etc/services.d/cloudflared exit 1 else echo "**** Cloudflare tunnel parameters found, starting cloudflare tunnel setup... ****" @@ -162,24 +163,8 @@ if [[ ${#CF_ACCOUNT_ID} -gt 0 ]] && [[ ${#CF_API_TOKEN} -gt 0 ]] && [[ ${#CF_TUN done fi else - echo "**** Optional parameters blank or missing, skipped cloudflare tunnel setup ****" + echo "**** Cloudflare parameters blank or missing, skipped cloudflare tunnel setup ****" + rm -rf /etc/services.d/cloudflared fi -echo "**** Cleaning up cloudflared setup script dependencies if required... ****" -for PKG in "${!CLEANUP[@]}"; do - if [ "${CLEANUP[$PKG]}" = true ]; then - CLEANUP[$PKG]=false - echo "**** Uninstalling ${PKG}... ****" - if $ALPINE; then - apk del ${PKG} - elif $UBUNTU; then - apt-get -qqy remove ${PKG} - apt-get -qqy autoremove - fi - fi -done - -echo "**** Uninstalling /tmp/yq... ****" -rm /tmp/yq - echo "**** Cloudflared setup script done, exiting... ****" \ No newline at end of file