-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.go
77 lines (63 loc) · 1.49 KB
/
install.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package xcdevice
import (
"errors"
"fmt"
"io/fs"
"log"
"os"
"path"
"github.com/romantomjak/xcdevice/infoplist"
)
func Install(device *Device, filepath string) error {
if _, err := os.Stat(filepath); err != nil {
if errors.Is(err, fs.ErrNotExist) {
log.Printf("the file at %s does not exist. typo?\n", filepath)
return err
}
return err
}
info, err := infoplist.Stat(filepath)
if err != nil {
return err
}
bundleID, ok := info[infoplist.PlistKeyBundleIdentifier].(string)
if !ok {
return fmt.Errorf("failed to cast BundleIdentifier")
}
lockdown, err := LockdownService(device)
if err != nil {
return fmt.Errorf("lockdown: %v", err)
}
afc, err := lockdown.AFCService()
if err != nil {
return fmt.Errorf("afc: %v", err)
}
stagingPath := "PublicStaging"
pathInfo, err := afc.Stat(stagingPath)
if err != nil {
if !errors.Is(err, ErrObjectNotFound) {
return err
}
}
if pathInfo == nil {
if err := afc.CreateDirectory(stagingPath); err != nil {
return err
}
}
installationPath := path.Join(stagingPath, fmt.Sprintf("%s.ipa", bundleID))
bytes, err := os.ReadFile(filepath)
if err != nil {
return err
}
if err := afc.WriteFile(installationPath, bytes, AfcFileModeWr); err != nil {
return err
}
installationProxy, err := lockdown.InstallationProxyService()
if err != nil {
return fmt.Errorf("installation proxy: %v", err)
}
if err := installationProxy.InstallApplication(bundleID, installationPath); err != nil {
return err
}
return nil
}