From 83b24254816d883348c60e842bbd6924957719fb Mon Sep 17 00:00:00 2001 From: Steven Penny Date: Sun, 12 Apr 2015 04:33:27 -0500 Subject: [PATCH] Begin Go rewrite This may end up being nothing, but would like to rewrite apt-cyg in Go. This will be nice because you will end up with a single EXE file, similar to setup-x86_64.exe. The difference is that it will be totally command line like apt-cyg, but better because you can build all the requirements (wget, bunzip2, awk) right into the EXE. My concern right now is that I will probably have to write an INI parser, because Cygwin setup.ini is a weird format. Since I am just starting with Go I may not have the skill, we shall see. --- go-cyg.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 go-cyg.go diff --git a/go-cyg.go b/go-cyg.go new file mode 100644 index 0000000..97b717f --- /dev/null +++ b/go-cyg.go @@ -0,0 +1,57 @@ +package main +import ( + "compress/bzip2" + "fmt" + "io" + "net/http" + "os" + "strings" +) + +func wget(url string) { + tokens := strings.Split(url, "/") + fileName := tokens[len(tokens)-1] + fmt.Println("Downloading", url, "to", fileName) + output, err := os.Create(fileName) + if err != nil { + return + } + response, err := http.Get(url) + if err != nil { + return + } + n, err := io.Copy(output, response.Body) + if err != nil { + return + } + fmt.Println(n, "bytes downloaded.") +} + +func bunzip2(alpha string) { + bravo, err := os.Open(alpha) + if err != nil { + return + } + charlie := bzip2.NewReader(bravo) + delta, err := os.Create("setup.ini") + if err != nil { + return + } + io.Copy(delta, charlie) +} + +func foxtrot() { + // create release folder + os.MkdirAll("mirror/x86_64/release", 0) + // cd + os.Chdir("mirror/x86_64") + // download + wget("http://cygwin.osuosl.org/x86_64/setup.bz2") + // extract + bunzip2("setup.bz2") +} + +func main() { + foxtrot() + // parse ini +}