Skip to content

Instantly share code, notes, and snippets.

@sammy8806
Last active August 23, 2019 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sammy8806/d50af6164061b72211ed6b255bf78566 to your computer and use it in GitHub Desktop.
Save sammy8806/d50af6164061b72211ed6b255bf78566 to your computer and use it in GitHub Desktop.
# Contributed by: Steven Tappert <admin@dark-it.net>
. "$SUBR_DIR/ip"
WgConfig=("${WgConfig}")
wireguard_up() {
if is_interface "$Interface"; then
report_error "Interface '$Interface' already exists"
return 1
fi
interface_add wireguard "$Interface"
if ! is_interface "$Interface"; then
report_error "Interface '$Interface' could not be created!"
return 1
fi
wg setconf "$Interface" "$WgConfig"
bring_interface_up "$Interface"
ip_set
}
wireguard_down() {
ip unset
interface_delete "$Interface"
}
@TobleMiner
Copy link

I'd suggest the following patch for better error handling:

--- old/wireguard	2019-08-23 18:38:36.237784076 +0000
+++ new/wireguard	2019-08-23 18:38:21.238639227 +0000
@@ -1,8 +1,14 @@
+#!/usr/bin/env bash
+
+set -e
+
 # Contributed by: Steven Tappert <admin@dark-it.net>
 
 . "$SUBR_DIR/ip"
 
-WgConfig=("${WgConfig}")
+if [ -z "$WgConfig" ]; then
+        WgConfig="/etc/wireguard/$Interface.conf"
+fi
 
 wireguard_up() {
         if is_interface "$Interface"; then
@@ -17,7 +23,17 @@
                 return 1
         fi
 
-        wg setconf "$Interface" "$WgConfig"
+        if ! [ -f "$WgConfig" ]; then
+                report_error "Wireguard config file '"$WgConfig"' does not exist"
+                interface_delete "$Interface"           
+                return 1                
+        fi
+
+        if ! wg setconf "$Interface" "$WgConfig"; then
+                report_error "Failed to configure wireguard on "Interface" using "$WgConfig""
+                interface_delete "$Interface"
+                return 1
+        fi
 
         bring_interface_up "$Interface"
         ip_set
@@ -27,4 +43,3 @@
         ip unset
         interface_delete "$Interface"
 }
-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment