summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go64
1 files changed, 44 insertions, 20 deletions
diff --git a/main.go b/main.go
index 7bfb2e0..8247ab4 100644
--- a/main.go
+++ b/main.go
@@ -42,8 +42,15 @@ func main() {
log.Println("Starting craft")
defer log.Println("Exiting craft")
+ source, err := os.MkdirTemp("", "*-craft")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer os.RemoveAll(source)
+ checkout(repo, commit, source)
+
vm := qemu()
- err := vm.Start()
+ err = vm.Start()
if err != nil {
log.Fatal(err)
}
@@ -53,22 +60,11 @@ func main() {
log.Fatal(err)
}
}()
-
waitBoot()
- checkoutSources(repo, commit)
- craft()
-}
+ upload(source)
-func runCommand(name string, args ...string) {
- log.Printf("Remote execution: %s %s\n", name, strings.Join(args, " "))
- command := sshCommand(name, args...)
- command.Stderr = os.Stderr
- command.Stdout = os.Stdout
- err := command.Run()
- if err != nil {
- log.Fatal(err)
- }
+ craft()
}
func qemu() *exec.Cmd {
@@ -148,20 +144,31 @@ cd %s
}
}
-func checkoutSources(repo string, commit string) string {
+func runCommand(name string, args ...string) {
+ log.Printf("Execution: %s %s\n", name, strings.Join(args, " "))
+ command := exec.Command(name, args...)
+ command.Stderr = os.Stderr
+ command.Stdout = os.Stdout
+ err := command.Run()
+ if err != nil {
+ log.Fatal(err)
+ }
+}
+
+func checkout(repo string, commit string, target string) {
runCommand(
"git",
"clone",
repo,
- workbench,
+ target,
)
runCommand(
"git",
"--git-dir",
- filepath.Join(workbench, ".git"),
+ filepath.Join(target, ".git"),
"--work-tree",
- workbench,
+ target,
"checkout",
commit,
)
@@ -169,7 +176,7 @@ func checkoutSources(repo string, commit string) string {
runCommand(
"git",
"-C",
- workbench,
+ target,
"submodule",
"update",
"--depth=1",
@@ -177,5 +184,22 @@ func checkoutSources(repo string, commit string) string {
"--recursive",
)
- return workbench
+ log.Printf("Checked source out to '%s'", target)
+}
+
+func upload(directory string) {
+ mkdir := sshCommand("mkdir", "/root/build")
+ err := mkdir.Run()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ runCommand(
+ "rsync",
+ "-a",
+ filepath.Clean(directory)+"/",
+ "--rsh",
+ "ssh -p "+port+" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "+key,
+ "root@localhost:/root/build/",
+ )
}