-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprehighsierra.go
122 lines (98 loc) · 2.78 KB
/
prehighsierra.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package mic
import (
"errors"
"io/ioutil"
"log"
"os"
"github.com/stephen-fox/mic/internal/asrutil"
"github.com/stephen-fox/mic/internal/hdiutilw"
)
type PreHighSierra struct {
name string
isLoggingEnabled bool
}
func (o PreHighSierra) Name() string {
return o.name
}
func (o *PreHighSierra) SetLogging(enabled bool) {
o.isLoggingEnabled = enabled
}
func (o PreHighSierra) CreateIso(isoDestinationPath string, installerApplicationPath string) error {
_, statErr := os.Stat(osxBaseSystemMountPath)
if statErr == nil {
return errors.New("An OS-X base system is already mounted at '" +
osxBaseSystemMountPath + "'. You must umount it first")
}
esdMountPath, err := ioutil.TempDir("", "mount-esd-")
if err != nil {
return errors.New("Failed to create mount point - " + err.Error())
}
err = hdiutilw.Attach(installerApplicationPath + "/Contents/SharedSupport/InstallESD.dmg", esdMountPath)
if err != nil {
return errors.New("Failed to mount installer application's .dmg - " + err.Error())
}
defer hdiutilw.Detach(esdMountPath)
sparseImage, err := ioutil.TempFile("", "macos-installer-sparseimage-")
if err != nil {
return errors.New("Failed to create empty sparseimage - " + err.Error())
}
sparseImage.Close()
os.Remove(sparseImage.Name())
sparseImagePath, err := hdiutilw.CreateSparseImage(sparseImage.Name(), 8000)
if err != nil {
return err
}
defer os.Remove(sparseImagePath)
sparseImageMountPath, err := ioutil.TempDir("", "mount-sparseimage-")
if err != nil {
return errors.New("Failed to create mount point - " + err.Error())
}
err = hdiutilw.Attach(sparseImagePath, sparseImageMountPath)
if err != nil {
return err
}
defer hdiutilw.Detach(sparseImageMountPath)
if o.isLoggingEnabled {
log.Println("Adding installer files to .iso sparseimage...")
}
err = asrutil.Restore(esdMountPath + "/BaseSystem.dmg", sparseImageMountPath)
if err != nil {
return err
}
if o.isLoggingEnabled {
log.Println("Copying installer files...")
}
err = copyInstallerResources(esdMountPath, osxBaseSystemMountPath)
if err != nil {
return err
}
err = hdiutilw.Detach(osxBaseSystemMountPath)
if err != nil {
return err
}
if o.isLoggingEnabled {
log.Println("Shrinking .iso sparseimage...")
}
err = hdiutilw.Compact(sparseImagePath)
if err != nil {
return err
}
if o.isLoggingEnabled {
log.Println("Converting .iso sparseimage to a .iso file...")
}
iso, err := ioutil.TempFile("", "macos-installer-iso-")
if err != nil {
return errors.New("Failed to create empty .iso file - " + iso.Name())
}
iso.Close()
os.Remove(iso.Name())
isoFinalFilePath, err := hdiutilw.ConvertImageToIso(sparseImagePath, iso.Name())
if err != nil {
return err
}
err = os.Rename(isoFinalFilePath, isoDestinationPath)
if err != nil {
return err
}
return nil
}