caskroom/homebrew-cask — pull request #8231 by claui (2014-12-18 18:57:16+00:00)
Title: WIP: Extract EULAs from a .dmg file

This is a first draft for extracting EULAs from a DMG.

I just wanted to try out the suggestions @phinze [proposed](https://github.com/caskroom/homebrew-cask/issues/720#issue-16571317) and @MattiSG [further elaborated](https://github.com/caskroom/homebrew-cask/issues/720#issuecomment-67331594) in #720.

### Please try this out

@federicobond @ndr-qef @phinze @rolandwalker @vitorgalvao

Despite this PR being little more than a proof-of-concept, I’d still love some feedback early on:

- You can try out this branch right now. When you install one or more Casks from the above list, it should extract and display the EULA according to your locale.

- Does the EULA show up for you?

- I have used shell commands to get the prototype working quickly. Would you say it’s necessary that I rewrite part of this logic in Ruby? If so, which parts?

### Testing

The following Casks are known to have their DMGs carry an EULA.
To help testing, **please feel free to add more such Casks to this list.**

- [`sketchup`](https://github.com/caskroom/homebrew-cask/blob/384dcfa854cd6b1892917626a11d270bbe0bdae8/Casks/sketchup.rb#L7) ([DMG](https://dl.trimble.com/sketchup/SketchUpMake-en.dmg), 115 MB)
- [`no-ip-duc`](https://github.com/caskroom/homebrew-cask/blob/124bc5495dbea944ec3ab00d8ddb08ddc8951051/Casks/no-ip-duc.rb#L5) ([DMG](https://www.noip.com/client/mac/noip3.2.1.dmg), 7 MB) Has a known issue – see section _To do_

### To do

This is just a proof of concept so some more work is needed until this is ready to be reviewed/merged.

The main to-dos are:

- [ ] Ask user to accept or decline the EULA
- [ ] Introduce a `--blindly-accept-license` option
- [ ] Find out whether we can rely on users having `derez` installed; alternatively, rewrite the `derez` part in Ruby
- [ ] Port logic to Ruby where it makes sense
- [ ] To improve UX, use `less` instead of just dumping the EULA; need to figure out how to persuade less that we are in a terminal
- [ ] To improve UX, allow the user to actually press `y` or `n` instead of `q`; figure out how to make a custom `.lesskey` file
- [ ] Write tests
- [ ] Leverage RTF formatting, display bold text in color
- [ ] Known issue: To extract the EULA, I unflatten the DMG but this causes the SHA2 of the DMG to change. Example where this causes subsequent installs to break: `no-ip-duc`
- [ ] Review
- [ ] Manual testing on different OSes
- [ ] Rigorous manual testing with as many Casks as possible
- [ ] Remove most `odebug` statements

### Implementation notes (WIP)

The implementation introduces two concepts:

- in containers, a new `eula?` predicate, and
- in the installer, an additional stage called `display_eula`.

This is what `display_eula` does:

- Are we a DMG? If not, stop here.
- Can we find a resource fork? If not, `hdiutil unflatten` the DMG. (Vendors typically flatten their DMGs to make sure the resource fork survives the download.)
- Still no resource fork? Then stop here.
- Extract all EULAs from the resource fork of the primary container.
- Decide if one of the locales match the user’s locale per the `AppleLocale` setting.
- Fall back to the most common locales if we don’t have an exact match.
- If we have a RTF, convert it to text.
- Prefer RTF over text if there are both.