equal
deleted
inserted
replaced
|
1 #!/bin/bash |
|
2 |
|
3 # Downloads and install a .dmg from a URL |
|
4 # |
|
5 # Usage |
|
6 # $ dmg_pkg_install [url] |
|
7 # |
|
8 # Adopted from https://gist.github.com/afgomez/4172338 |
|
9 |
|
10 |
|
11 if [[ $# -lt 1 ]]; then |
|
12 echo "Usage: dmg_pkg_install [url]" |
|
13 exit 1 |
|
14 fi |
|
15 |
|
16 url=$* |
|
17 |
|
18 # Generate a random file name |
|
19 tmp_file=/tmp/`openssl rand -base64 10 | tr -dc '[:alnum:]'`.dmg |
|
20 |
|
21 # Download file |
|
22 echo "Downloading $url..." |
|
23 curl -# -L -o $tmp_file $url |
|
24 |
|
25 echo "Mounting image..." |
|
26 volume=`hdiutil mount $tmp_file | tail -n1 | perl -nle '/(\/Volumes\/[^ ]+)/; print $1'` |
|
27 |
|
28 # Locate .pkg |
|
29 app_pkg=`find $volume/. -name *.pkg -maxdepth 1 -print0` |
|
30 echo "Install pkg..." |
|
31 installer -pkg $app_pkg -target / |
|
32 |
|
33 # Unmount volume, delete temporal file |
|
34 echo "Cleaning up..." |
|
35 hdiutil unmount $volume -quiet |
|
36 rm $tmp_file |
|
37 |
|
38 echo "Done!" |
|
39 exit 0 |