0

I have spent quite some time Googling for a specific product solution that I cannot seem to find for the life of me, so I come to Stack overflow for some help.

I work for an unmentioned public university in which a certain group of incoming freshman students are required to purchase a new laptop and one of the options they have is a specific configuration of a 13" Macbook Pro. We are forecasting that approximately 1,800 students will be aquiring these Macbooks over the next few months before the Fall semester begins in August.

The issue we have is they are required to use some specific software that is only available in Windows. We have found a product solution that runs a simple .dmg file and partitions the existing hard drive as such to install a pre-configured Windows image in Boot Camp which includes this required software. This way the student is not required to perform any tasks that are outside their scope of technical knowledge, seeing as Boot Camp can at times be a bit confusing.

The solution I am looking for is an application or method that performs the following;

  1. Downloading that potentially large .dmg file (in excess of 40 GB) without the student having to enter any input, such as where the file is located on the internet
  2. Verifying the file through an md5 checksum
  3. If possible, automatically executing that .dmg file

Or is this something that I will need an understanding of Swift/Objective-C to accomplish by developing myself?

SDee
  • 121
  • 1
  • 9
  • You can write apps in other languages. Whip one up in Javascript if that's your forte. – john elemans May 17 '16 at 20:46
  • 1
    This is a deployment problem more than a programming problem. Have you looked at Apple's [Education Deployment Guide](https://help.apple.com/deployment/education/) and [other resources](http://www.apple.com/education/it/)? I'd also talk to your Apple sales rep or SE -- if you're buying that many machines, it might be possible to order them preconfigured. – Caleb May 28 '16 at 20:54

1 Answers1

3

Basically, yes, you will need a little language of Swift / Cocoa framework to do it this way. You can always use another language, like Python, to do this as well.

  1. Download file. You can do this with a simple downloader class, like this:

    class HTTP {
        static func download(download_path: NSURL, save_path: NSURL, completion: ((NSError?, NSData?) -> Void)) {
            let req = NSMutableURLRequest(URL: download_path)
            req.HTTPMethod = "GET"
            NSURLSession.sharedSession().dataTaskWithRequest(req) { data, response, error in
                if error != nil {
                    //Downloading file failed
                    completion(error, nil)
                } else {
                    //Downloaded file
                    do {
                        //Write data to file:
                        if data != nil {
                            try data!.writeToFile(save_path.absoluteString + "file.dmg", options: [])
                            completion(nil, data!)
                        } else {
                            completion(NSError(domain: "Downloaded file null", code: -1, userInfo: nil), nil)
                        }
    
                    } catch {
                        completion(NSError(domain: "Could not write to file", code: -1, userInfo: nil), nil)
                    }
                }
            }.resume()
        }
    }
    
    //Usage: 
    HTTP.download(NSURL(string:"http://www.example.com/file.dmg")!, save_path:  NSURL(string: "/Users/username/Desktop/")!) {
        error, data in
    
        //Check if there's an error or data is null, if not continue to step 2
    }
    
  2. Check MD5 checksum. Use CommonCrypto Library to calculate MD5 of file data:

    //Usage:
    "contents-of-file".MD5
    
  3. For running the DMG, look at running terminal commands from swift and how to run a DMG file from terminal. Alternatively, you could use Applescript to run the DMG and call that script from swift.

Complete example using above methods:

HTTP.download(NSURL(string:"http://www.example.com/file.dmg")!, save_path: NSURL(string: "/Users/username/Desktop/")!) {
    error, data in
    if error == nil {
        guard data != nil else {
            //Data is nil
        }
        if String(data: data!, encoding: NSUTF8StringEncoding)!.md5() == /* Other MD5 value to check */ {
            //MD5 checksum completed. Use whatever method here to execute the DMG
            executeDMG(NSURL(string: "/Users/username/Desktop/file.dmg")!)
        }

    } else {
        //Couldn't download file
        //Info: error.localizedDescription property
    }
}
Community
  • 1
  • 1
brimstone
  • 3,314
  • 3
  • 28
  • 48