Created
November 13, 2019 03:00
-
-
Save mcharo/5fe6c32e0bb204ab54933022d35cba9c to your computer and use it in GitHub Desktop.
Install Microsoft Teams pkg (and maybe others) on macOS without admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# setup | |
pkgpath=$1 | |
pkgout=/tmp/$(/usr/bin/openssl rand -hex 10) | |
payout=/tmp/$(/usr/bin/openssl rand -hex 10) | |
if [ -d "$pkgout" ]; then | |
echo $pkgout already exists | |
exit 1 | |
fi | |
if [ ! -d "$payout" ]; then | |
mkdir "$payout" | |
fi | |
# uncompress pkg | |
echo Expanding $pkgpath... | |
pkgutil --expand $pkgpath $pkgout > /dev/null | |
# get the pkg name | |
expandpkg=`find "$pkgout" -name *.pkg | tail -n 1 | xargs basename` | |
# if there's a payload directory then that's probably the .app so move it out | |
if [ -d "$pkgout/$expandpkg/payload" ]; then | |
echo Copying $expandpkg.app... | |
mv "$pkgout/$expandpkg/payload" "$payout/$expandpkg.app" | |
fi | |
# if there's a payload file, then it's probably a tar'd version of the .app folder so extract it | |
if [[ -f "$pkgout/$expandpkg/Payload" ]]; then | |
echo Extracting payload to $payout... | |
tar xf "$pkgout/$expandpkg/Payload" -C "$payout" > /dev/null | |
fi | |
# if we did this before, clean up dmg | |
if [[ -f "/tmp/${expandpkg}.dmg" ]]; then | |
rm -f /tmp/${expandpkg}.dmg | |
fi | |
# create dmg, mount it, create link to ~/Applications and detach | |
echo Creating DMG... | |
hdiutil create -srcfolder "$payout" -volname "$expandpkg" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "/tmp/${expandpkg}.dmg" > /dev/null | |
MOUNT_DIR="/Volumes/${expandpkg}" | |
DEV_NAME=$(hdiutil attach -readwrite -noverify -noautoopen "/tmp/${expandpkg}.dmg" | egrep --color=never '^/dev/' | sed 1q | awk '{print $1}') | |
ln -s ~/Applications "$MOUNT_DIR/Applications" | |
hdiutil detach "${DEV_NAME}" > /dev/null | |
# pop open dmg | |
echo Opening DMG... | |
hdiutil attach -readonly -noverify -autoopen "/tmp/${expandpkg}.dmg" >/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment