Now detects the OS at compilation
Using build tags was a more elegant way of determining the OS. Hopefully making less room for errors and easier configuration later Also it is now a negligibly smaller binaryexperimental
parent
38f54c8cdb
commit
011feaf557
|
|
@ -22,7 +22,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"os"
|
||||
"io"
|
||||
"bufio"
|
||||
|
|
@ -31,6 +30,7 @@ import (
|
|||
"flag"
|
||||
"time"
|
||||
"fmt"
|
||||
sysos "jbreich/rhosts/sys"
|
||||
)
|
||||
// siteList holds the location of all the sites along with a list of their location
|
||||
type siteList struct {
|
||||
|
|
@ -99,7 +99,7 @@ func main() {
|
|||
log.Print("interval:",interval)
|
||||
}
|
||||
|
||||
sysdetect (&tmpdir, &hostsloc, &cfgloc)
|
||||
sysos.Detect (&tmpdir, &hostsloc, &cfgloc)
|
||||
|
||||
for true {
|
||||
var sites, downloads, whitelist []string
|
||||
|
|
@ -149,25 +149,6 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
// sysdetect determines which OS it is running on and set the default locations
|
||||
func sysdetect (tmpdir, hostsloc, cfgloc *string) {
|
||||
// Detect OS and set params
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
//log.Fatal("Windows is not supported")
|
||||
*tmpdir = "/tmp"
|
||||
*hostsloc = "/Windows/System32/drivers/etc/hosts"
|
||||
*cfgloc = "/ProgramData/rhosts/"
|
||||
case "linux":
|
||||
*tmpdir = "/tmp/"
|
||||
*hostsloc = "/etc/hosts"
|
||||
*cfgloc ="/etc/rhosts/"
|
||||
case "ios":
|
||||
log.Fatal("IOS is not supported")
|
||||
default:
|
||||
log.Fatal(runtime.GOOS," is not supported")
|
||||
}
|
||||
}
|
||||
|
||||
// cfgparse recieves the location of the config file and returns a list of sites to add and content to download
|
||||
func cfgparse (sites, downloads, whitelist *[]string, cfgloc string) (error){
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
// +build linux
|
||||
|
||||
package sys
|
||||
|
||||
|
||||
func init(){
|
||||
|
||||
system.os = "linux"
|
||||
system.tmpdir = "/tmp/"
|
||||
system.hostsloc = "/etc/hosts"
|
||||
system.cfgloc = "/etc/rhosts/"
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// This manages all the system specific settings
|
||||
package sys
|
||||
|
||||
import (
|
||||
"log"
|
||||
)
|
||||
|
||||
var system struct {
|
||||
os string
|
||||
tmpdir string
|
||||
hostsloc string
|
||||
cfgloc string
|
||||
}
|
||||
|
||||
func Detect (tmpdirp, hostslocp, cfglocp *string) {
|
||||
if (system.os == "") {
|
||||
log.Panic("This OS does not seem to be supported")
|
||||
}
|
||||
*tmpdirp = system.tmpdir
|
||||
*hostslocp = system.hostsloc
|
||||
*cfglocp = system.cfgloc
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
// +build windows
|
||||
|
||||
package sys
|
||||
|
||||
|
||||
var os string = "windows"
|
||||
var tmpdir string = "/tmp/"
|
||||
var hostsloc string = "/Windows/System32/drivers/etc/hosts"
|
||||
var cfgloc string = "/ProgramData/rhosts/"
|
||||
|
||||
Loading…
Reference in New Issue