Skip to content

Commit

Permalink
replace haikeu repo with mspvirajpatel (#168)
Browse files Browse the repository at this point in the history
the old repo wasn't well maintained and images were not working or deprecated. 
Using https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images now for the `image auto` command. 

Should resolve #167 
thanks a ton people!
  • Loading branch information
danielpaulus authored Aug 26, 2022
1 parent 12f0988 commit ca2f71b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
53 changes: 27 additions & 26 deletions ios/imagemounter/imagedownloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,40 @@ import (

"github.com/Masterminds/semver"
"github.com/danielpaulus/go-ios/ios"
"github.com/danielpaulus/go-ios/ios/zipconduit"
log "github.com/sirupsen/logrus"
)

const repo = "https://github.com/haikieu/xcode-developer-disk-image-all-platforms/raw/master/DiskImages/iPhoneOS.platform/DeviceSupport/%s.zip"
const imagepath = "devimages"
const developerDiskImageDmg = "DeveloperDiskImage.dmg"

var availableVersions = []string{"10.0", "10.1", "10.2", "10.3", "11.0", "11.1", "11.2", "11.3", "11.4", "12.0", "12.1", "12.2", "12.3", "13.0", "13.1", "13.1.2", "13.2", "13.3", "13.4", "13.5", "13.6", "13.7", "14.0", "14.2", "14.3", "14.4", "14.5", "14.6", "14.7", "15.0", "15.2", "15.4", "8.0", "8.1", "8.2", "8.3", "8.4", "9.0", "9.1", "9.2", "9.3"}
var versionMap = map[string]string{"4.2": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/4.2", "4.3": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/4.3", "5.0": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/5.0", "5.1": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/5.1", "6.0": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/6.0", "6.1": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/6.1", "7.0": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/7.0", "7.1": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/7.1", "8.0": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/8.0", "8.1": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/8.1", "8.2": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/8.2", "8.3": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/8.3", "8.4 (12H141)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/8.4%20(12H141)", "9.0 (13A340)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/9.0%20(13A340)", "9.1 (13B5110e)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/9.1%20(13B5110e)", "9.2 (13C75)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/9.2%20(13C75)", "9.3 (13E230)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/9.3%20(13E230)", "10.0 (14A345)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/10.0%20(14A345)", "10.1 (14B72)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/10.1%20(14B72)", "10.2 (14C5062c)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/10.2%20(14C5062c)", "10.3 (14E269)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/10.3%20(14E269)", "11.0 (15A372)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/11.0%20(15A372)", "11.1 (15B87)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/11.1%20(15B87)", "11.2 (15C5092b)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/11.2%20(15C5092b)", "11.3 (15E5178d)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/11.3%20(15E5178d)", "11.4 (15F5037c)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/11.4%20(15F5037c)", "12.0 (16A5288q)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/12.0%20(16A5288q)", "12.1 (16B5059d)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/12.1%20(16B5059d)", "12.2 (16E5191d)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/12.2%20(16E5191d)", "12.3 (16F148)": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/12.3%20(16F148)", "12.4": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/12.4", "13.0": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/13.0", "13.1": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/13.1", "13.2": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/13.2", "13.3": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/13.3", "13.4": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/13.4", "13.5": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/13.5", "13.7": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/13.7", "14.0": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/14.0", "14.1": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/14.1", "14.2": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/14.2", "14.4": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/14.4", "14.5": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/14.5", "14.6": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/14.6", "14.7": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/14.7", "14.7.1": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/14.7.1", "14.8": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/14.8", "15.0": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/15.0", "15.1": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/15.1", "15.2": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/15.2", "15.3": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/15.3", "15.3.1": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/15.3.1", "15.4": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/15.4", "15.5": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/15.5", "15.6": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/15.6", "15.6.1": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/15.6.1", "16.0": "https://github.com/mspvirajpatel/Xcode_Developer_Disk_Images/blob/master/Developer%20Disk%20Image/16.0"}
var availableVersions = []string{"4.2", "4.3", "5.0", "5.1", "6.0", "6.1", "7.0", "7.1", "8.0", "8.1", "8.2", "8.3", "8.4 (12H141)", "9.0 (13A340)", "9.1 (13B5110e)", "9.2 (13C75)", "9.3 (13E230)", "10.0 (14A345)", "10.1 (14B72)", "10.2 (14C5062c)", "10.3 (14E269)", "11.0 (15A372)", "11.1 (15B87)", "11.2 (15C5092b)", "11.3 (15E5178d)", "11.4 (15F5037c)", "12.0 (16A5288q)", "12.1 (16B5059d)", "12.2 (16E5191d)", "12.3 (16F148)", "12.4", "13.0", "13.1", "13.2", "13.3", "13.4", "13.5", "13.7", "14.0", "14.1", "14.2", "14.4", "14.5", "14.6", "14.7", "14.7.1", "14.8", "15.0", "15.1", "15.2", "15.3.1", "15.3", "15.4", "15.5", "15.6", "15.6.1", "16.0"}

const v12_2 = "12.2 (16E226)"
const imageFile = "DeveloperDiskImage.dmg"
const signatureFile = "DeveloperDiskImage.dmg.signature"

func MatchAvailable(version string) string {
log.Debugf("device version: %s ", version)
requestedVersionParsed := semver.MustParse(version)
var bestMatch *semver.Version = nil
var bestMatchString string

for _, availableVersion := range availableVersions {
parsedAV := semver.MustParse(availableVersion)
parsedAV := semver.MustParse(strings.Split(availableVersion, " (")[0])
if parsedAV.Equal(requestedVersionParsed) {
return availableVersion
}
if bestMatch == nil {
bestMatch = parsedAV
bestMatchString = availableVersion
continue
}
if parsedAV.GreaterThan(bestMatch) && (parsedAV.LessThan(requestedVersionParsed) || parsedAV.Equal(requestedVersionParsed)) {
if parsedAV.GreaterThan(bestMatch) && (parsedAV.LessThan(requestedVersionParsed)) {
bestMatch = parsedAV
bestMatchString = availableVersion
}
}
log.Debugf("device version: %s bestMatch: %s", version, bestMatch)
if bestMatchString == "12.2" {
return v12_2
}

return bestMatchString
}

Expand All @@ -63,40 +64,40 @@ func DownloadImageFor(device ios.DeviceEntry, baseDir string) (string, error) {
log.Infof("%s already downloaded from https://github.com/haikieu/", imageDownloaded)
return imageDownloaded, nil
}
downloadUrl := fmt.Sprintf(repo, version)
downloadUrl := ""
log.Infof("downloading from: %s", downloadUrl)
log.Info("thank you haikieu for making these images available :-)")
zipFileName := path.Join(baseDir, imagepath, fmt.Sprintf("%s.zip", version))
err = downloadFile(zipFileName, downloadUrl)
log.Info("thank you github.com/mspvirajpatel for making these images available :-)")
versionDir := strings.Split(version, " (")[0]
downloadUrl = versionMap[version] + "/" + imageFile + "?raw=true"
imageFileName := path.Join(baseDir, versionDir, imageFile)

signatureDownloadUrl := versionMap[version] + "/" + signatureFile + "?raw=true"
signatureFileName := path.Join(baseDir, versionDir, signatureFile)
err = os.Mkdir(path.Join(baseDir, versionDir), 0755)
if err != nil {
return "", err
}
files, size, err := zipconduit.Unzip(zipFileName, path.Join(baseDir, imagepath))
log.Infof("downloading '%s' to path '%s'", downloadUrl, imageFileName)
err = downloadFile(imageFileName, downloadUrl)
if err != nil {
return "", err
}
err = os.Remove(zipFileName)
if err != nil {
log.Warnf("failed deleting: '%s' with err: %+v", zipFileName, err)
}
log.Infof("downloaded: %+v totalbytes: %d", files, size)
downloadedDmgPath, err := findImage(path.Join(baseDir, imagepath), version)

err = downloadFile(signatureFileName, signatureDownloadUrl)
if err != nil {
return "", err
}
os.RemoveAll(path.Join(baseDir, imagepath, "__MACOSX"))

log.Infof("Done extracting: %s", downloadedDmgPath)
return downloadedDmgPath, nil
return imageFileName, nil
}

func findImage(dir string, version string) (string, error) {
var imageToFind string
switch runtime.GOOS {
case "windows":
imageToFind = fmt.Sprintf("%s\\%s", version, developerDiskImageDmg)
imageToFind = fmt.Sprintf("%s\\%s", version, imageFile)
default:
imageToFind = fmt.Sprintf("%s/%s", version, developerDiskImageDmg)
imageToFind = fmt.Sprintf("%s/%s", version, imageFile)
}
var imageWeFound string
err := filepath.Walk(dir,
Expand Down
12 changes: 6 additions & 6 deletions ios/imagemounter/imagedownloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
)

func TestVersionMatching(t *testing.T) {
assert.Equal(t, "11.2", imagemounter.MatchAvailable("11.2.5"))
assert.Equal(t, "12.2 (16E226)", imagemounter.MatchAvailable("12.2.5"))
assert.Equal(t, "13.6", imagemounter.MatchAvailable("13.6.1"))
assert.Equal(t, "14.7", imagemounter.MatchAvailable("14.7.1"))
assert.Equal(t, "15.2", imagemounter.MatchAvailable("15.3.1"))
assert.Equal(t, "11.2 (15C5092b)", imagemounter.MatchAvailable("11.2.5"))
assert.Equal(t, "12.2 (16E5191d)", imagemounter.MatchAvailable("12.2.5"))
assert.Equal(t, "13.5", imagemounter.MatchAvailable("13.6.1"))
assert.Equal(t, "14.7.1", imagemounter.MatchAvailable("14.7.1"))
assert.Equal(t, "15.3.1", imagemounter.MatchAvailable("15.3.1"))
assert.Equal(t, "15.4", imagemounter.MatchAvailable("15.4.1"))
assert.Equal(t, "15.4", imagemounter.MatchAvailable("19.4.1"))
assert.Equal(t, "16.0", imagemounter.MatchAvailable("19.4.1"))
}

0 comments on commit ca2f71b

Please sign in to comment.