Compare commits

...

3 commits

Author SHA1 Message Date
timoxa0 dfd5cee2fc Update gofastboot 2024-06-21 17:36:31 +05:00
timoxa0 3d7b885994 Fix nil pointer panic 2024-06-21 17:30:46 +05:00
timoxa0 d3e41c0ce1 Rename build 2024-06-21 17:30:09 +05:00
4 changed files with 37 additions and 15 deletions

View file

@ -1,15 +1,16 @@
# Define variables
NAME = lon-tool
GOFLAGS ?= -ldflags="-s -w"
SRC ?= main.go
BIN_DIR ?= ./bin
# macOS settings
MACOS_BIN = $(BIN_DIR)/lnd_mac_amd64
MACOS_BIN = $(BIN_DIR)/$(NAME)_mac_amd64
MACOS_CC = x86_64-apple-darwin23-gcc-14
MACOS_CXX = x86_64-apple-darwin23-g++-14
# Windows settings
WINDOWS_BIN = $(BIN_DIR)/lnd_win_amd64.exe
WINDOWS_BIN = $(BIN_DIR)/$(NAME)_win_amd64.exe
WINDOWS_CC = x86_64-w64-mingw32-gcc
WINDOWS_CXX = x86_64-w64-mingw32-g++
WINDOWS_PKG_CONFIG_PATH = /usr/local/x86_64-w64-mingw32/lib/pkgconfig
@ -17,7 +18,7 @@ WINDOWS_CGO_CFLAGS = -I/usr/local/x86_64-w64-mingw32/include
WINDOWS_CGO_LDFLAGS = -L/usr/local/x86_64-w64-mingw32/lib
# Linux settings
LINUX_BIN = $(BIN_DIR)/lnd_lin_amd64
LINUX_BIN = $(BIN_DIR)/$(NAME)_lin_amd64
LINUX_CC = x86_64-linux-gnu-gcc
LINUX_CXX = x86_64-linux-gnu-g++
LINUX_PKG_CONFIG_PATH = /usr/local/x86_64-linux-gnu/lib/pkgconfig

View file

@ -3,8 +3,8 @@ package cmd
import (
"io"
"io/fs"
"lon-tool/utils"
"lon-tool/image"
"lon-tool/utils"
"net"
"os"
"regexp"
@ -30,6 +30,7 @@ var deployCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var msg string
req_repartition := partsize != ""
image, close, err := image.ReadImage(args[0])
@ -44,6 +45,7 @@ var deployCmd = &cobra.Command{
logger.Fatal("Failed to get adb client", logger.Args(err))
}
fb_devs, err := fastboot.FindDevices()
logger.Debug("Devices", logger.Args("Devices", fb_devs, "err", err))
if err != nil {
logger.Fatal("Failed to get fastboot device", logger.Args(err))
}
@ -56,14 +58,16 @@ var deployCmd = &cobra.Command{
if serail == "autodetect" {
for _, dev := range fb_devs {
product, err := dev.GetVar("product")
devSerial, _ := dev.Device.SerialNumber()
if err != nil {
logger.Warn("Unable to communicate with device", logger.Args("Serial", dev.Serial))
logger.Warn("Unable to communicate with device", logger.Args("Serial", devSerial))
logger.Debug("Unable to communicate with device", logger.Args("err", err))
continue
}
logger.Debug("Found device", logger.Args("Product", product, "Sraial", dev.Serial))
logger.Debug("Found device", logger.Args("Product", product, "Sraial", devSerial, "object", dev))
if product == "nabu" {
logger.Debug("Nabu found", logger.Args("Serial", dev.Serial))
serail = dev.Serial
logger.Debug("Nabu found", logger.Args("Serial", devSerial))
serail = devSerial
if !req_repartition {
_, err1 := dev.GetVar("partition-type:linux")
_, err2 := dev.GetVar("partition-type:esp")
@ -72,6 +76,9 @@ var deployCmd = &cobra.Command{
break
}
}
for _, dev := range fb_devs {
dev.Close()
}
if serail == "autodetect" {
logger.Fatal("Nabu in fastboot mode not found")
os.Exit(170)
@ -106,6 +113,10 @@ var deployCmd = &cobra.Command{
} else {
run_repartition, _ = pterm.DefaultInteractiveConfirm.Show("Found compatible partition table. Do you want to change it?")
}
if req_repartition && !run_repartition {
pterm.Println("Bye")
os.Exit(0)
}
for {
if partsize != "" || !run_repartition {
@ -155,7 +166,14 @@ var deployCmd = &cobra.Command{
pterm.Println("Bye")
os.Exit(253)
}
fb_dev, _ := fastboot.FindDevice(serail)
fb_dev, err := fastboot.FindDevice(serail)
if err != nil {
logger.Error("Unable to find device", logger.Args("object", fb_dev, "err", err))
fb_devs, err := fastboot.FindDevices()
logger.Debug("Devices", logger.Args("Devices", fb_devs, "err", err))
os.Exit(255)
}
adbd := adbc.Device(adb.DeviceWithSerial(serail))
bootdata, err := utils.Files.OrangeFox.Get(*pbar.WithTitle("Downloading orangefox"))
if err != nil {
@ -166,7 +184,6 @@ var deployCmd = &cobra.Command{
os.Exit(179)
}
}
logger.Debug("Bootdata")
if run_repartition {
gpt, err := utils.Files.GPT.Get(*pbar.WithTitle("Downloading default partition table"))

View file

@ -28,17 +28,21 @@ var uninstallCmd = &cobra.Command{
if serail == "autodetect" {
for _, dev := range fb_devs {
product, err := dev.GetVar("product")
devSerial, _ := dev.Device.SerialNumber()
if err != nil {
logger.Warn("Unable to communicate with device", logger.Args("Serial", dev.Serial))
logger.Warn("Unable to communicate with device", logger.Args("Serial", devSerial))
continue
}
logger.Debug("Found device", logger.Args("Product", product, "Sraial", dev.Serial))
logger.Debug("Found device", logger.Args("Product", product, "Sraial", devSerial))
if product == "nabu" {
logger.Debug("Nabu found", logger.Args("Serial", dev.Serial))
serail = dev.Serial
logger.Debug("Nabu found", logger.Args("Serial", devSerial))
serail = devSerial
break
}
}
for _, dev := range fb_devs {
dev.Close()
}
if serail == "autodetect" {
logger.Fatal("Nabu in fastboot mode not found")
os.Exit(170)

2
go.mod
View file

@ -7,7 +7,7 @@ require (
github.com/pterm/pterm v0.12.79
github.com/spf13/cobra v1.8.0
github.com/timoxa0/goadb v0.0.0-20240617073314-c303241c8c53
github.com/timoxa0/gofastboot v0.0.0-20240617184805-918afbb71e47
github.com/timoxa0/gofastboot v0.0.0-20240621122731-6a022539b068
)
require (