@@ -3,11 +3,8 @@ package main
33import (
44 "arduino-flasher/updater"
55 "context"
6- "fmt"
7- "net/url"
86 "os"
97 "runtime"
10- "strings"
118
129 "github.com/arduino/go-paths-helper"
1310 runas "github.com/arduino/go-windows-runas"
@@ -53,76 +50,8 @@ func runFlashCommand(ctx context.Context, args []string, forceYes bool) {
5350 feedback .Fatal (i18n .Tr ("could not find image absolute path: %v" , err ), feedback .ErrBadArgument )
5451 }
5552
56- if ! imagePath .Exist () {
57- version := args [0 ]
58-
59- updateURL := os .Getenv ("UPDATE_URL" )
60- if updateURL == "" {
61- // TODO: change to prod
62- updateURL = "https://downloads.oniudra.cc"
63- }
64-
65- parsedURL , err := url .Parse (updateURL )
66- if err != nil {
67- feedback .Fatal (i18n .Tr ("invalid UPDATE_URL:" , err ), feedback .ErrBadArgument )
68- }
69-
70- headers := map [string ]string {}
71- clientID := os .Getenv ("CF_ACCESS_CLIENT_ID" )
72- clientSecret := os .Getenv ("CF_ACCESS_CLIENT_SECRET" )
73- if clientID != "" && clientSecret != "" {
74- headers ["CF-Access-Client-Id" ] = clientID
75- headers ["CF-Access-Client-Secret" ] = clientSecret
76- }
77-
78- var client * updater.Client
79- if len (headers ) == 2 {
80- client = updater .NewClient (parsedURL , "debian-im/Stable" , updater .WithHeaders (headers ))
81- } else {
82- client = updater .NewClient (parsedURL , "debian-im/Stable" )
83- }
84-
85- tempImagePath , err := updater .DownloadAndExtract (client , version , func (target string ) (bool , error ) {
86- feedback .Printf ("Found Debian image version: %s" , target )
87- feedback .Printf ("Do you want to download it and flash it on the board? (yes/no)" )
88-
89- var yesInput string
90- _ , err := fmt .Scanf ("%s\n " , & yesInput )
91- if err != nil {
92- return false , err
93- }
94- yes := strings .ToLower (yesInput ) == "yes" || strings .ToLower (yesInput ) == "y"
95- return yes , nil
96- }, forceYes )
97-
98- if err != nil {
99- feedback .Fatal (i18n .Tr ("could not download and extract the image: %v" , err ), feedback .ErrBadArgument )
100- }
101-
102- defer tempImagePath .Parent ().RemoveAll ()
103-
104- imagePath = tempImagePath
105- } else if ! imagePath .IsDir () {
106- temp , err := paths .MkTempDir ("" , "debian-image-" )
107- if err != nil {
108- feedback .Fatal (i18n .Tr ("error creating a temporary directory to extract the archive: %v" , err ), feedback .ErrBadArgument )
109- }
110- defer temp .RemoveAll ()
111-
112- err = updater .ExtractImage (imagePath , temp )
113- if err != nil {
114- feedback .Fatal (i18n .Tr ("error extracting the archive: %v" , err ), feedback .ErrBadArgument )
115- }
116-
117- tempContent , err := temp .ReadDir (paths .AndFilter (paths .FilterDirectories (), paths .FilterPrefixes ("arduino-unoq-debian-image-" )))
118- if err != nil {
119- feedback .Fatal (i18n .Tr ("could not find Debian image directory: %v" , err ), feedback .ErrBadArgument )
120- }
121-
122- imagePath = tempContent [0 ]
123- }
124-
125- if err := updater .FlashBoard (ctx , imagePath .String ()); err != nil {
53+ err = updater .Flash (ctx , imagePath , args [0 ], forceYes )
54+ if err != nil {
12655 feedback .Fatal (i18n .Tr ("error flashing the board: %v" , err ), feedback .ErrBadArgument )
12756 }
12857}
0 commit comments