博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
macOs 静默安装dmg文件
阅读量:2063 次
发布时间:2019-04-29

本文共 3566 字,大约阅读时间需要 11 分钟。

公司电脑是macOS,手动安装某些软件(*.dmg)时需要系统管理员输入用户名和密码,要看管理员脸色行事。作为电脑的使用者有sudo权限,那我们是不是可以有绕过的方法呢?答案是肯定的。

那我们就可以使用系统自带的hdituil命令来静默安装软件。

 

hdiutil 命令详解

NAME

     hdiutil -- manipulate disk images (attach, verify, create, etc)

 

SYNOPSIS

     hdiutil verb [options]

 

DESCRIPTION

     hdiutil uses the DiskImages framework to manipulate disk images.  Common verbs include attach, detach, verify, create, convert, and compact.

 

     The rest of the verbs are currently: help, info, burn, checksum, chpass, erasekeys, unflatten, flatten, imageinfo, isencrypted, mountvol, unmount, plugins, udifrez, udifderez, resize, segment, makehybrid, and

     pmap.

 

BACKGROUND

     Disk images are data containers that emulate disks.  Like disks, they can be partitioned and formatted.  Many common uses of disk images blur the distinction between the disk image container and its content,

     but this distinction is critical to understanding how disk images work.  The terms "attach" and "detach" are used to distinguish the way disk images are connected to and disconnected from a system.  "Mount" and

     "unmount" are the parallel filesystems options.

 

     For example, when you double-click a disk image in the macOS Finder, two separate things happen.  First, the image is "attached" to the system just like an external drive.  Then, the kernel and Disk Arbitration

     probe the new device for recognized file structures.  If any are discovered that should be mounted, the associated volumes will mount and appear on the desktop.    

 主要用到它的两个命令 hdituil attach, hdiutil detach.

attach image [options]

                attach a disk image as a device.  attach will return information about an already-attached image as if it had attached it.  If any associated volumes are unmounted (and mounting is not suppressed),

                they will be remounted.  mount is a poorly-named synonym for attach.  See BACKGROUND.

 

                By default, the system applies additional mount options to filesystems backed by untrusted devices like disk images: options like nosuid and quarantine.  PERMISSIONS VS. OWNERS explains the behavior

                of such filesystems and EXAMPLES shows how to override some of the default behavior.

 

                The output of attach has been stable since Mac OS X 10.0 (though it was called hdid(8) then) and is intended to be program-readable.  It consists of the /dev node, a tab, a content hint (if applica-

                ble), another tab, and a mount point (if any filesystems were mounted).  Because content hints are derived from the partition data, GUID Partition Table types may leak through.  Common GUIDs such as

                "48465300-0000-11AA-AA11-0030654" are mapped to their human-readable counterparts (here "Apple_HFS").

detach dev_name [-force]

                detach a disk image and terminate any associated process.  dev_name is a partial /dev node path (e.g. "disk1").  As of Mac OS X 10.4, dev_name can also be a mountpoint.  If Disk Arbitration is run-

                ning, detach will use it to unmount any filesystems and detach the image.  If not, detach will attempt to unmount any filesystems and detach the image directly (using the `eject' ioctl).  If Disk

                Arbitration is not running, it may be necessary to unmount the filesystems with umount(8) before detaching the image.  eject is a synonym for detach.  In common operation, detach is very similar to

                diskutil(8)'s eject.

 

安装dmg文件的脚本

#/bin/bash

 

VOLUME=`hdiutil attach $1 | grep Volumes | awk '{print $3}'`

 

APP_NAME=`ls $VOLUME | grep .app`

 

cp -rf $VOLUME/$APP_NAME /Applications/$APP_NAME

 

xattr -c /Applications/$APP_NAME

 

hdiutil detach $VOLUME

xattr -c *.app 是删除所有扩展属性,解决问题“App can’t be opened because it is from an unidentified developer”。

详情参考:

 

安装示例

./install_app.sh Docker.dmg 

 

参考:

 

转载地址:http://nohlf.baihongyu.com/

你可能感兴趣的文章
剑指offer 25.二叉树中和为某一值的路径
查看>>
剑指offer 26. 数组中出现次数超过一半的数字
查看>>
剑指offer 27.二叉树的深度
查看>>
剑指offer 29.字符串的排列
查看>>
剑指offer 31.最小的k个树
查看>>
剑指offer 32.整数中1出现的次数
查看>>
剑指offer 33.第一个只出现一次的字符
查看>>
剑指offer 34.把数组排成最小的数
查看>>
剑指offer 35.数组中只出现一次的数字
查看>>
剑指offer 36.数字在排序数组中出现的次数
查看>>
剑指offer 37.数组中重复的数字
查看>>
剑指offer 38.丑数
查看>>
剑指offer 39.构建乘积数组
查看>>
剑指offer 57. 删除链表中重复的结点
查看>>
剑指offer 58. 链表中环的入口结点
查看>>
剑指offer 59. 把字符串转换成整数
查看>>
剑指offer 60. 不用加减乘除做加法
查看>>
leetcode 热题 Hot 100-3. 合并两个有序链表
查看>>
leetcode 热题 Hot 100-4. 对称二叉树
查看>>
Leetcode C++《热题 Hot 100-12》226.翻转二叉树
查看>>