From e3eb3e4594638f9facd652c9d51ecf84b24df461 Mon Sep 17 00:00:00 2001
From: The_Spider <nhyatt@smoothnet.org>
Date: Wed, 2 Mar 2022 11:24:19 -0600
Subject: [PATCH] deluge changed to alpine base

---
 build-deluge.jenkins | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/build-deluge.jenkins b/build-deluge.jenkins
index f9cd977..682a73d 100644
--- a/build-deluge.jenkins
+++ b/build-deluge.jenkins
@@ -3,37 +3,39 @@
 def repository = "registry.c.test-chamber-13.lan"
 def repositoryCreds = "harbor-repository-creds"
 
-def connectivity_test = """#! /usr/bin/env bash
-curl --silent --fail --insecure http://localhost:8112 > /dev/null
-if [[ "\${?}" != "0" ]]; then
+def route_override = """#! /usr/bin/env sh
+VPN_GATEWAY=\$(ip route | grep default | awk '{print $3}')
+ip route add 10.42.0.0/16 via "\${VPN_GATEWAY}" dev eth0
+ip route add 10.43.0.0/16 via "\${VPN_GATEWAY}" dev eth0
+ip route add 10.20.0.0/16 via "\${VPN_GATEWAY}" dev eth0
+ip route del default via "\${VPN_GATEWAY}"
+printf "%s\n" "Route Updated"
+"""
+
+def connectivity_test = """#! /usr/bin/env sh
+if ! curl --silent --fail --insecure http://localhost:8112 > /dev/null; then
 	printf '%s\\n' "Deluge not running."
 	exit 100
 fi
-
-if [[ -z "\${DDNS_HOST}" ]] || [[ "\${DDNS_HOST}" == "" ]]; then
+if [ -z "\${DDNS_HOST}" ] || [ "\${DDNS_HOST}" = "" ]; then
 	printf '%s\\n' "Dynamic DNS host is not set."
 	exit 100
 fi
-
 DIP=\$(dig -4 @ns1.google.com TXT o-o.myaddr.l.google.com +short | sed -e 's/"//g')
-if [[ -z "\${DIP+x}" ]] || [[ "\${DIP}" == "" ]]; then
+if [ -z "\${DIP+x}" ] || [ "\${DIP}" = "" ]; then
 	printf '%s\\n' "Unable to detect real-world IP."
 	exit 100
 fi
-
-KIP=\$(dig \${DDNS_HOST} +short)
-if [[ -z "\${KIP+x}" ]] || [[ "\${KIP}" == "" ]]; then
+KIP=\$(dig "\${DDNS_HOST}" +short)
+if [ -z "\${KIP+x}" ] || [ "\${KIP}" = "" ]; then
 	printf '%s\\n' "Unable to get known IP."
 	exit 100
 fi
-
-if [[ "\${DIP}" == "\${KIP}" ]]; then
+if [ "\${DIP}" = "\${KIP}" ]; then
 	printf '%s\\n' "VPN is not functional."
 	exit 100
 fi
-
-ping -c 2 google.com > /dev/null
-if [[ "\${?}" != "0" ]]; then
+if ! ping -c 2 google.com > /dev/null; then
 	printf '%s\\n' "No internet connectivity."
 	exit 100
 fi
@@ -42,13 +44,10 @@ fi
 def dockerFile = """FROM ${repository}/linuxserver/linuxserver/deluge:amd64-latest
 LABEL maintainer="The_Spider <spider@smoothnet.org>"
 
-COPY connectivity_test.sh /root/connectivity_test.sh
+COPY /root/route-override.sh connectivity_test.sh /root/
 
-RUN apt-get update && \\
-	apt-get install -y openvpn iputils-ping dnsutils && \\
-	apt-get clean && \\
-	rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* && \\
-    chmod +x /root/connectivity_test.sh
+RUN apk add --no-cache openvpn iputils bind-tools && \\
+    chmod +x /root/route-override.sh /root/connectivity_test.sh
 """
 
 def label = "kubernetes-${UUID.randomUUID().toString()}"
@@ -65,6 +64,7 @@ podTemplate(
     node (label) {
         def workspace = pwd()
 
+        writeFile(file: workspace + "/route-override.sh", text: route_override)
         writeFile(file: workspace + "/connectivity_test.sh", text: connectivity_test)
 
         functions.buildContainer(