diff --git a/netclient-install.sh b/netclient-install.sh index 81621aec..02ae02ae 100755 --- a/netclient-install.sh +++ b/netclient-install.sh @@ -7,7 +7,7 @@ set -e -wget -O netclient https://github.com/gravitl/netmaker/releases/download/v0.1/netclient +wget -O netclient https://github.com/gravitl/netmaker/releases/download/v0.1/netclient netclient chmod +x netclient sudo ./netclient -c install -s $SERVER_URL -g $NET_NAME -k $KEY rm -f netclient diff --git a/netclient/functions/common.go b/netclient/functions/common.go index 385bba75..a6fff8a3 100644 --- a/netclient/functions/common.go +++ b/netclient/functions/common.go @@ -79,6 +79,12 @@ func Install(accesskey string, password string, server string, group string, noa tnetwork := "" tkey := "" + if FileExists("/etc/systemd/system/netclient-"+group+".timer") || + FileExists("/etc/netclient/netconfig-"+group) { + err := errors.New("ALREADY_INSTALLED. Netclient appears to already be installed for network " + group + ". To re-install, please remove by executing 'sudo netclient -c remove -n " + group + "'. Then re-run the install command.") + return err + } + if accesstoken != "" && accesstoken != "badtoken" { btoken, err := base64.StdEncoding.DecodeString(accesstoken) if err != nil { diff --git a/netclient/functions/local.go b/netclient/functions/local.go index 5e53568a..c2962655 100644 --- a/netclient/functions/local.go +++ b/netclient/functions/local.go @@ -12,7 +12,7 @@ import ( ) -func fileExists(f string) bool { +func FileExists(f string) bool { info, err := os.Stat(f) if os.IsNotExist(err) { return false @@ -45,14 +45,17 @@ func ConfigureSystemD(network string) error { return err } - if !fileExists("/usr/local/bin/netclient") { + if !FileExists("/usr/local/bin/netclient") { + os.Symlink("/etc/netclient/netclient","/usr/local/bin/netclient") + /* _, err = copy(binarypath, "/usr/local/bin/netclient") if err != nil { log.Println(err) return err } + */ } - if !fileExists("/etc/netclient/netclient") { + if !FileExists("/etc/netclient/netclient") { _, err = copy(binarypath, "/etc/netclient/netclient") if err != nil { log.Println(err) @@ -100,7 +103,7 @@ WantedBy=timers.target servicebytes := []byte(systemservice) timerbytes := []byte(systemtimer) - if !fileExists("/etc/systemd/system/netclient@.service") { + if !FileExists("/etc/systemd/system/netclient@.service") { err = ioutil.WriteFile("/etc/systemd/system/netclient@.service", servicebytes, 0644) if err != nil { log.Println(err) @@ -108,7 +111,7 @@ WantedBy=timers.target } } - if !fileExists("/etc/systemd/system/netclient-"+network+".timer") { + if !FileExists("/etc/systemd/system/netclient-"+network+".timer") { err = ioutil.WriteFile("/etc/systemd/system/netclient-"+network+".timer", timerbytes, 0644) if err != nil { log.Println(err) diff --git a/netclient/main.go b/netclient/main.go index b9568534..738ccbdb 100644 --- a/netclient/main.go +++ b/netclient/main.go @@ -110,6 +110,7 @@ func main() { fmt.Println("Beginning agent installation.") err := functions.Install(*taccesskey, *tpassword, *tserver, *tnetwork, *tnoauto, *taccesstoken, *tname) if err != nil { + if !strings.Contains(err.Error(), "ALREADY_INSTALLED") { fmt.Println("Error installing: ", err) fmt.Println("Cleaning up (uninstall)") err = functions.Remove(*tnetwork) @@ -126,6 +127,10 @@ func main() { } } os.Exit(1) + } else { + fmt.Println(err.Error()) + os.Exit(1) + } } /* case "service-install":