Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-04-18 20:28:23 -07:00
parent d17f986b10
commit fe66d485fd
2 changed files with 10 additions and 134 deletions

View File

@ -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

View File

@ -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
}