8 Commits

3 changed files with 36 additions and 1 deletions

View File

@ -2,7 +2,7 @@
GO111MODULE=on
VERSION=0.0.07
VERSION=0.0.12
USER_GH=eyedeekay
version:

View File

@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
"os/user"
"runtime"
"strings"
@ -198,3 +199,37 @@ func FindI2PIsInstalledDefaultLocation() (string, error) {
}
return "", fmt.Errorf("i2p router not found.")
}
func ConditionallyLaunchI2P() (bool, error) {
ok, err := CheckI2PIsInstalledDefaultLocation()
if err != nil {
return false, err
}
if ok {
if ok, err := CheckI2PIsRunning(); err == nil {
if !ok {
path, err := FindI2PIsInstalledDefaultLocation()
if err != nil {
return false, err
}
if strings.HasSuffix(path, "i2prouter") {
cmd := exec.Command(path, "start")
if err := cmd.Start(); err != nil {
return false, fmt.Errorf("I2P router startup failure", err)
}
} else {
cmd := exec.Command(path, "--daemon")
if err := cmd.Start(); err != nil {
return false, fmt.Errorf("I2P router startup failure", err)
}
}
return true, nil
}
return true, nil
} else {
return false, err
}
} else {
return false, fmt.Errorf("I2P is not a default location, please set $I2P environment variable")
}
}

Binary file not shown.