reid 2 ani în urmă
părinte
comite
fb07ba5293
1 a modificat fișierele cu 22 adăugiri și 20 ștergeri
  1. 22 20
      docker/wireguard.go

+ 22 - 20
docker/wireguard.go

@@ -89,10 +89,12 @@ func WriteWgConf() error {
 	existingConf, err := ioutil.ReadFile(filePath)
 	if err != nil {
 		// assume it doesn't exist, so write the current config
+		logger.Info("Creating WG config")
 		return writeWgConfToFile(filePath, newConf)
 	}
 	if string(existingConf) != newConf {
 		// If they differ, overwrite
+		logger.Info("Updating WG config")
 		return writeWgConfToFile(filePath, newConf)
 	}
 	return nil
@@ -100,26 +102,26 @@ func WriteWgConf() error {
 
 // either write directly or create volumes
 func writeWgConfToFile(filePath string, content string) error {
-    // try writing
-    err := ioutil.WriteFile(filePath, []byte(content), 0644)
-    if err == nil {
-        return nil
-    }
-    // ensure the directory structure exists
-    dir := filepath.Dir(filePath)
-    if err = os.MkdirAll(dir, 0755); err != nil {
-        return err
-    }
-    // try writing again
-    err = ioutil.WriteFile(filePath, []byte(content), 0644)
-    if err != nil {
-        err = copyFileToVolume(filePath, "/etc/wireguard/", "wireguard")
-        // otherwise create the volume
-        if err != nil {
-            return fmt.Errorf("Failed to copy WG config file to volume: %v", err)
-        }
-    }
-    return nil
+	// try writing
+	err := ioutil.WriteFile(filePath, []byte(content), 0644)
+	if err == nil {
+		return nil
+	}
+	// ensure the directory structure exists
+	dir := filepath.Dir(filePath)
+	if err = os.MkdirAll(dir, 0755); err != nil {
+		return err
+	}
+	// try writing again
+	err = ioutil.WriteFile(filePath, []byte(content), 0644)
+	if err != nil {
+		err = copyFileToVolume(filePath, "/etc/wireguard/", "wireguard")
+		// otherwise create the volume
+		if err != nil {
+			return fmt.Errorf("Failed to copy WG config file to volume: %v", err)
+		}
+	}
+	return nil
 }
 
 // write wg conf to volume