Skip to content

Commit

Permalink
Begin Go rewrite
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Steven Penny committed Apr 12, 2015
1 parent aea773d commit 83b2425
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions go-cyg.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 83b2425

Please sign in to comment.