From 3869749fe27d05e969245314aa7e495282674656 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 8 Apr 2019 12:11:32 -0700 Subject: [PATCH] try to wget the image if it doesn't exist Signed-off-by: Jeff Carr --- get-image/main.go | 81 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 15 deletions(-) diff --git a/get-image/main.go b/get-image/main.go index 5591e4b..47b9b96 100644 --- a/get-image/main.go +++ b/get-image/main.go @@ -1,10 +1,10 @@ package main -/* +import "os" import "log" +/* import "fmt" import "reflect" -import "os" */ import "git.wit.com/jcarr/shell" @@ -12,25 +12,76 @@ import "git.wit.com/jcarr/shell" func main() { parseConfig() + if _, err := os.Stat("/home/factory"); !os.IsNotExist(err) { + } else { + shell.Run("mkdir /home/factory") + } + + if _, err := os.Stat("/dev/mmcblk0p2"); !os.IsNotExist(err) { + log.Println("device /dev/mmcblk0p2 exists") + } else { + log.Println("device /dev/mmcblk0p2 does not exist") + // fail() + } + shell.Run("mount /dev/mmcblk0p2 /home/factory") + imagename := "factory-2019-01-20" + fullname := "/home/factory/" + imagename + + if _, err := os.Stat(fullname); !os.IsNotExist(err) { + log.Println("filename", fullname, "does not exist") + shell.Run("cd /home/factory") + shell.Run("wget -c " + "http://fire.lab.wit.com/factory/" + imagename) + } + if _, err := os.Stat(fullname); !os.IsNotExist(err) { + log.Println("filename", fullname, "exists. dd here") + shell.Run("dd " + fullname + " of=/dev/mmcblk2 bs=1M status=progress oflag=sync") + } else { + log.Println("filename", fullname, "does not exist") + fail() + } + + // wget -c http://fire.lab.wit.com/factory/ /* echo dd if=/home/factory/emmc.img.armbian of=/dev/mmcblk2 -dd if=/home/factory/emmc.img.armbian of=/dev/mmcblk2 bs=16M status=progress - -echo sync -sync +dd if=/home/factory/emmc.img.armbian of=/dev/mmcblk2 bs=1M status=progress oflag=sync dialog --ascii-lines --msgbox "Flash Image Completed!" 10 70 - -echo -echo -echo INSTALL SUCCEEDED -echo INSTALL SUCCEEDED -echo INSTALL SUCCEEDED -echo INSTALL SUCCEEDED -echo -echo */ } + +func fail () { + log.Println("") + log.Println("") + log.Println("") + log.Println("INSTALL FAILED") + log.Println("INSTALL FAILED") + log.Println("INSTALL FAILED") + log.Println("INSTALL FAILED") + log.Println("INSTALL FAILED") + log.Println("INSTALL FAILED") + log.Println("") + log.Println("") + log.Println("") + + os.Exit(-1) +} + +func succeeded () { + log.Println("") + log.Println("") + log.Println("") + log.Println("INSTALL SUCCEEDED") + log.Println("INSTALL SUCCEEDED") + log.Println("INSTALL SUCCEEDED") + log.Println("INSTALL SUCCEEDED") + log.Println("INSTALL SUCCEEDED") + log.Println("INSTALL SUCCEEDED") + log.Println("") + log.Println("") + log.Println("") + + os.Exit(0) +}