|
|
@@ -79,6 +79,7 @@ func buildWgConf() (string, error) {
|
|
|
return res, nil
|
|
|
}
|
|
|
|
|
|
+// write latest conf
|
|
|
func writeWgConf() error {
|
|
|
newConf, err := buildWgConf()
|
|
|
if err != nil {
|
|
|
@@ -97,15 +98,16 @@ func writeWgConf() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// either write directly or create volumes
|
|
|
func writeWgConfToFile(filePath string, content string) error {
|
|
|
+ // try writing to path
|
|
|
err := ioutil.WriteFile(filePath, []byte(content), 0644)
|
|
|
if err != nil {
|
|
|
- return fmt.Errorf("Failed to write new WG config: %v", err)
|
|
|
- }
|
|
|
- // Copy to volume
|
|
|
- err = copyFileToVolume(filePath, "/etc/wireguard/", "wireguard")
|
|
|
- if err != nil {
|
|
|
- return fmt.Errorf("Failed to copy WG config file to volume: %v", err)
|
|
|
+ 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
|
|
|
}
|
|
|
@@ -145,4 +147,4 @@ func copyFileToVolume(filePath string, targetPath string, volumeName string) err
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
-}
|
|
|
+}
|