Skip to content

Instantly share code, notes, and snippets.

@Overbryd
Created January 22, 2012 12:35
Show Gist options
  • Select an option

  • Save Overbryd/1656935 to your computer and use it in GitHub Desktop.

Select an option

Save Overbryd/1656935 to your computer and use it in GitHub Desktop.
A whole bunch of great bash functions to install stuff on MacOSX
# Install a .app, .pkg or a .dmg with ease
function install() {
if [[ "$1" =~ ^http ]]; then
# Fix download using expect wrapping lwp-download
# lwp-download is the only tool that gets any remote file name correct, unfortunately it is highly interactive and relies on user input
echo "not reliable atm"
else
case $1 in
*.dmg)
install_dmg "$1"
;;
*.app)
install_app "$1"
;;
*.prefPane)
install_prefPane "$1"
;;
*.pkg)
install_pkg "$1"
;;
*)
echo "Unknown file or url given"
return 1
esac
fi
}
# Mounts a disk image and tries to find a pkg or app to install, then unmounts
function install_dmg() {
mountpoint=$(hdiutil mount "$1" | tail -n 1 | sed -e 's/.*\(\/Volumes.*\)/\1/')
installable=$(find "$mountpoint" -name '*.app' -or -name '*.pkg' -or -name '*.prefPane' -maxdepth 1 | head -n1)
if [[ "$installable" != "" ]]; then
install "$installable"
fi
hdiutil unmount "$mountpoint"
}
function install_app() {
cp -R "$1" /Applications/
}
function install_prefPane() {
cp -R "$1" ~/Library/PreferencePanes/
}
function install_pkg() {
sudo installer -pkg "$@" -target "/"
}
@wikimatze
Copy link

Great idea

@Overbryd
Copy link
Author

Note: I've updated the gist. For now I have removed the download feature, since it was causing troubles with detecting the correct remote file name.

I also fixed a problem in the install_app function.

I've added install_prefPane to install preference panes.

Everything else should be working fine. Please report if you experience any inconveniences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment