From fe66d485fd35ad07c014c4b5f51f6aa9d543be5d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 18 Apr 2019 20:28:23 -0700 Subject: [PATCH] woops Signed-off-by: Jeff Carr --- make-sdcard/main.go | 27 ++++------ make-sdcard/shell.go | 117 ------------------------------------------- 2 files changed, 10 insertions(+), 134 deletions(-) delete mode 100644 make-sdcard/shell.go diff --git a/make-sdcard/main.go b/make-sdcard/main.go index 032f0d5..b0622f3 100644 --- a/make-sdcard/main.go +++ b/make-sdcard/main.go @@ -18,7 +18,7 @@ func rsync(mybut *ui.Button) { if _, err := os.Stat("/mnt/sdcard/lost+found/"); !os.IsNotExist(err) { log.Println("run rsync here") - script(` + shell.Script(` rsync -av --progress --inplace /home/pinebook/factory/FACTORY-IMAGER-ROOTFS/ /mnt/sdcard/ umount /mnt/sdcard `) @@ -29,7 +29,7 @@ func rsync(mybut *ui.Button) { } } -func dd(mybut *ui.Button) int { +func dd(mybut *ui.Button) { if _, err := os.Stat("/mnt/factory-image/lost+found/"); os.IsNotExist(err) { shell.Run("mkdir /mnt/factory-image/") shell.Run("mount /dev/sdb2 /mnt/factory-image/") @@ -37,23 +37,16 @@ func dd(mybut *ui.Button) int { if _, err := os.Stat("/mnt/factory-image/lost+found/"); os.IsNotExist(err) { log.Println("partition is not mounted") ui.MsgBoxError(mainwin, "The partition is not mounted at /mnt/sdcard", "") - return -1 + return } - script("dd if=/home/pinebook/factory/factory-pine14inch of=/dev/sdb status=progress bs=1M oflag=sync count=300"); - - log.Println("run rsync here") - script(` - rsync -av --progress --inplace /home/pinebook/factory/FACTORY-IMAGER-ROOTFS/ /mnt/sdcard/ - umount /mnt/sdcard - `) - ui.MsgBox(mainwin, "The sdcard is finished", "") - } else { - log.Println("partition is not mounted") - ui.MsgBoxError(mainwin, "The partition is not mounted at /mnt/sdcard", "") - } - return 0 + log.Println("run rsync here") + shell.Script(` + rsync -av --progress --inplace /home/pinebook/factory/FACTORY-IMAGER-ROOTFS/ /mnt/sdcard/ + umount /mnt/sdcard + `) + ui.MsgBox(mainwin, "The sdcard is finished", "") } // select the dev entry to partition and format @@ -74,7 +67,7 @@ func format(mybut *ui.Button) { log.Println("format() mybut =", reflect.ValueOf(mybut).Elem()) log.Println("format and mount here") - script(` + shell.Script(` parted -s /dev/sdb mklabel msdos parted -s /dev/sdb mkpart primary ext4 1MiB 8GB parted -s /dev/sdb mkpart primary ext4 8GB 32GB diff --git a/make-sdcard/shell.go b/make-sdcard/shell.go deleted file mode 100644 index f1afe16..0000000 --- a/make-sdcard/shell.go +++ /dev/null @@ -1,117 +0,0 @@ -package main - -import "fmt" -import "log" -import "strings" -import "time" -import "os" -import "os/exec" -import "bufio" -import "github.com/davecgh/go-spew/spew" -import "github.com/svent/go-nbreader" - -func script(cmds string) int { - // split on new lines (while we are at it, handle stupid windows text files - lines := strings.Split(strings.Replace(cmds, "\r\n", "\n", -1), "\n") - - for _, line := range lines { - line = strings.TrimSpace(line) // this is like 'chomp' in perl - fmt.Println("LINE:", line) - time.Sleep(1) - shell(line) - } - return 0 -} - -func shell(cmdline string) int { - log.Println("START " + cmdline) - - cmd := strings.TrimSpace(cmdline) // this is like 'chomp' in perl - cmdArgs := strings.Fields(cmd) - if (len(cmdArgs) == 0) { - log.Println("END ", cmd) - return 0 // nothing to do - } - if (cmdArgs[0] == "cd") { - if (len(cmdArgs) > 1) { - log.Println("os.Chdir()", cmd) - os.Chdir(cmdArgs[1]) - } - log.Println("END ", cmd) - return 0 // nothing to do - } - - process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) - stdout, _ := process.StdoutPipe() - stderr, _ := process.StderrPipe() - process.Start() - - f := bufio.NewWriter(os.Stdout) - - newreader := bufio.NewReader(stdout) - nbr := nbreader.NewNBReader(newreader, 1024) - - newerrreader := bufio.NewReader(stderr) - nbrerr := nbreader.NewNBReader(newerrreader, 1024) - - for { - time.Sleep(2 * time.Millisecond) // only check the buffer 500 times a second - // log.Println("sleep done") - - oneByte := make([]byte, 1024) - count, err := nbr.Read(oneByte) - - if (err != nil) { - // log.Println("Read() count = ", count, "err = ", err) - oneByte = make([]byte, 1024) - count, err = nbr.Read(oneByte) - f.Write([]byte(string(oneByte))) - f.Flush() - } - f.Write([]byte(string(oneByte))) - f.Flush() - - oneByte = make([]byte, 1024) - count, err = nbrerr.Read(oneByte) - - if (err != nil) { - oneByte = make([]byte, 1024) - count, err = nbrerr.Read(oneByte) - f.Write([]byte(string(oneByte))) - f.Flush() - - log.Println("Read() count = ", count, "err = ", err) - spew.Dump(process.Process) - spew.Dump(process.ProcessState) - err := process.Wait() - if err != nil { - spew.Dump(err.(*exec.ExitError)) - spew.Dump(process.ProcessState) - stuff := err.(*exec.ExitError) - log.Println("ERROR ", stuff) - log.Println("END ", cmdline) - return -1 - } - log.Println("END ", cmdline) - return 0 - } else { - f.Write([]byte(string(oneByte))) - f.Flush() - } - - // spew.Dump(reflect.ValueOf(cmd.Process).Elem()) - } - - err := process.Wait() - - if err != nil { - spew.Dump(err.(*exec.ExitError)) - spew.Dump(process.ProcessState) - stuff := err.(*exec.ExitError) - log.Println("ERROR ", stuff) - log.Println("END ", cmdline) - return -1 - } - log.Println("END ", cmdline) - return 0 -}