mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-06 21:24:16 +08:00
changed exec stuff and maybe fixed listenport
This commit is contained in:
parent
fbb999f36b
commit
3a77f4df14
5 changed files with 23 additions and 44 deletions
|
@ -3,7 +3,6 @@ package database
|
|||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
@ -29,12 +28,10 @@ var SQLITE_FUNCTIONS = map[string]interface{}{
|
|||
func initSqliteDB() error {
|
||||
// == create db file if not present ==
|
||||
if _, err := os.Stat("data"); os.IsNotExist(err) {
|
||||
log.Println("Could not find data directory, creating it.")
|
||||
os.Mkdir("data", 0644)
|
||||
}
|
||||
dbFilePath := filepath.Join("data", dbFilename)
|
||||
if _, err := os.Stat(dbFilePath); os.IsNotExist(err) {
|
||||
log.Println("Could not get database file, creating it.")
|
||||
os.Create(dbFilePath)
|
||||
}
|
||||
// == "connect" the database ==
|
||||
|
@ -55,7 +52,6 @@ func sqliteCreateTable(tableName string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Println(tableName, "table created")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -70,7 +66,6 @@ func sqliteInsert(key string, value string, tableName string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Println("inserted", key, ":", value, "into ", tableName)
|
||||
return nil
|
||||
} else {
|
||||
return errors.New("invalid insert " + key + " : " + value)
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
|
@ -314,17 +313,13 @@ func RemoveLocalInstance(cfg *config.ClientConfig, networkName string) error {
|
|||
|
||||
func DeleteInterface(ifacename string, postdown string) error {
|
||||
ipExec, err := exec.LookPath("ip")
|
||||
|
||||
cmdIPLinkDel := &exec.Cmd{
|
||||
Path: ipExec,
|
||||
Args: []string{ipExec, "link", "del", ifacename},
|
||||
Stdout: os.Stdout,
|
||||
Stderr: os.Stdout,
|
||||
}
|
||||
err = cmdIPLinkDel.Run()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
out, err := local.RunCmd(ipExec + " link del " + ifacename)
|
||||
if err != nil {
|
||||
log.Println(out, err)
|
||||
}
|
||||
if postdown != "" {
|
||||
runcmds := strings.Split(postdown, "; ")
|
||||
err = local.RunCmds(runcmds)
|
||||
|
|
|
@ -136,12 +136,7 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
|
|||
cfg.Node.MacAddress = macs[0]
|
||||
}
|
||||
}
|
||||
if cfg.Node.ListenPort == 0 {
|
||||
cfg.Node.ListenPort, err = GetFreePort(51821)
|
||||
if err != nil {
|
||||
fmt.Printf("Error retrieving port: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
var wcclient nodepb.NodeServiceClient
|
||||
var requestOpts grpc.DialOption
|
||||
requestOpts = grpc.WithInsecure()
|
||||
|
@ -174,6 +169,7 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
|
|||
SaveConfig: cfg.Node.SaveConfig,
|
||||
UDPHolePunch: cfg.Node.UDPHolePunch,
|
||||
}
|
||||
|
||||
if err = config.ModConfig(postnode); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -200,6 +196,13 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if node.ListenPort == 0 {
|
||||
node.ListenPort, err = GetFreePort(51821)
|
||||
if err != nil {
|
||||
fmt.Printf("Error retrieving port: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if node.DNSOn == "yes" {
|
||||
cfg.Node.DNSOn = "yes"
|
||||
}
|
||||
|
|
|
@ -279,17 +279,13 @@ func WipeLocal(network string) error {
|
|||
}
|
||||
|
||||
ipExec, err := exec.LookPath("ip")
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ifacename != "" {
|
||||
cmdIPLinkDel := &exec.Cmd{
|
||||
Path: ipExec,
|
||||
Args: []string{ipExec, "link", "del", ifacename},
|
||||
Stdout: os.Stdout,
|
||||
Stderr: os.Stdout,
|
||||
}
|
||||
err = cmdIPLinkDel.Run()
|
||||
out, err := RunCmd(ipExec + " link del " + ifacename)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Println(out, err)
|
||||
}
|
||||
if nodecfg.PostDown != "" {
|
||||
runcmds := strings.Split(nodecfg.PostDown, "; ")
|
||||
|
|
|
@ -123,21 +123,11 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
_ = local.UpdateDNS(ifacename, network, nameserver)
|
||||
}
|
||||
//=========End DNS Setup=======\\
|
||||
|
||||
cmdIPLinkUp := &exec.Cmd{
|
||||
Path: ipExec,
|
||||
Args: []string{ipExec, "link", "set", "up", "dev", ifacename},
|
||||
Stdout: os.Stdout,
|
||||
Stderr: os.Stdout,
|
||||
if ipLinkDownOut, err := local.RunCmd(ipExec + " link set down dev " + ifacename); err != nil {
|
||||
log.Println(ipLinkDownOut, err)
|
||||
return err
|
||||
}
|
||||
|
||||
cmdIPLinkDown := &exec.Cmd{
|
||||
Path: ipExec,
|
||||
Args: []string{ipExec, "link", "set", "down", "dev", ifacename},
|
||||
Stdout: os.Stdout,
|
||||
Stderr: os.Stdout,
|
||||
}
|
||||
err = cmdIPLinkDown.Run()
|
||||
if nodecfg.PostDown != "" {
|
||||
runcmds := strings.Split(nodecfg.PostDown, "; ")
|
||||
err = local.RunCmds(runcmds)
|
||||
|
@ -146,8 +136,8 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
}
|
||||
}
|
||||
|
||||
err = cmdIPLinkUp.Run()
|
||||
if err != nil {
|
||||
if ipLinkUpOut, err := local.RunCmd(ipExec + " link set up dev " + ifacename); err != nil {
|
||||
log.Println(ipLinkUpOut, err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue