Added minimal support for daemon mode
parent
b42829d904
commit
49612063d7
|
|
@ -28,22 +28,41 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"flag"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
tmpdir := ""
|
tmpdir := ""
|
||||||
hostsloc := ""
|
hostsloc := ""
|
||||||
cfgloc := ""
|
cfgloc := ""
|
||||||
|
i := true
|
||||||
|
var daemon bool=false
|
||||||
|
var interval int=1440
|
||||||
|
|
||||||
|
// Parsing Flags
|
||||||
|
flag.BoolVar(&daemon, "d", false, "Should this be run in daemon mode")
|
||||||
|
flag.IntVar(&interval, "t", 1440, "Minutes until next run of daemon")
|
||||||
|
flag.Parse()
|
||||||
|
log.Print("daemon:" , daemon)
|
||||||
|
log.Print("interval:",interval)
|
||||||
|
|
||||||
sysdetect (&tmpdir, &hostsloc, &cfgloc)
|
sysdetect (&tmpdir, &hostsloc, &cfgloc)
|
||||||
|
|
||||||
sites, downloads := cfgparse(cfgloc)
|
for ;i == true; time.Sleep(time.Duration(interval) * time.Minute){
|
||||||
log.Print("Sites:\n",sites)
|
sites, downloads := cfgparse(cfgloc)
|
||||||
log.Print("Downloads:\n",downloads)
|
log.Print("Sites:\n",sites)
|
||||||
copystatichosts(tmpdir, hostsloc)
|
log.Print("Downloads:\n",downloads)
|
||||||
downloadcontent(downloads, tmpdir)
|
copystatichosts(tmpdir, hostsloc)
|
||||||
writesites(sites, tmpdir)
|
downloadcontent(downloads, tmpdir)
|
||||||
writetmp2hosts(hostsloc, tmpdir)
|
writesites(sites, tmpdir)
|
||||||
|
writetmp2hosts(hostsloc, tmpdir)
|
||||||
|
log.Print("Finished updating host")
|
||||||
|
i = daemon
|
||||||
|
if (i == false){
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sysdetect (tmpdir, hostsloc, cfgloc *string) {
|
func sysdetect (tmpdir, hostsloc, cfgloc *string) {
|
||||||
|
|
@ -183,11 +202,11 @@ func downloadcontent(downloads []string, tmpdir string) {
|
||||||
log.Print("Downloading: ",d)
|
log.Print("Downloading: ",d)
|
||||||
file.WriteString("# rhosts download - " + d + "\n")
|
file.WriteString("# rhosts download - " + d + "\n")
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
response, err := http.Get(d)
|
response, err := http.Get(d)
|
||||||
if (err !=nil) {
|
if (err !=nil) {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
|
continue
|
||||||
}else{
|
}else{
|
||||||
_,err := io.Copy(file,response.Body)
|
_,err := io.Copy(file,response.Body)
|
||||||
if (err != nil){
|
if (err != nil){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue