diff --git a/main.go b/main.go index be0709c..e8350e3 100644 --- a/main.go +++ b/main.go @@ -3,16 +3,10 @@ package main import "fmt" func main() { - //fmt.Println("Hello!") - - //var config Configuration - config := initializeConfig("config.yaml") sshConn, sshConfig := initializeConnection(config) clientConns := sshConn.dialConnection(sshConfig) - fmt.Println(clientConns) clientSessions := sshConn.openSession(clientConns) - fmt.Println(clientSessions) success := sshConn.executeTarFile(clientSessions) fmt.Println(success) } diff --git a/remote/main.go b/remote/main.go deleted file mode 100644 index ff0da6e..0000000 --- a/remote/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("Hello from the remote side!") -} diff --git a/remote/ssh_remote.go b/remote/ssh_remote.go deleted file mode 100644 index 2f5c8df..0000000 --- a/remote/ssh_remote.go +++ /dev/null @@ -1,5 +0,0 @@ -package main - -// this file is to ssh back to the master machine to send back the tarball -// still planning this piece out. stay tuned for more! -// handsomely, Wyatt J. Miller, the guy who doesn't know what socket is headed where diff --git a/remote/tar.go b/remote/tar.go deleted file mode 100644 index 06ab7d0..0000000 --- a/remote/tar.go +++ /dev/null @@ -1 +0,0 @@ -package main diff --git a/ssh.go b/ssh.go index 1f0145c..aca09ae 100644 --- a/ssh.go +++ b/ssh.go @@ -91,8 +91,8 @@ func (s SSHConnection) executeTarFile(execute SSHSessions) SSHSuccess { success := SSHSuccess{} for _, j := range execute { - // this is just a placeholder, change to the actual tarring executable - err := j.Run("echo 'hello world'! > test.txt") + // TODO: this is just a placeholder, change to the actual tarring executable + err := j.Run("echo 'hello world' > test.txt") if err != nil { fmt.Errorf("Can't execute program", err) diff --git a/tar.go b/tar.go new file mode 100644 index 0000000..d727416 --- /dev/null +++ b/tar.go @@ -0,0 +1,72 @@ +package main + +import ( + "compress/gzip" + "fmt" + "io" + "os" + "path/filepath" + "time" +) + +type Header struct { + Comment string + Extra []byte + ModTime time.Time + Name string + OS byte +} + +func gzipit(source string, target string) error { + reader, err := os.Open(source) + + if err != nil { + fmt.Errorf("Cannot open source") + } + + filename := filepath.Base(source) + target = filepath.Join(target, fmt.Sprintf("%s.tar.gz", filename)) + writer, err := os.Create(target) + + if err != nil { + fmt.Errorf("Cannot create target archive") + } + + defer writer.Close() + + archiver := gzip.NewWriter(writer) + archiver.Name = filename + defer archiver.Close() + + _, err = io.Copy(archiver, reader) + return err +} + +func ungzipit(source string, target string) { + reader, err := os.Open(source) + + if err != nil { + fmt.Errorf("Cannot open source") + } + + defer reader.Close() + + archive, err := gzip.NewReader(reader) + + if err != nil { + fmt.Errorf("Cannot open archive") + } + + defer archive.Close() + + target = filepath.Join(target, archive.Name) + writer, err := os.Create(target) + + if err != nil { + fmt.Errorf("Cannot extract archive") + } + + defer writer.Close() + + _, err = io.Copy(writer, archive) +}