added tarring to the equation
This commit is contained in:
parent
37ca23c542
commit
d4c5d1d596
6
main.go
6
main.go
@ -3,16 +3,10 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//fmt.Println("Hello!")
|
|
||||||
|
|
||||||
//var config Configuration
|
|
||||||
|
|
||||||
config := initializeConfig("config.yaml")
|
config := initializeConfig("config.yaml")
|
||||||
sshConn, sshConfig := initializeConnection(config)
|
sshConn, sshConfig := initializeConnection(config)
|
||||||
clientConns := sshConn.dialConnection(sshConfig)
|
clientConns := sshConn.dialConnection(sshConfig)
|
||||||
fmt.Println(clientConns)
|
|
||||||
clientSessions := sshConn.openSession(clientConns)
|
clientSessions := sshConn.openSession(clientConns)
|
||||||
fmt.Println(clientSessions)
|
|
||||||
success := sshConn.executeTarFile(clientSessions)
|
success := sshConn.executeTarFile(clientSessions)
|
||||||
fmt.Println(success)
|
fmt.Println(success)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("Hello from the remote side!")
|
|
||||||
}
|
|
@ -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
|
|
@ -1 +0,0 @@
|
|||||||
package main
|
|
4
ssh.go
4
ssh.go
@ -91,8 +91,8 @@ func (s SSHConnection) executeTarFile(execute SSHSessions) SSHSuccess {
|
|||||||
success := SSHSuccess{}
|
success := SSHSuccess{}
|
||||||
|
|
||||||
for _, j := range execute {
|
for _, j := range execute {
|
||||||
// this is just a placeholder, change to the actual tarring executable
|
// TODO: this is just a placeholder, change to the actual tarring executable
|
||||||
err := j.Run("echo 'hello world'! > test.txt")
|
err := j.Run("echo 'hello world' > test.txt")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("Can't execute program", err)
|
fmt.Errorf("Can't execute program", err)
|
||||||
|
72
tar.go
Normal file
72
tar.go
Normal file
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user