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.
This commit is contained in:
Steven Penny 2015-04-12 04:33:27 -05:00
parent aea773d829
commit 83b2425481
1 changed files with 57 additions and 0 deletions

57
go-cyg.go Normal file
View File

@ -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
}