Skip to content

Commit 4f1e45a

Browse files
committed
Add JAR backup, improve banner messaging
1 parent 4292b66 commit 4f1e45a

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed
0 Bytes
Binary file not shown.
299 Bytes
Binary file not shown.

assets/jars/2.0.10/maestro-ios.jar

-11 Bytes
Binary file not shown.

cmd/maestro-ios-device/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ func fatal(format string, args ...any) {
2323
}
2424

2525
func printBanner() {
26-
fmt.Printf("maestro-ios-device %s (Unofficial — devicelab.dev)\n\n", version)
26+
fmt.Printf("maestro-ios-device %s\n", version)
27+
fmt.Println(" Unofficial stop-gap until Maestro adds real device support")
28+
fmt.Println(" Built by DeviceLab — https://devicelab.dev")
29+
fmt.Println()
2730
}
2831

2932
func main() {
@@ -47,7 +50,9 @@ func run() {
4750
flag.Parse()
4851

4952
if *showVersion {
50-
fmt.Printf("maestro-ios-device %s (Unofficial — devicelab.dev)\n", version)
53+
fmt.Printf("maestro-ios-device %s\n", version)
54+
fmt.Println(" Unofficial stop-gap until Maestro adds real device support")
55+
fmt.Println(" Built by DeviceLab — https://devicelab.dev")
5156
return
5257
}
5358

internal/maestro/maestro.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ func RunSetup() error {
6868
}
6969

7070
fmt.Println()
71+
fmt.Println("📦 Backing up existing JARs...")
72+
if err := backupJars(libPath); err != nil {
73+
return fmt.Errorf("failed to backup JARs: %w", err)
74+
}
75+
fmt.Println("✅ Backup complete")
76+
7177
fmt.Println("📥 Downloading JARs...")
7278
if err := downloadAndExtract(releaseURL+"/"+jarsZip, libPath); err != nil {
7379
return fmt.Errorf("failed to download JARs: %w", err)
@@ -198,6 +204,52 @@ func findLibInScript(content, scriptDir string) string {
198204
return ""
199205
}
200206

207+
func backupJars(libPath string) error {
208+
home, err := os.UserHomeDir()
209+
if err != nil {
210+
return err
211+
}
212+
backupDir := filepath.Join(home, ".maestro", "backup")
213+
if err := os.MkdirAll(backupDir, 0755); err != nil {
214+
return err
215+
}
216+
217+
entries, err := os.ReadDir(libPath)
218+
if err != nil {
219+
return err
220+
}
221+
222+
for _, entry := range entries {
223+
name := entry.Name()
224+
if !strings.HasPrefix(name, "maestro") || !strings.HasSuffix(name, ".jar") {
225+
continue
226+
}
227+
src := filepath.Join(libPath, name)
228+
dst := filepath.Join(backupDir, name)
229+
if err := copyFile(src, dst); err != nil {
230+
return fmt.Errorf("failed to backup %s: %w", name, err)
231+
}
232+
}
233+
return nil
234+
}
235+
236+
func copyFile(src, dst string) error {
237+
in, err := os.Open(src)
238+
if err != nil {
239+
return err
240+
}
241+
defer in.Close()
242+
243+
out, err := os.Create(dst)
244+
if err != nil {
245+
return err
246+
}
247+
defer out.Close()
248+
249+
_, err = io.Copy(out, in)
250+
return err
251+
}
252+
201253
func downloadAndExtract(url, dest string) error {
202254
resp, err := http.Get(url)
203255
if err != nil {

0 commit comments

Comments
 (0)