-
-
Notifications
You must be signed in to change notification settings - Fork 166
/
erase.go
53 lines (48 loc) · 1.26 KB
/
erase.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
package mcinstall
import (
"fmt"
"io"
"github.com/danielpaulus/go-ios/ios"
log "github.com/sirupsen/logrus"
)
// Erase tells a device to remove all apps and settings. You need to activate it afterwards.
// Be careful with this if you do not have a backup!
func Erase(device ios.DeviceEntry) error {
conn, err := New(device)
if err != nil {
return err
}
defer conn.Close()
log.Info("start erasing")
log.Debug("send flush request")
_, err = check(conn.sendAndReceive(request("Flush")))
if err != nil {
return err
}
log.Debug("get cloud config")
config, err := check(conn.sendAndReceive(request("GetCloudConfiguration")))
if err != nil {
return err
}
log.Debugf("config: %v", config)
log.Debug("send erase request")
eraseRequest := map[string]interface{}{
"RequestType": "EraseDevice",
"PreserveDataPlan": 1,
}
_, err = check(conn.sendAndReceive(eraseRequest))
if err != nil && err != io.EOF {
return err
}
log.Info("device should be rebooting now")
return nil
}
func check(request map[string]interface{}, err error) (map[string]interface{}, error) {
if err != nil {
return map[string]interface{}{}, err
}
if !checkStatus(request) {
return map[string]interface{}{}, fmt.Errorf("failed command: %v", request)
}
return request, nil
}