Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for creating APFS disk images #221

Merged
merged 9 commits into from
Feb 3, 2023
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ the JSON file's path.
- `UDZO` - UDIF zlib-compressed image
- `UDBZ` - UDIF bzip2-compressed image (OS X 10.4+ only)
- `ULFO` - UDIF lzfse-compressed image (OS X 10.11+ only)
- `filesystem` (enum[string], optional) - Disk image filesystem
- `HFS+`
- `APFS` (macOS 10.13+ only)
- `contents` (array[object], required) - This is the contents of your DMG.
- `x` (number, required) - X position relative to icon center
- `y` (number, required) - Y position relative to icon center
Expand Down
23 changes: 14 additions & 9 deletions lib/appdmg.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ module.exports = exports = function (options) {
**/

pipeline.addStep('Creating temporary image', function (next) {
hdiutil.create(global.opts.title, `${global.megabytes}m`, function (err, temporaryImagePath) {
hdiutil.create(global.opts.title, `${global.megabytes}m`, global.opts.filesystem, function (err, temporaryImagePath) {
if (err) return next(err)

pipeline.addCleanupStep('unlink-temporary-image', 'Removing temporary image', function (next) {
Expand Down Expand Up @@ -396,15 +396,20 @@ module.exports = exports = function (options) {
**/

pipeline.addStep('Blessing image', function (next) {
const args = [
'--folder', global.temporaryMountPath
]

if (os.arch() !== 'arm64') {
args.push('--openfolder', global.temporaryMountPath)
}
// Blessing does not work for APFS disk images
if (global.opts.filesystem != "APFS") {
const args = [
'--folder', global.temporaryMountPath
]

if (os.arch() !== 'arm64') {
args.push('--openfolder', global.temporaryMountPath)
}

util.sh('bless', args, next)
util.sh('bless', args, next)
} else {
next.skip()
}
zorgiepoo marked this conversation as resolved.
Show resolved Hide resolved
})

/**
Expand Down
15 changes: 8 additions & 7 deletions lib/hdiutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const fs = require('fs')
const temp = require('fs-temp')
const crypto = require('crypto')
const util = require('./util')

exports.convert = function (source, format, target, cb) {
Expand All @@ -22,14 +23,14 @@ exports.convert = function (source, format, target, cb) {
})
}

exports.create = function (volname, size, cb) {
exports.create = function (volname, size, filesystem, cb) {
temp.template('%s.dmg').writeFile('', function (err, outname) {
if (err) return cb(err)

const args = [
'create', outname,
'-ov',
'-fs', 'HFS+',
'-fs', filesystem,
zorgiepoo marked this conversation as resolved.
Show resolved Hide resolved
'-size', size,
'-volname', volname
]
Expand All @@ -43,20 +44,20 @@ exports.create = function (volname, size, cb) {
}

exports.attach = function (path, cb) {
const mountpoint = '/Volumes/' + crypto.randomUUID()
zorgiepoo marked this conversation as resolved.
Show resolved Hide resolved
const args = [
'attach', path,
'-nobrowse',
'-noverify',
'-noautoopen'
'-noautoopen',
'-mountpoint',
mountpoint
]

util.sh('hdiutil', args, function (err, res) {
if (err) return cb(err)

const m = /Apple_HFS\s+(.*)\s*$/.exec(res.stdout)
if (m === null) return cb(new Error('Failed to mount image'))

cb(null, m[1])
cb(null, mountpoint)
zorgiepoo marked this conversation as resolved.
Show resolved Hide resolved
})
}

Expand Down
7 changes: 7 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
"UDBZ"
]
},
"filesystem": {
"type": "string",
"enum": [
"HFS+",
"APFS"
]
},
"contents": {
"type": "array",
"items": {
Expand Down